Using the UltraGrid's BeforeSortChange and AfterSortChange events
The UltraGrid fires both a BeforeSortChange and an AfterSortChange event when the grid header is clicked and the HeaderClickAction is set to one of the sort options.
The UltraGrid default sort processing is asynchronous. A drawback to asynchronous processing is that the cursor does not automatically change to indicate ongoing processing. To provide the end-user with that visual clue, you can switch to synchronous processing and change the cursor by including code like the following in the BeforeSortChange event:
Setting the HeaderClickAction to ExternalSortSingle or ExternalSortMulti tells the UltraGrid not to do its own sorting. To give access to the sort specified in the UI, the UltraGrid exposes a SortColumns collection on the band. Because this is a collection, you can sort on multiple columns when you specify the ExternalSortMulti option. This collection contains UltraGridColumns that expose a SortIndicator, which reflects the direction of the sort in the UI. The SortColumns are updated in the event, not before the event. So, you implement the ABL sort in the AfterSortChange event to access the SortColumns that correspond to the fired event.
The following code snippet shows an example function that returns a sort string from a band using the band's SortedColumns collection and the sorted columns' SortIndicator. An AfterSortChange event can call this function with the band attribute on the passed BandEventArgs as input and append the returned string to the query of the grid's data source before reopening the query:
METHOD STATIC PUBLIC CHARACTER SortExpression
(band AS Infragistics.Win.UltraWinGrid.UltraGridBand):
DEFINE VARIABLE sortColumn AS Infragistics.Win.UltraWinGrid.UltraGridColumn NO-UNDO.
DEFINE VARIABLE i AS INT NO-UNDO.
DEFINE VARIABLE sortString AS CHAR NO-UNDO.
/* build a sort string from the band's SortedColumns */
DO i = 0 TO band:SortedColumns:Count - 1:
sortColumn = cast(band:SortedColumns[i],
Infragistics.Win.UltraWinGrid.UltraGridColumn).
sortString = sortString + " by " + sortColumn:Key.
IF Progress.Util.EnumHelper:AreEqual(sortColumn:SortIndicator,
Infragistics.Win.UltraWinGrid.SortIndicator:DESCENDING) THEN
sortString = sortString + " descending".
END.
RETURN left-trim(sortString).
END METHOD.