Try OpenEdge Now
skip to main content
GUI for .NET Programming
Binding ABL Data to .NET Controls : Managing data updates : Sorting : Sorting child tables for a recursive data-relation
 
Sorting child tables for a recursive data-relation
If a grid control is bound to a ProDataSet with a recursive data-relation, it presents an additional level of complexity. When the recursive data-relation is defined in the ProDataSet, it has a single buffer for the child table. For example:
DEFINE DATASET dsetMyrecurs FOR ttEmp
  DATA-RELATION drel1 FOR ttEmp, ttEmp
  RELATION-FIELDS(Emp-name, Manager) RECURSIVE.
But because the data-relation is defined recursively, this maps to multiple bands in the grid's hierarchical control. A band consists of all the records at a given level in the hierarchical display. Internally, the AVM needs to create a separate buffer for each band in the control, each with a unique buffer name. For example, if you have defined the following recursive data-relation with child table ttemp, the AVM will create a new buffer object for each band in the hierarchy naming them ttemp1, ttemp2, ttemp3, and so on.
You need to be aware of this if you are subscribing to the grid's sort event and writing your own sorting code in ABL. The band's key name from the grid control will be the unique buffer name, the one corresponding to the band that the sort request was made from. When using this to set a new value for the data-relation WHERE-STRING attribute in the sort event handler, you must map it to the original child table's buffer name. For example, using an UltraGrid control:
USING Infragistics.Win.UltraWinGrid.* FROM ASSEMBLY.

PROCEDURE ultraGrid1_AfterSortChange:
  /* Progress.Data.BindingSource */
DEFINE INPUT PARAMETER sender AS System.Object.
DEFINE INPUT PARAMETER eventArgs AS BandEventArgs.

  DEFINE VARIABLE sortColumn AS UltraGridColumn NO-UNDO.
  DEFINE VARIABLE sortString AS CHARACTER NO-UNDO.
  DEFINE VARIABLE cBandKey AS CHARACTER NO-UNDO.

  /* cOriginalWhereString to be set from initial drelHdl:WHERE-STRING */
  DEFINE VARIABLE cOriginalWhereString AS CHARACTER NO-UNDO.
  DEFINE VARIABLE drelHdl AS HANDLE NO-UNDO.

  sortColumn = CAST(eventArgs:Band:SortedColumns[0], UltraGridColumn).
  IF sortColumn:Band:Key BEGINS "ttemp" THEN
    ASSIGN cBandKey = "ttemp".
  ELSE
    ASSIGN cBandKey = sortColumn:Band:Key.

  sortString = " BY " + cBandKey + "." + sortColumn:Key.

  IF EnumHelper:AreEqual
       (sortColumn:SortIndicator, SortIndicator:Descending) THEN
    sortString = sortString + " DESCENDING".
  
  ASSIGN
    drelHdl = DATA-RELATION drel1:HANDLE /* From the dsetMyrecurs example */
    drelHdl:WHERE-STRING = cOriginalWhereString + " " + sortString.

  CAST(sender, Progress.Data.BindingSource):RefreshAll( ).
END.
Note: For more information on using bands to access the child queries of recursive data-relations, see Finding the proper child query in a ProDataSet.