Friday, January 30, 2015

How to Sort a PeopleSoft Grid Column According to Hidden Data Values

Have you ever wanted to display a description of a code in a grid column, but then sort by the actual code when:

  • you click on the column's header or 
  • you call the rowset's Sort() method?
Here's a solution that I came up with.


At BYU in some of our non-PeopleSoft systems, we have Year-Term (instead of STRM) fields.  With a project we are working on right now, the Year-Term needs to be accommodated in our PeopleSoft Campus Solutions environment.  Below is an example of what the year-term codes and descriptions look like side-by-side in a grid column:

Figure 1.

When I click on the Year-Term column header shown in Figure 1, the data will sort correctly, because the Year-Term code is prepended to each value. But what if I don't want to display the code value and still get my data to sort as shown in Figure 2 below when I click on the Year-Term column header?

Figure 2.

(Side-Note: the display of the shaded and outlined icons shown in my screen shots is determined at RowInit time based on whether the corresponding record in the grid has notes associated with it, but that's for another blog article.)

Simply removing the Year-Term code causes the data to be sorted alphabetically, as illustrated below.
Figure 3.

So...how to get the data to sort like Figure 1 but display like Figure 2?  It's all in the use of the HTML comment (i.e. <!--Some hidden text here-->).

Step 1. Place an HTML area as the object that will display the record.field information in your grid column.

Step 2.  Assuming that the HTMLAREA's record field in your grid is named WORK_RECORD.HTMLAREA, set the value of that field in your "TABLE_RECORD" RowInit() PeopleCode to something like the following:
WORK_RECORD.HTMLAREA.Value = 
"<!--" | TABLE_RECORD.Y_YEAR_TERM.Value |
"-->" | describeYearTerm(TABLE_RECORD.YEAR_TERM.Value);
Note:  The describeYearTerm function takes the TABLE_RECORD.YEAR_TERM.Value and returns its description from the YEAR_TERM_TABLE, in "Semester YYYY" format, as illustrated in Figures 1, 2, and 3 above.

Thus the Year-Term code will be included in the values that are placed into the grid column, but only the description of the Year-Term will be displayed.

And the data will sort how you want it to be sorted.

No comments: