Question T14362
Visible to All Users

Data Dictionary

created a year ago

Hello,

I have made some surveys and would like to know if you have any product that can output a data dictionary based off of the survey? A data dictionary consists of variable name, the question, the values for each answer, question type, etc. It would be ideal to output this into a table format/excel format.

Thanks

Patri

Answers approved by surveyjs Support

created a year ago

Hello Patri,
Please let me ensure I got you correctly. You have some data dictionary and you would like to print this information within a survey. In SurveyJS, we have a matrix question type. It allows you to display data in a tabular format. Please refer to our demos for more information.

Display data in an editable table

A Multi-Select Matrix allows you to configure various cell types. If you wish to display dictionary data in edit mode, consider a Single-Line Input cell type. Please take note that a matrix receives data in a specified format. Therefore, you may need to transform your dictionary into an object which is accepted by a matrix question. Use the survey.setValue function to set an array of values to a survey's question.

JavaScript
const dataDictionary = [ { variableName: "age", question: "What is your age?", values: ["Under 18", "18-30", "31-45", "46-60", "Over 60"], questionType: "choice" }, { variableName: "gender", question: "What is your gender?", values: ["Male", "Female", "Non-binary", "Prefer not to say"], questionType: "choice" }, { variableName: "education", question: "What is your highest level of education?", values: [ "High School", "Associate's Degree", "Bachelor's Degree", "Master's Degree", "Doctorate" ], questionType: "choice" }, { variableName: "income", question: "What is your approximate household income?", values: [ "Less than $25,000", "$25,001 - $50,000", "$50,001 - $75,000", "$75,001 - $100,000", "Over $100,000" ], questionType: "choice" }, { variableName: "feedback", question: "Please provide any additional feedback or comments:", values: [], questionType: "text" } ]; const transformedData = {}; dataDictionary.forEach((record, index) => { transformedData[`Row ${index + 1}`] = { variableName: record.variableName, question: record.question, values: record.values, questionType: record.questionType }; }); survey.setValue("question1", transformedData);

Please refer to the following demo: View Demo.
Clipboard-File-1.png

Display data in read-only table

To display data in read-only mode, you may wish to consider a read-only cell type, e.g., Expression. Please note that in this case, you need to set a matrix'es defaultValue property and assign an array of row values to it.

JavaScript
const dataDictionary = [ { variableName: "age", question: "What is your age?", values: ["Under 18", "18-30", "31-45", "46-60", "Over 60"], questionType: "choice" }, { variableName: "gender", question: "What is your gender?", values: ["Male", "Female", "Non-binary", "Prefer not to say"], questionType: "choice" }, { variableName: "education", question: "What is your highest level of education?", values: [ "High School", "Associate's Degree", "Bachelor's Degree", "Master's Degree", "Doctorate" ], questionType: "choice" }, { variableName: "income", question: "What is your approximate household income?", values: [ "Less than $25,000", "$25,001 - $50,000", "$50,001 - $75,000", "$75,001 - $100,000", "Over $100,000" ], questionType: "choice" }, { variableName: "feedback", question: "Please provide any additional feedback or comments:", values: [], questionType: "text" } ]; const transformedData = {}; dataDictionary.forEach((record, index) => { transformedData[`Row ${index + 1}`] = { variableName: record.variableName, question: record.question, values: record.values, questionType: record.questionType }; }); let matrix = survey.getQuestionByName("question1"); matrix.defaultValue = transformedData;

The following demo shows a table in read-only mode: View Demo.
Clipboard-File-2.png

You can additionally customize column and row headers to meet your requirements.

Hope it can help you. Please let me know if you have any further questions.