Version

Sorting and Grouping Process Overview (xamDataGrid)

Topic Overview

Purpose

This topic describes those actions performed by the xamDataGrid™ control s internal comparer for sorting and grouping processes.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic introduces the xamDataGrid control and various elements, on which control is composed.

This topic gives an overview of the grouping functionality of xamDataGrid™. This feature allows users to group data into more readable and navigable way.

This topic gives an overview of sorting functionality of xamDataGrid . xamDataGrid display and handles the sorting for you. Your users can sort columns by clicking the column headers, allowing them to view the grid data in the order they want.

In this topic

This topic contains the following sections:

Sorting and Grouping Process Overview

Sorting and Grouping process

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.

Note
Note

You cannot use the following process if the GroupByEvaluationMode property on FieldLayoutSettings is set to UseCollectionView, or the SortEvaluationMode property is set to either Manual or UseCollectionView.

The internal comparer performs the following:

  1. 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:

    1. 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.

    2. Next, all of the SortedFields collection’s non-grouped fields using either the field’s SortComparer or the default comparer.

    3. 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.

    4. 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.

  1. In its Compare method, implementation selects the high-order field comparer’s (index 0 in the array) as the first field comparer to process.

  2. If calling the field comparer’s Compare method returns anything other than a 0 processing ends and returns that value.

  3. 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.

  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.

  5. Creates the appropriate GroupByRecords to contain any grouped fields after sorting. If possible, the optimized logic attempts to reuse any existing `GroupByRecord`s.

  6. Finally specifying a GroupByComparer for a grouped field using the associated `GroupByRecord`s as part of a second sort pass.

Related Content

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic describes user interactions for sorting records when xamDataGrid records are grouped.

This topic is your gateway to important task-based information that will help you to effectively use the various features and functionalities provided by xamDataGrid control.