Skip to content

Commit

Permalink
html & image questions should not be shown in tabulator column by def…
Browse files Browse the repository at this point in the history
…ault fix #455
  • Loading branch information
andrewtelnov committed Aug 1, 2024
1 parent 5fd1306 commit e60915b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/tables/table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SurveyModel, Question, Event, settings, QuestionSelectBase, QuestionMatrixModel, ItemValue, JsonError, EventBase } from "survey-core";
import { SurveyModel, Question, Event, Serializer, EventBase } from "survey-core";
import * as SurveyCore from "survey-core";
import {
IPermission,
Expand Down Expand Up @@ -172,11 +172,16 @@ export abstract class Table {
protected buildColumns = (survey: SurveyModel) => {
let columns: Array<IColumn> = [];
this._survey.getAllQuestions().forEach((question: Question) => {
const builder = ColumnsBuilderFactory.Instance.getColumnsBuilder(question.getTemplate());
columns = columns.concat(builder.buildColumns(question, this));
if(!this.isNonValueQuestion(question)) {
const builder = ColumnsBuilderFactory.Instance.getColumnsBuilder(question.getTemplate());
columns = columns.concat(builder.buildColumns(question, this));
}
});
return columns;
};
private isNonValueQuestion(question: Question): boolean {
return Serializer.isDescendantOf(question.getType(), "nonvalue");
}

public isColumnVisible(column: IColumn) {
if (column.location !== QuestionLocation.Column) return false;
Expand Down
28 changes: 28 additions & 0 deletions tests/tables/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,34 @@ test("check columns for question with comment", () => {
expect(<any>table.columns[1].dataType).toEqual(ColumnDataType.Text);
});

test("do not create columns for html and image questions", () => {
const json = {
questions: [
{
type: "text",
name: "q1"
},
{
type: "html",
name: "q2"
},
{
type: "image",
name: "q3"
},
{
type: "text",
name: "q4"
},
],
};
const survey = new SurveyModel(json);
const table = new TableTest(survey, [], {}, []);
expect((<any>table).columns).toHaveLength(2);
expect((<any>table).columns[0].name).toEqual("q1");
expect((<any>table).columns[1].name).toEqual("q4");
});

test("check columns for question with other and storeOthersAsComment: true", () => {
const json = {
questions: [
Expand Down

0 comments on commit e60915b

Please sign in to comment.