From e60915b50b2e1788abdd3205afa346cd9a0b3c62 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Thu, 1 Aug 2024 14:15:01 +0300 Subject: [PATCH] html & image questions should not be shown in tabulator column by default fix #455 --- src/tables/table.ts | 11 ++++++++--- tests/tables/tables.test.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/tables/table.ts b/src/tables/table.ts index 2f1049e59..d4eb39cae 100644 --- a/src/tables/table.ts +++ b/src/tables/table.ts @@ -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, @@ -172,11 +172,16 @@ export abstract class Table { protected buildColumns = (survey: SurveyModel) => { let columns: Array = []; 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; diff --git a/tests/tables/tables.test.ts b/tests/tables/tables.test.ts index 4a6fe888f..9425ed606 100644 --- a/tests/tables/tables.test.ts +++ b/tests/tables/tables.test.ts @@ -274,6 +274,34 @@ test("check columns for question with comment", () => { expect(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((table).columns).toHaveLength(2); + expect((table).columns[0].name).toEqual("q1"); + expect((table).columns[1].name).toEqual("q4"); +}); + test("check columns for question with other and storeOthersAsComment: true", () => { const json = { questions: [