Refresh option in grid not working

Hi All,

Trying to refresh using a refresh variable in grid. Facing issue with refresh. Please find below code and let me know if any changes are required.

a!localVariables(
  local!refreshCounter: 0,
  local!startIndex: a!refreshVariable(
    value: 1,
    refreshOnVarChange: local!refreshCounter
  ),
  local!pagingInfo: a!pagingInfo(local!startIndex, 5),
  local!data: a!refreshVariable(
    value: rule!S_getAPI(),
    refreshOnVarChange: local!refreshCounter
  ),
  {
    a!buttonArrayLayout(
      a!buttonWidget(
        label: "Refresh",
        size: "SMALL",
        style: "SECONDARY",
        saveInto: {
          a!save(
            local!refreshCounter,
            local!refreshCounter + 1
          ),
          
        }
      )
    ),
    a!gridField(
      label: "Data",
      labelPosition: "ABOVE",
      data: local!data,
      columns: {
        a!gridColumn(
          label: "First Name",
          sortField: "firstName",
          value: fv!row.firstName
        ),
        a!gridColumn(
          label: "Last Name",
          sortField: "lastName",
          value: fv!row.lastName
        ),
        a!gridColumn(
          label: "Email",
          sortField: "email",
          value: fv!row.email
        ),
        a!gridColumn(
          label: "Phone",
          sortField: "phone",
          value: fv!row.phone
        )
      },
      validations: {},
      pagingSaveInto: a!save(
        local!startIndex,
        fv!pagingInfo.startIndex
      )
    )
  }
)

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    In gridfield we have the refreshOnVarChange - use it.
    a!gridField(....,

    refreshOnvarChange:local!refreshCounter)

  • 0
    Certified Lead Developer
    in reply to nagarajanc
    In gridfield we have the refreshOnVarChange

    AFAIK that may only do anything when the grid itself is querying the data.

  • 0
    Certified Lead Developer

    Your code box worked fine, i'm unclear why you also pasted the code a second time below it - that just makes your original post harder to read.

    Your refreshCounter setup looks generally OK - that's how I'd configure it for a start.  I'm a little unclear what you're doing with your local!pagingInfo variable, as it doesn't seem to actually get used/referenced at all in your query.

    As far as the data query itself - what's happening inside rule!S_getAPI()?  If it's using its own local variables then you might need to push a reference to your refreshVariable into it as well.  Also, what are you expecting to see when you click "refresh"?  As in, are you sure the data queried will be different when you test it?  If it's still the same, for instance, you wouldn't see any change on the front end, until some update has happened in the source data, even if the refresh functionality is working fine.

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    The Grid is refreshing the data even when the data is coming from the local variable. Please try the attached code snippet. 

    a!localVariables(
      local!refreshCounter: 0,
      local!startIndex:1,
      local!pagingInfo: a!pagingInfo(local!startIndex, 5),
      local!data:  {
          {firstName:"a"},
          {firstName:"b"},
          {firstName:"c"},
          {firstName:"d"},
          {firstName:"e"},
          {firstName:"f"},
          {firstName:"g"},
          {firstName:"h"},
          {firstName:"i"}
        },
      {
        a!buttonArrayLayout(
          a!buttonWidget(
            label: "Refresh",
            size: "SMALL",
            style: "SECONDARY",
            saveInto: {
              a!save(
                local!refreshCounter,
                local!refreshCounter + 1
              ),
    
            }
          )
        ),
        a!gridField(
          label: "Data",
          labelPosition: "ABOVE",
          data: local!data,
          columns: {
            a!gridColumn(
              label: "First Name",
              sortField: "firstName",
              value: fv!row.firstName
            )
          },
          pageSize: 3,
          refreshOnVarChange: local!refreshCounter,
          pagingSaveInto: a!save(
            local!startIndex,
            fv!pagingInfo.startIndex
          )
        )
      }
    )