Skip to main content
March 18, 2021
Question

Paging reset to 1 on button click, if update happen on another page

  • March 18, 2021
  • 6 replies
  • 0 views

having issue on the APN 20.1 with gridFiled, Paging reset to original page on UPDATE DATA button click, if the selected row is update from next page. 

a!localVariables(
  local!selection,
  local!selectedEmployees,
  local!employeeDS: {
    {id: 11,name: "Elizabeth Ward",dept: "Engineering",startDate: today() - 500},
    {id: 22,name: "Michael Johnson",dept: "Finance",startDate: today() - 100},
    {id: 33,name: "John Smith",dept: "Engineering",startDate: today() - 1000},
    {id: 44,name: "Diana Hellstrom",dept: "Engineering",startDate: today() - 1200},
    {id: 55,name: "Francois Morin",dept: "Sales",startDate: today() - 700},
    {id: 66,name: "Maya Kapoor",dept: "Sales",startDate: today() - 1400},
    {id: 77,name: "Anthony Wu",dept: "Human Resources",startDate: today() - 300}
  },
  {
    a!richTextDisplayField(
      label: "",
      labelPosition: "COLLAPSED",
      value: {
        a!richTextHeader(
          text: "Paging reset to 1 on ""UPDATE DATA"" button click, if update happen on another page"
        )
      }
    ),
    a!columnsLayout(
      columns: {
        a!columnLayout(
          contents: {
            a!gridField(
              label: "Employee Directory",
              data: todatasubset(
                local!employeeDS,
                fv!pagingInfo
              ),
              columns: {
                a!gridColumn(
                  label: "Name",
                  sortField: "name",
                  value: fv!row.name
                ),
                a!gridColumn(
                  label: "Department",
                  sortField: "dept",
                  value: fv!row.dept
                ),
                a!gridColumn(
                  label: "Start Date",
                  sortField: "startDate",
                  value: fv!row.startDate,
                  align: "END"
                )
              },
              pageSize: 3,
              selectable: true,
              selectionValue: local!selection,
              selectionSaveInto: {
                local!selection,
                a!save(
                  local!selectedEmployees,
                  index(
                    fv!selectedRows,
                    length(fv!selectedRows),
                    null
                  )
                ),
                a!save(
                  local!selection,
                  index(
                    save!value,
                    length(save!value),
                    null
                  )
                )
              }
            )
          }
        )
      },
      stackWhen: {
        "PHONE",
        "TABLET_PORTRAIT"
      }
    ),
    a!buttonArrayLayout(
      buttons: {
        a!buttonWidget(
          label: "Update Data",
          saveInto: {
            a!save(
              local!employeeDS,
              remove(
                local!employeeDS,
                wherecontains(
                  touniformstring(local!selectedEmployees.id),
                  touniformstring(local!employeeDS.id)
                )
              )
            ),
            a!save(
              local!employeeDS,
              append(
                local!employeeDS,
                local!selectedEmployees
              )
            ),
            a!save(
              local!employeeDS,
              todatasubset(
                arrayToPage: local!employeeDS,
                pagingConfiguration: a!pagingInfo(
                  startIndex: 1,
                  batchSize: 10,
                  sort: a!sortInfo(
                    field: "id",
                    ascending: true
                  )
                )
              ).data
            )
          },
          submit: false,
          style: "NORMAL"
        )
      },
      align: "START"
    )
  }
)

    6 replies

    mikes0011
    Brainy
    March 18, 2021

    two quick things:

    1. code this long is much much easier for us to read if you use the "Code Box" functionality available in the "Insert" menu, sub-heading "Insert Code".  It uses a friendly font size and style for reading through code, as well as preserving indentation and some degree of formatting, and keeps code from blowing out a post's length to require a lot of scrolling such as has happened here.
    2. What exactly are you trying to do, and what is happening instead?  I'm a little unclear, though it seems like you're saying you want the start index to revert to 1 when the user uses that button.  Can you confirm?
    March 18, 2021

    Hey Mike, 

    Its standalone code, so you can play with it. Use case when you click on the next page on the grid. and select some value and click on button. the grid resets from current page and goes back to initial page. 

    mikes0011
    Brainy
    March 18, 2021

    Thanks for editing to include a Code Box.

    As far as your issue: are you saying you don't want it to revert to the first plage any time the button is clicked?