This topic describes those actions performed by the xamDataGrid™ control ’ s internal comparer for sorting and grouping processes.
The following topics are prerequisites to understanding this topic:
This topic contains the following sections:
By default, an optimized internal comparer sorts all of the xamDataGrid DataRecords. The remainder of this topic provides additional information about the control’s optimizations made with this release along with a detailed description of the process.
The internal comparer performs the following:
It creates an array of individual field comparers and caches other relatable information inside its constructor. The field comparers are sequenced within the array in the following order:
First, all of the SortedFields collection’s grouped fields (they are the high-order criteria) using their IGroupByEvaluator
SortComparer objects. If any of these is Null
, then that field will use either the SortComparer
or the default comparer.
Next, all of the SortedFields
collection’s non-grouped fields using either the field’s SortComparer
or the default comparer.
Finally, all of the SortedFields
collection’s grouped fields, appearing only once in the collection (in other words they were not added in again in step ‘b’) being appended to the end again. This time ignoring the IGroupByEvaluator.SortComparer
and instead uses either the field’s SortComparer
or the default comparer.
If any of the field comparers from step ‘b’ or step’ ‘c’ are unnecessary (that is IGroupByEvaluator.SortComparer
returned Null
), then those comparers are not added to the array a second time. Instead, this is where the control performs its other array pruning optimizations thus avoiding any unnecessary overhead during the sort.
In its Compare method, implementation selects the high-order field comparer’s (index 0 in the array) as the first field comparer to process.
If calling the field comparer’s Compare method returns anything other than a 0 processing ends and returns that value.
Otherwise, the field comparer returns a 0 to indicate that the 2 `DataRecord`s are equal as far as that comparer is concerned; it increases the array index and checks the next field comparer by repeating steps 3 and 4.
If all of the field sort comparers in the array return 0, indicating that they are all equal, the control uses the relative indexes of the associated Data Items in the Data Source for the final comparison. Additionally, it caches the Data Item indices to avoid repeatedly performing the IndexOf
operation on the data source to query the data item index during the comparison process.
Creates the appropriate GroupByRecords to contain any grouped fields after sorting. If possible, the optimized logic attempts to reuse any existing `GroupByRecord`s.
Finally specifying a GroupByComparer for a grouped field using the associated `GroupByRecord`s as part of a second sort pass.
The following topics provide additional information related to this topic.