KB-1519 Grid data duplicated across multiple pages in a grid when sorting on a non-unique column

Symptoms

Users will notice that one or more rows of data will persist in a grid when moving to another page and sorting on a non-unique column. See the below animation as an example:

Sorting on unique columns does not reproduce the same problem.

Cause

When sorting on a column in a grid, the grid replaces the sort field in the pagingInfo with the column field on which the user clicked. If the column header the user selected is not a unique key for the dataset, then the order of the rows on each page is not guaranteed when you query the same entity. This results in duplicate rows show on multiple pages.

Action

Append the original pagingInfo.sort to the pagingInfo.sort that is saved by the grid field in SAIL. If  the original pagingInfo sorted by the field id, then the user clicks on non-unique column A, then the resulting pagingInfo saved by the grid field should append the "id" field to the sort.

Below is an example of how to add variables/structure to your SAIL grid in order for the grid to sort on a non-unique column and page correctly:

local!originalUniquePagingInfo: a!pagingInfo(
  startIndex: 1,
  batchSize: 7,
  sort: a!sortInfo(
    field: "id",
    ascending: true
  )
),
local!pagingInfo: local!originalUniquePagingInfo,
a!gridField(
  ...
  value: local!pagingInfo,
  saveInto: a!save(
    local!pagingInfo,
    if(
      contains(
        save!value.sort,
        local!originalUniquePagingInfo.sort
      ),
      save!value,
      'type!{http://www.appian.com/ae/types/2009}PagingInfo'(
        startIndex: save!value.startIndex,
        batchSize: save!value.batchSize,
        sort: {
          save!value.sort,
          local!originalUniquePagingInfo.sort
        }
      )
    )
  )
  ...
)

Affected Versions

This article applies to all versions of Appian.

Last Reviewed: March 2018

Related
Recommended