Combination of multi dropdown and editable grid

Certified Lead Developer

Hi guys,

I have the requirement where I need to have two components multi dropdown and an editable grid,

In the multiple drowndown component the user will select the value based on that the number of rows need to be populated in the grid. Where when the user deselect the value in dropdown the corresponding row in the grid need to deleted or not to shown to user.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I am fetching  the data from db and the data will be shown up the drop down field,

    Now my use case is whenever the user selects the value in the dropdown, the row will be populated in the grid with one column data will be the value from dropdown. And the remaining columns will be editable.

    Now when a user selects a value in dropdown a row will be populated(it was done) and in remaining fields the data will be entered by user. Now when he deselects the value in dropdown the row need to be hidden but the data need not be flushed. When he selects the same deselected value the row with same data need to be shown.

  • 0
    Certified Lead Developer
    in reply to santoshd378

    You can actually call a rule which would feed data in to local!editableGridData in the sample code that I have shared.

     

    PFA updated sample code which should work for your use case.

     

    load(
      local!multiSelectedValues,
      local!editableGridData: {
        {
          employeeId: 1,
          employeeName: "ABC"
        },
        {
          employeeId: 2,
          employeeName: "XYZ"
        },
        {
          employeeId: 3,
          employeeName: "PQR"
        }
      },
      local!filteredData,
      a!sectionLayout(
        contents: {
          a!multipleDropdownField(
            label: "Multi Select Dropdown",
            choiceLabels: index(
              local!editableGridData,
              "employeeName",
              {}
            ),
            choiceValues: index(
              local!editableGridData,
              "employeeId",
              {}
            ),
            value: local!multiSelectedValues,
            saveInto: {
              local!multiSelectedValues,
              a!save(
                local!filteredData,
                index(
                  local!editableGridData,
                  wherecontains(
                    local!multiSelectedValues,
                    index(
                      local!editableGridData,
                      "employeeId",
                      {}
                    )
                  ),
                  {}
                )
              ),
              
            }
          ),
          a!gridLayout(
            label: "Editable Grid",
            headerCells: {
              a!gridLayoutHeaderCell(
                label: "Employee Id"
              ),
              a!gridLayoutHeaderCell(
                label: "Employee Name"
              )
            },
            rows: a!forEach(
              items: local!filteredData,
              expression: a!gridRowLayout(
                id: fv!index,
                contents: {
                  a!integerField(
                    readOnly: true(),
                    value: fv!item.employeeId,
                    saveInto: fv!item.employeeId
                  ),
                  a!textField(
                    value: fv!item.employeeName,
                    saveInto: {
                      fv!item.employeeName,
                      /* Uncomment this code if you want to save the changes on focus out of each field. */
                      /* a!save(
                        local!editableGridData,
                        updatearray(
                          local!editableGridData,
                          wherecontains(
                            local!multiSelectedValues,
                            index(
                              local!editableGridData,
                              "employeeId",
                              {}
                            )
                          ),
                          local!filteredData
                        )
                      ) */
                      
                    }
                  )
                }
              )
            )
          ),
          a!buttonLayout(
            primaryButtons: {
              a!buttonWidget(
                label: "Save Changes",
                saveInto: a!save(
                  local!editableGridData,
                  updatearray(
                    local!editableGridData,
                    wherecontains(
                      local!multiSelectedValues,
                      index(
                        local!editableGridData,
                        "employeeId",
                        {}
                      )
                    ),
                    local!filteredData
                  )
                )
              )
            }
          )
        }
      )
    )

     

    But in the sample code that I have attached, the changes in the selected row(s) would only be reflected when you click on the Save Changes button.

    However you can also save the changes on focus out of every field(then and there) in the grid after making changes. Please uncomment the commented portion in the attached sample code for this behavior.

     

    Hope this helps. :)

Reply
  • 0
    Certified Lead Developer
    in reply to santoshd378

    You can actually call a rule which would feed data in to local!editableGridData in the sample code that I have shared.

     

    PFA updated sample code which should work for your use case.

     

    load(
      local!multiSelectedValues,
      local!editableGridData: {
        {
          employeeId: 1,
          employeeName: "ABC"
        },
        {
          employeeId: 2,
          employeeName: "XYZ"
        },
        {
          employeeId: 3,
          employeeName: "PQR"
        }
      },
      local!filteredData,
      a!sectionLayout(
        contents: {
          a!multipleDropdownField(
            label: "Multi Select Dropdown",
            choiceLabels: index(
              local!editableGridData,
              "employeeName",
              {}
            ),
            choiceValues: index(
              local!editableGridData,
              "employeeId",
              {}
            ),
            value: local!multiSelectedValues,
            saveInto: {
              local!multiSelectedValues,
              a!save(
                local!filteredData,
                index(
                  local!editableGridData,
                  wherecontains(
                    local!multiSelectedValues,
                    index(
                      local!editableGridData,
                      "employeeId",
                      {}
                    )
                  ),
                  {}
                )
              ),
              
            }
          ),
          a!gridLayout(
            label: "Editable Grid",
            headerCells: {
              a!gridLayoutHeaderCell(
                label: "Employee Id"
              ),
              a!gridLayoutHeaderCell(
                label: "Employee Name"
              )
            },
            rows: a!forEach(
              items: local!filteredData,
              expression: a!gridRowLayout(
                id: fv!index,
                contents: {
                  a!integerField(
                    readOnly: true(),
                    value: fv!item.employeeId,
                    saveInto: fv!item.employeeId
                  ),
                  a!textField(
                    value: fv!item.employeeName,
                    saveInto: {
                      fv!item.employeeName,
                      /* Uncomment this code if you want to save the changes on focus out of each field. */
                      /* a!save(
                        local!editableGridData,
                        updatearray(
                          local!editableGridData,
                          wherecontains(
                            local!multiSelectedValues,
                            index(
                              local!editableGridData,
                              "employeeId",
                              {}
                            )
                          ),
                          local!filteredData
                        )
                      ) */
                      
                    }
                  )
                }
              )
            )
          ),
          a!buttonLayout(
            primaryButtons: {
              a!buttonWidget(
                label: "Save Changes",
                saveInto: a!save(
                  local!editableGridData,
                  updatearray(
                    local!editableGridData,
                    wherecontains(
                      local!multiSelectedValues,
                      index(
                        local!editableGridData,
                        "employeeId",
                        {}
                      )
                    ),
                    local!filteredData
                  )
                )
              )
            }
          )
        }
      )
    )

     

    But in the sample code that I have attached, the changes in the selected row(s) would only be reflected when you click on the Save Changes button.

    However you can also save the changes on focus out of every field(then and there) in the grid after making changes. Please uncomment the commented portion in the attached sample code for this behavior.

     

    Hope this helps. :)

Children
No Data