Question T13112
Visible to All Users

how to hide/disable add row button for dynamic matrix?

created 2 years ago (modified 2 years ago)

HI Team,
We have a requirement that we should be able to hide/disable add row button for dynamic matrix depending on few role based conditions?
Is there any way to achieve it?

Clipboard-File-1.png

is there any similar event onMatrixAllowRemoveRow for remove add row button?

Code
survey.onMatrixAllowRemoveRow.add((sender, options) => {   console.log(options.question.name)   options.allow = //true/false; });

Answers approved by surveyjs Support

created 2 years ago

Hello Santosh,
You can handle the creator.onShowingProperty event and show/hide the 'Allow adding rows' property (the QuestionMatrixDynamicModel.allowAddRows property) depending on a user role.

Let me know if this option works for you.

    Comments (3)

      I wish to render a question with dynamic matrix where i need to hide the Add row button conditionally, PFA below

      Clipboard-File-1.png

      I have hidden the delete icon for dynamic matrix by using the below logic. similarly i would like to hide the Add row button as well.
      Could you provide an example

      Code
      survey.onMatrixAllowRemoveRow.add((sender, options) => {   options.allow = true; });

      Please let me know for any clarifications.

        Any update on this?

          Hi,
          Thank you for the update. There is no event similar to the onMatrixAllowRemoveRow function. The Add Row button is rendered for the entire Dynamic Matrix question, not for a specific row.
          If you wish to prevent a user from adding new rows, for instance, you can hide this setting from UI, and enable/disable the allowAddRows option for a Dynamic Matrix before you show a survey preview using the creator.onSurveyInstanceCreated event.

          Consider this sample:

          JavaScript
          import { Serializer } from "survey-core"; Serializer.getProperty("matrixdynamic", "allowAddRows").visible = false; ... creator.onSurveyInstanceCreated.add((sender, options) => { if (options.reason === 'test') { let dynamicmatrix = options.survey.getQuestionByName('question1'); dynamicmatrix.allowAddRows = //... } });

          Let me know if you have additional questions.