Like most grids, the C1FlexGrid supports sorting. Clicking on a column header will sort the data in ascending or descending order. When the grid is sorted, a triangle is displayed in the corresponding column to indicate the current sort direction.
In addition to the regular sort toggle behavior, the C1FlexGrid also allows users to remove the sorting by control-clicking column headers. This removes the sorting applied to the column and causes the data to be displayed in the original order.
Like grouping, sorting is actually performed by the ICollectionView used as a data source. The grid simply detects mouse clicks and defers the sorting to the data source object. You can also sort the data directly using code.
For example, the code below sorts the data by name and country:
// start clean
view.SortDescriptions.Clear();
// sort by name
view.SortDescriptions.Add(
new SortDescription("Name", ListSortDirection.Ascending));
// and then by country
view.SortDescriptions.Add(
new SortDescription("Country", ListSortDirection.Ascending));
Note that after this code is invoked, the grid will automatically show the data in the new sort order and will also show the triangle sort indicator in the country column header.
You can disable grid sorting by setting the AllowSorting property to false, or disable it for specific columns by setting the Column.AllowSorting property to false. You can also prevent the grid from showing the sort triangle by setting the ShowSort property to false.