Question T1415
Visible to All Users

Matrix Question Count

created 6 years ago

I'm using a simple Matrix type survey like this https://surveyjs.io/Examples/Library/?id=questiontype-matrix&platform=jQuery

How can I capture the number of questions displayed? I need to set this in a variable in order to do some calculations.

Each question is worth a potential 10 points, so I need to display the number of potential points available on the page, e.g 17 questions = 170 points.

I've tried to console.log(survey.data) but I don't understand most of it.

Comments (1)

    Hello,

    You can use the getAllQuestions of the survey object. You can use the pages and the visiblePages properties of the survey to iterate through pages. And you can use the questions property of a page to get all questions that belong this page.

    Each question has the isVisible property so you can calculate the exact count of the questions visible at the moment.

    Thanks, Serge
    SurveyJS Team

    Answers

    created 6 years ago

    Thanks for that, what should I expect to see?

    Apologies for the questions but I'm struggling to understand the docs. I simply want to console.log the number of questions in my matrix survey.

      Comments (1)

        Hello,
        The following code should work then:

        JavaScript
        var visibleQuestionsCount = 0; survey.getAllQuestions().forEach(function(question) { if(question.getType() == "matrix" && question.isVisible) { visibleQuestionsCount++; } });
        created 6 years ago

        Thanks for that.

        Could you possibly give me an example of how to use it?

        When I try this console.log(survey.getAllQuestions);

        On the console I see;

        ƒ (visibleOnly, includingDesignTime) { if (visibleOnly === void 0) { visibleOnly = false; } if (includingDesignTime === void 0) { includingDesignTime = false; } var result = new…

        Should I be doing something else?

          Comments (1)

            Sure:

            JavaScript
            var visibleQuestionsCount = 0; survey.getAllQuestions().forEach(function(question) { if(question.isVisible) { visibleQuestionsCount++; } });

            Thanks, Serge
            SurveyJS Team