How to sort Grid Columns using PeopleCode

PeopleSoft Grids are most common form of data display control and they display fields in spreadsheet like format. Often, we need to provide custom sort for grid columns in various situations.
This can be achieved easily by using Sort Method in Rowset PeopleCode class.
However, there are few things to consider and we will look at it later in this post. First, how do we provide custom Sort in a grid.

Please place the following code in appropriate event to provide custom sorting of a grid;
/* Assuming you grid is in level 1*/
Local Rowset &rsLevel1 = GetLevel0()(1).GetRowset(Scroll.MY_GRID_REC);
&rsLevel1.Sort("MY_GRID_REC.COL1", "A", "MY_GRID_REC.COL2", "A", "MY_GRID_REC.COL3", "D");
Note that MY_GRID_REC.COL1, MY_GRID_REC.COL2, MY_GRID_REC.COL3 are your grid columns that you want to sort and MY_GRID_REC is the primary record of the grid.
"A" specifies ascending order; "D" specifies descending order.

If you are not auto selecting rows to populate in a grid you can achieve the same thing as below;
/*The first example repopulates a rowset in a page programmatically by first flushing its contents, 
selecting new contents using Select, then sorting the rows in ascending order by EXPORT_OBJECT_NAME*/
Function populate_rowset

   &RS1 = GetLevel0()(1).GetRowset(SCROLL.EXPORT_OBJECT);
   &RS1.Select(RECORD.EXPORT_OBJECT, "where export_type =:EXPORT_TYPE_VW.EXPORT_TYPE");


Couple of Points to remember

  • PeopleSoft Application Designer enables the user to personalize a grid at runtime. By default, grid personalization is enabled. If you provide custom sort using PeopleCode and if user personalize the grid at runtime (i.e online) then custom sort will not work afterwards;
  • You can get back the custom sort you provided, by executing the same PeopleCode. To do that have to place a button on the page and allow user to click it to get back the custom sort on the grid.

Ayesha Wee

    Blogger Comment
    Facebook Comment


  1. I think in your first example of SORT:
    &rsLevel1.Sort("MY_GRID_REC.COL1", "A", "MY_GRID_REC.COL2", "A", "MY_GRID_REC.COL3", "D");
    The "s around the MY_GRID_REC.COL1 is not correct syntax.