The xamDataGrid sorting functionalities provides users with the ability to sort displayed data via the User Interface (UI) or by writing their own code. Users can sort column data within the UI by clicking on a LabelPresenter for the column to sort. The user can perform sorting in code by modifying the FieldLayout’s SortedFields collection. The xamDataGrid control performs the display and sorting tasks for you enabling your users to sort columns by clicking the column headers; allowing them to view the grid data in whatever order they desire.
Main Settings Summary
Main settings summary chart
The following table summarizes the various settings, along with their interrelationships, available for configuring and performing sorts.
Settings
Description
LabelClickAction
Determines what actions performed when users click on a field label. To enable sorting, you first must set a FieldSettings object’s LabelClickAction property to a LabelClickAction enumeration value.
SortComparer
Setting this property to an object that implements the IComparer interface found in the .NET framework allows users to provide their own sorting logic.
SortComparisonType
Setting this property to a FieldSortComparisonType enumeration value allows you to determine whether the default sorting logic is case-sensitive.
SortEvaluationMode
Setting this property, of the FieldLayoutSettings class specifies how the data presenter performs sorting operations.
This exposes the FieldLayoutSettings class, which can be configured by using property settings for each FieldLayout and by the xamDataGrid’sFieldLayoutSettings property, allowing you to specify the sort evaluation mode for each field layout, and for the control in general.
SortStatus
Exposes this read-only property on both Field and LabelPresenter objects, and allows you to determine a field’s current sort status.
If you need to determine a field’s sort order by writing code, use the Field object’s SortStatus property. However, if you are creating a style or template for the LabelPresenter object, you can use its SortStatus property as a trigger for hiding or showing a sorting indicator.
This setting exposes the read-only property on the Field object. It returns the current group-by sort status (the order of the GroupByRecords) of the field.
When the Label Presenter is in the group-by area, the Label Presenter’s SortStatus property binds to this property.
Label Click Action
Users can sort a field by clicking its header if a Field object’s LabelClickActionResolved property resolves to one of the following values:
Value:
Description
SortByOneFieldOnly
Enables users to perform single field sorting by clicking on its header; does not support sorting on multiply fields.
Toggling a column header alternately sorts the data in ascending or descending order.
SortByMultipleFields
Enables users to perform simultaneous multiple field sorting by holding down the CTRL key and clicking each of the field headers to include in the multiple field sorts.
As with the SortByOneFieldOnly value, users can toggle between ascending and descending sort order by pressing on the column header.
SortByOneFieldOnlyTriState
Enables users to perform on field sorting simply by clicking on the desired field’s header.
Again, users can choose between ascending, descending and unsorted data sorting by clicking on its column header.
SortByMultipleFieldsTriState
Enables users to sort multiple fields simultaneously by holding down the CTRL key and selecting several field headers to include in the sort.
As with the previous case, users can alternate between ascending sorting, descending sorting and unsorted data by clicking on any one of the selected column headers.
Note
Note:
Even if you disable sorting by setting the LabelClickAction property to either Nothing or SelectField, you can still programmatically sort a field. By default, the Label click action property is set to SortByMultipleFields.
Sort Comparer
Used as the comparer for sorting DataRecords within the GroupByRecord grouping; when specified. Additionally, this comparer determines the sort order of the `GroupByRecord`s in either of the following two scenarios:
When specifying a custom GroupByEvaluator, and its SortComparer property returns null
When specifying a custom GroupByEvaluator and its GroupByMode property returns either a Text or Value
Sort Comparison Type
By default, this setting resolves to CaseSensitive.
The control will ignore this setting if you specify a custom SortComparer.
Sort Evaluation Mode
This enumeration has four members:
Value
Description
Auto
The data presenter performs all sorting operations for its record collection internally.
Default
Default is resolved to Auto.
Manual
The data presenter takes no actions when the user sorts a field and the sorting becomes the user’s responsibility. You can use Sorting and Sorted events to detect a change in sorting criteria, and then make the appropriate changes to the order of the data items in the underlying data source.
UseCollectionView
The data presenter manipulates the ICollectionView’s SortedDescriptions collection to reflect the user selected sort criteria if the underlying data source is ICollectionView. The xamDataGrid also synchronize its SortedFields to reflect the ICollectionView sort descriptions, but only for the root field-layout.
In this mode xamDataGrid strips out any duplicate field entries. This happens with grouped fields, as there could be one entry for a field that determines the order of the GroupByRecords and another for the same field, determining the order of the DataRecords within each group.
Related Topics
The following topics provide additional information related to this topic.
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 explains how you can sort and/or group using XAML or procedural code without users clicking a field label or dragging a field label into the group-by area.