Question T7359
Visible to All Users

How to access the Choices array within a matrixdynamic column

created 4 years ago

Hi,

I am writing a custom function to populate the Choices array within a matrix dynamic question. I have tried several ways of accessing the choices array, I can write a function which populates a dropdown type question though I can't work out how to access the choices array in a matrix dynamic type.
JSON
{
"type": "matrixdynamic",
"name": "Question1",
"title": "Please select your nationality",
"columns": [
{
"name": "nations",
"cellType": "dropdown",
"choices": [
]
}
]
}

JS
function nationality(survey) {
const Question1 = survey.getQuestionByName("Question1")

if(Question1) {
Question1.columns.choices = ['British', 'French', 'German']
}
}

export default nationality;

I have tried
Question1.column.choices = ['British', 'French', 'German']
Question1.nations.choices = ['British', 'French', 'German']

Comments (2)

    Hello Helen,
    Please use the following code:

    JavaScript
    Question1.getColumnByName("nations").choices = ["Your choices"];

    Thank you,
    Andrew
    SurveyJS Team

      Thank you Andrew this works perfectly :)