Editable Grid - Dynamic rows

Certified Senior Developer

I want to fill separate values in these fields, How can I resolve it

rows: {
a!forEach(
items: local!counts,
expression: a!gridRowLayout(
contents: {
a!textField(
label: "Text",
labelPosition: "ABOVE",
value: ri!Queries.question,
saveInto: { ri!Queries.question },
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Text",
labelPosition: "ABOVE",
value: ri!answers.option1,
saveInto: { ri!answers.option1 },
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Text",
labelPosition: "ABOVE",
value: ri!answers.option1,
saveInto: { ri!answers.option1 },
refreshAfter: "UNFOCUS",
validations: {}
)
}
)
)
}

  Discussion posts and replies are publicly visible

Parents
  • Let's understand it first. For storing separate values, you need separate variables and a separate index of a variable. 
    So you need to make a 2D array here that you can achieve by adding 3 fields in a CDT and using that CDT as the datatype of an array type variable

  • 0
    Certified Senior Developer
    in reply to Harshit Bumb (Appyzie)

    a!localVariables(
    local!tech,
    local!count,
    local!counts: if(
    a!isNullOrEmpty(local!count),
    null,
    a!forEach(
    items: enumerate(local!count) + 1,
    expression: {
    a!textField(
    label: "Text",
    labelPosition: "ABOVE",
    value: ri!Queries.question,
    saveInto: { ri!Queries.question },
    refreshAfter: "UNFOCUS",
    validations: {}
    ),
    a!textField(
    label: "Text",
    labelPosition: "ABOVE",
    value: ri!answers.option1,
    saveInto: { ri!answers.option1 },
    refreshAfter: "UNFOCUS",
    validations: {}
    ),
    a!dropdownField(
    label: "Text",
    labelPosition: "ABOVE",
    placeholder: "--- Select a Value ---",
    choiceLabels: cons!MCS_ANSWERS,
    choiceValues: cons!MCS_ANSWERS,
    value: ri!answers.correctans,
    saveInto: { ri!answers.correctans },
    validations: {}
    )
    }
    )
    ),



    a!formLayout(
    label: "Questionare",
    contents: {
    a!columnsLayout(
    columns: {
    a!columnLayout(
    contents: {
    a!dropdownField(
    label: "Technology",
    labelPosition: "JUSTIFIED",
    placeholder: "--- Select a Value ---",
    choiceLabels: rule!MCS_GetTechnologyName().subname,
    choiceValues: rule!MCS_GetTechnologyName().subid,
    value: local!tech,
    saveInto: {
    a!save(local!tech, save!value),
    a!save(ri!Queries.subid, local!tech)
    },
    searchDisplay: "AUTO",
    validations: {}
    )
    }
    ),
    a!columnLayout(
    contents: {
    a!dropdownField(
    label: "Count of Queries",
    labelPosition: "JUSTIFIED",
    placeholder: "--- Select a Value ---",
    choiceLabels: cons!MCS_COUNTOFQUESTIONS,
    choiceValues: cons!MCS_COUNTOFQUESTIONS,
    value: local!count,
    saveInto: local!count,
    searchDisplay: "AUTO",
    required: true,
    validations: {}
    )
    }
    ),
    a!columnLayout(contents: {})
    }
    ),
    a!gridLayout(
    label: "Enter Questionnaire ",
    labelPosition: "ABOVE",
    headerCells: {
    a!gridLayoutHeaderCell(label: "Question"),
    a!gridLayoutHeaderCell(label: "Option Available"),
    a!gridLayoutHeaderCell(label: "Correct Option")
    },
    columnConfigs: {},
    rows: {
    a!forEach(
    items: local!counts,
    expression: a!gridRowLayout(
    contents: {
    a!textField(
    label: "Text",
    labelPosition: "ABOVE",
    value: fv!item.question,
    saveInto: fv!item.question,
    refreshAfter: "UNFOCUS",
    validations: {}
    ),
    a!textField(
    label: "Text",
    labelPosition: "ABOVE",
    value: fv!item.option1,
    saveInto: fv!item.option1,
    refreshAfter: "UNFOCUS",
    validations: {}
    ),
    a!dropdownField(
    label: "Text",
    labelPosition: "ABOVE",
    placeholder: "--- Select a Value ---",
    choiceLabels: cons!MCS_ANSWERS,
    choiceValues: cons!MCS_ANSWERS,
    value: fv!item.correctans,
    saveInto: fv!item.correctans,
    validations: {}
    )
    }
    )
    )
    },
    selectionSaveInto: {},
    validations: {},
    shadeAlternateRows: true
    )
    },
    buttons: a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Submit",
    submit: true,
    style: "PRIMARY",
    loadingIndicator: true
    )
    },
    secondaryButtons: {
    a!buttonWidget(
    label: "Cancel",
    value: true,
    saveInto: {},
    submit: true,
    style: "NORMAL",
    validate: false
    )
    }
    )
    )
    )

  • 0
    Certified Lead Developer
    in reply to kavitar0003

    Use this feature to make your code more readable.

  • 0
    Certified Senior Developer
    in reply to kavitar0003

    Could you please try the below code?

    a!localVariables(
      local!tech,
      local!count,
      local!counts: a!refreshVariable(
        refreshOnVarChange: local!count,
        value: a!forEach(
          items: if(a!isNullOrEmpty(local!count),null,enumerate(local!count)+1),
          expression: {
            question:"",
            option1:"",
            correctans:""
          }
        )
      ),
      a!formLayout(
        label: "Questionare",
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!dropdownField(
                    label: "Technology",
                    labelPosition: "JUSTIFIED",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: {"Java","Python","Git"},
                    choiceValues: {"Java","Python","Git"},
                    value: local!tech,
                    saveInto: {
                      a!save(local!tech, save!value),
                    },
                    searchDisplay: "AUTO",
                    validations: {}
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!dropdownField(
                    label: "Count of Queries",
                    labelPosition: "JUSTIFIED",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: {1,2,3,4,5},
                    choiceValues: {1,2,3,4,5},
                    value: local!count,
                    saveInto: local!count,
                    searchDisplay: "AUTO",
                    required: true,
                    validations: {}
                  )
                }
              ),
              a!columnLayout(contents: {})
            }
          ),
          a!gridLayout(
            label: "Enter Questionnaire ",
            labelPosition: "ABOVE",
            headerCells: {
              a!gridLayoutHeaderCell(label: "Question"),
              a!gridLayoutHeaderCell(label: "Option Available"),
              a!gridLayoutHeaderCell(label: "Correct Option")
            },
            columnConfigs: {},
            rows: {
              a!forEach(
                items: local!counts,
                expression: a!gridRowLayout(
                  contents: {
                    a!textField(
                      label: "Text",
                      labelPosition: "ABOVE",
                      value: fv!item.question,
                      saveInto: fv!item.question,
                      refreshAfter: "UNFOCUS",
                      validations: {}
                    ),
                    a!textField(
                      label: "Text",
                      labelPosition: "ABOVE",
                      value: fv!item.option1,
                      saveInto: fv!item.option1,
                      refreshAfter: "UNFOCUS",
                      validations: {}
                    ),
                    a!textField(
                      label: "Text",
                      labelPosition: "ABOVE",
                      placeholder: "--- Select a Value ---",
                      value: fv!item.correctans,
                      saveInto: fv!item.correctans,
                      validations: {}
                    )
                  }
                )
              )
            },
            selectionSaveInto: {},
            validations: {},
            shadeAlternateRows: true
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              submit: true,
              style: "PRIMARY",
              loadingIndicator: true
            )
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              value: true,
              saveInto: {},
              submit: true,
              style: "NORMAL",
              validate: false
            )
          }
        )
      )
    )

