Issue with Edit and Delete Row Actions in Editable Grid

I am loading data from an Excel sheet into an Editable Grid. I added Edit and Delete buttons for each row, but the actions are not functioning as expected. Could someone guide me on how to fix this or share the correct approach?

I

a!localVariables(
  local!data: 309474,
  local!sheetCount: getnumberofsheets(document: local!data),
  local!sheetIndexes: enumerate(local!sheetCount),
  local!activeTab: 1,
  local!readOnly: tointeger({}),
  local!sheets: a!forEach(
    items: local!sheetIndexes,
    expression: a!localVariables(
      local!sheetNumber: fv!item,
      local!excelOutput: readexcelsheetpaging(
        excelDocument: local!data,
        sheetNumber: local!sheetNumber,
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 1000)
      ),
      local!rows: index(local!excelOutput, "data", {}),
      local!totalRow: tointeger(
        index(local!excelOutput, "totalCount", 0)
      ),
      local!rowHeaderRaw: index(index(local!rows, 1, {}), "values", {}),
      local!headers: a!forEach(
        items: enumerate(length(local!rowHeaderRaw)),
        expression: a!localVariables(
          local!colIndex: fv!item + 1,
          local!txtTrimmed: trim(
            tostring(
              index(local!rowHeaderRaw, local!colIndex, "")
            )
          ),
          local!txtNoCR: substitute(local!txtTrimmed, char(13), ""),
          local!txtNoCRLF: substitute(local!txtNoCR, char(10), ""),
          if(
            a!isNullOrEmpty(local!txtNoCRLF),
            "Col_" & local!colIndex,
            local!txtNoCRLF
          )
        )
      ),
      local!dataRowCount: if(
        local!totalRow > 1,
        min(local!totalRow - 1, 999),
        0
      ),
      local!rowIndexes: if(
        local!dataRowCount > 0,
        enumerate(local!dataRowCount) + 2,
        {}
      ),
      {
        sheetNumber: local!sheetNumber,
        headers: local!headers,
        data: a!forEach(
          items: local!rowIndexes,
          expression: a!localVariables(
            local!values: index(
              index(local!rows, fv!item, {}),
              "values",
              {}
            ),
            local!pairs: a!forEach(
              items: enumerate(length(local!headers)),
              expression: a!localVariables(
                local!colIndex: fv!item + 1,
                local!key: index(local!headers, local!colIndex, ""),
                local!valRaw: tostring(index(local!values, local!colIndex, "")),
                local!valEsc1: substitute(
                  local!valRaw,
                  char(92),
                  char(92) & char(92)
                ),
                local!valEsc2: substitute(
                  local!valEsc1,
                  char(34),
                  char(92) & char(34)
                ),
                local!valEsc3: substitute(local!valEsc2, char(13), char(92) & "n"),
                local!valEsc: substitute(local!valEsc3, char(10), char(92) & "n"),
                concat(
                  char(34),
                  local!key,
                  char(34),
                  ":",
                  char(34),
                  local!valEsc,
                  char(34)
                )
              )
            ),
            local!json: concat("{", joinarray(local!pairs, ","), "}"),
            a!fromJson(local!json)
          )
        )
      }
    )
  ),
  local!activeSheet: index(local!sheets, local!activeTab, {}),
  local!gridData: index(local!activeSheet, "data", {}),
  local!gridHeaders: index(local!activeSheet, "headers", {}),
  {
    a!radioButtonField(
      label: "Select Sheet",
      labelPosition: "ABOVE",
      choiceLabels: a!forEach(
        items: enumerate(length(local!sheets)),
        expression: concat("Sheet ", fv!item + 1)
      ),
      choiceValues: enumerate(length(local!sheets)) + 1,
      value: local!activeTab,
      saveInto: {
        a!save(local!activeTab, save!value),
        a!save(local!readOnly, tointeger({}))
      },
      required: false
    ),
    a!gridLayout(
      label: concat(
        "Sheet ",
        local!activeTab,
        " - ",
        length(local!gridData),
        " rows"
      ),
      labelPosition: "ABOVE",
      headerCells: append(
        a!forEach(
          items: local!gridHeaders,
          expression: a!gridLayoutHeaderCell(label: fv!item)
        ),
        a!gridLayoutHeaderCell(label: ""),
        a!gridLayoutHeaderCell(label: "")
      ),
      columnConfigs: append(
        a!forEach(
          items: enumerate(length(local!gridHeaders)),
          expression: a!gridLayoutColumnConfig(width: "DISTRIBUTE")
        ),
        a!gridLayoutColumnConfig(width: "ICON"),
        a!gridLayoutColumnConfig(width: "ICON")
      ),
      rows: a!forEach(
        items: enumerate(length(local!gridData)) + 1,
        expression: a!localVariables(
          local!rowIndex: fv!item,
          local!rowData: index(local!gridData, local!rowIndex, {}),
          a!gridRowLayout(
            contents: append(
              a!forEach(
                items: local!gridHeaders,
                expression: a!localVariables(
                  local!columnName: fv!item,
                  a!textField(
                    value: index(local!rowData, local!columnName, ""),
                    saveInto: a!save(
                      local!gridData[local!rowIndex][local!columnName],
                      save!value
                    ),
                    readOnly: a!isNullOrEmpty(
                      wherecontains(local!rowIndex, local!readOnly)
                    )
                  )
                )
              ),
              a!richTextDisplayField(
                value: if(
                  a!isNullOrEmpty(
                    wherecontains(local!rowIndex, local!readOnly)
                  ),
                  a!richTextIcon(
                    icon: "pencil",
                    caption: "Edit Record",
                    linkStyle: "STANDALONE",
                    link: a!dynamicLink(
                      saveInto: a!save(
                        local!readOnly,
                        append(
                          local!readOnly,
                          tointeger(local!rowIndex)
                        )
                      )
                    )
                  ),
                  a!richTextIcon(
                    icon: "floppy-o",
                    color: "POSITIVE",
                    caption: "Save record",
                    linkStyle: "STANDALONE",
                    link: a!dynamicLink(
                      saveInto: a!save(
                        local!readOnly,
                        remove(
                          local!readOnly,
                          wherecontains(local!rowIndex, local!readOnly)
                        )
                      )
                    )
                  )
                )
              ),
              a!richTextDisplayField(
                value: a!richTextIcon(
                  icon: "trash",
                  color: "NEGATIVE",
                  linkStyle: "STANDALONE",
                  caption: "Delete row",
                  link: a!dynamicLink(
                    saveInto: {
                      a!save(
                        local!gridData,
                        remove(local!gridData, local!rowIndex)
                      ),
                      a!save(
                        local!readOnly,
                        compact(
                          a!forEach(
                            items: local!readOnly,
                            expression: if(
                              fv!item < local!rowIndex,
                              fv!item,
                              if(fv!item = local!rowIndex, null, fv!item - 1)
                            )
                          )
                        )
                      )
                    }
                  )
                )
              )
            )
          )
        )
      ),

      shadeAlternateRows: true
    )
  }
)


  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Compact() returns text array but local!readOnly needs integers, breaking delete logic and row indexing.
    Replace line 211 with

    a!save(
      local!readOnly,
      tointeger(
        reject(
          fn!isnull(_),
          a!forEach(
            items: local!readOnly,
            expression: if(
              fv!item < local!rowIndex,
              fv!item,
              if(fv!item = local!rowIndex, null, fv!item - 1)
            )
          )
        )
      )
    )
    



    Replace line number 157 with

    not(a!isNullOrEmpty(wherecontains(local!rowIndex, local!readOnly)))

Reply
  • 0
    Certified Lead Developer

    Compact() returns text array but local!readOnly needs integers, breaking delete logic and row indexing.
    Replace line 211 with

    a!save(
      local!readOnly,
      tointeger(
        reject(
          fn!isnull(_),
          a!forEach(
            items: local!readOnly,
            expression: if(
              fv!item < local!rowIndex,
              fv!item,
              if(fv!item = local!rowIndex, null, fv!item - 1)
            )
          )
        )
      )
    )
    



    Replace line number 157 with

    not(a!isNullOrEmpty(wherecontains(local!rowIndex, local!readOnly)))

Children