Reply
  • 0
    Certified Senior Developer
    in reply to kavitar0003

    Could you please try the below code?

    a!localVariables(
      local!tech,
      local!count,
      local!counts: a!refreshVariable(
        refreshOnVarChange: local!count,
        value: a!forEach(
          items: if(a!isNullOrEmpty(local!count),null,enumerate(local!count)+1),
          expression: {
            question:"",
            option1:"",
            correctans:""
          }
        )
      ),
      a!formLayout(
        label: "Questionare",
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!dropdownField(
                    label: "Technology",
                    labelPosition: "JUSTIFIED",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: {"Java","Python","Git"},
                    choiceValues: {"Java","Python","Git"},
                    value: local!tech,
                    saveInto: {
                      a!save(local!tech, save!value),
                    },
                    searchDisplay: "AUTO",
                    validations: {}
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!dropdownField(
                    label: "Count of Queries",
                    labelPosition: "JUSTIFIED",
                    placeholder: "--- Select a Value ---",
                    choiceLabels: {1,2,3,4,5},
                    choiceValues: {1,2,3,4,5},
                    value: local!count,
                    saveInto: local!count,
                    searchDisplay: "AUTO",
                    required: true,
                    validations: {}
                  )
                }
              ),
              a!columnLayout(contents: {})
            }
          ),
          a!gridLayout(
            label: "Enter Questionnaire ",
            labelPosition: "ABOVE",
            headerCells: {
              a!gridLayoutHeaderCell(label: "Question"),
              a!gridLayoutHeaderCell(label: "Option Available"),
              a!gridLayoutHeaderCell(label: "Correct Option")
            },
            columnConfigs: {},
            rows: {
              a!forEach(
                items: local!counts,
                expression: a!gridRowLayout(
                  contents: {
                    a!textField(
                      label: "Text",
                      labelPosition: "ABOVE",
                      value: fv!item.question,
                      saveInto: fv!item.question,
                      refreshAfter: "UNFOCUS",
                      validations: {}
                    ),
                    a!textField(
                      label: "Text",
                      labelPosition: "ABOVE",
                      value: fv!item.option1,
                      saveInto: fv!item.option1,
                      refreshAfter: "UNFOCUS",
                      validations: {}
                    ),
                    a!textField(
                      label: "Text",
                      labelPosition: "ABOVE",
                      placeholder: "--- Select a Value ---",
                      value: fv!item.correctans,
                      saveInto: fv!item.correctans,
                      validations: {}
                    )
                  }
                )
              )
            },
            selectionSaveInto: {},
            validations: {},
            shadeAlternateRows: true
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              submit: true,
              style: "PRIMARY",
              loadingIndicator: true
            )
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              value: true,
              saveInto: {},
              submit: true,
              style: "NORMAL",
              validate: false
            )
          }
        )
      )
    )

Children