Data rows can be sorted in either a descending or ascending direction according to the values of one or more columns. Groups are automatically sorted in the same direction as the column set in the group's GroupBy property. In order to sort groups that were created using only custom grouping, the group's GroupBy property must be set even though it will not cause groups to be created based on the values of the column set in its GroupBy property.
To sort a column, its SortDirection property must be set. Setting a column's SortDirection property to either ascending or descending, will automatically add it to the grid's collection of SortedColumns. Setting the column's SortDirection property to none will remove any sorting presently applied on the column and remove it from the grid's collection of SortedColumns.
To do custom sorting, set the DataComparer property of the column whose values are to be sorted. Any class that implements the IComparer interface can be used.
Currently, there is no built-in functionality that allows for data rows to be filtered automatically, however there are three possible workarounds that can simulate filtering:
1- Set the Visible property of the rows that need to be filtered to false (this is is normally done in the CellValueChanged event of the datarow template). This workaround would be sufficient in the case of grids that do not contain much data, however in the case of grids that contain a lot of data, the process can be slow.
In the following example, all the rows whose products are discontinued will be filtered by having their Visible properties set to false. However if there are groups in the grid, the empty groups (those whose data rows are not visible), will still be visible.
View code
C# | Copy Code |
---|---|
|
The code below will create 2 groups which will provide the same presentation as if the data rows were not grouped: Neither of the groups will have rows in their header or footer sections, the "Filtered" group will be collapsed and the visible group will have no margin.
View code
C# | Copy Code |
---|---|
|
The code below will create 3 groups: the first will contain all products whose names begin with the letter A to N, the second group will contain all products whose names begin with the letter M to Z while all the groups that are discontinued will be in a third group called "Filtered" which will not be visible.
If the grid contains one or more GroupByRow's, the empty groups will appear in it. You can change the title of the "invisible" group as it appears in the GroupByRow, by setting the group's GroupByRowTitle property.
View code
C# | Copy Code |
---|---|
|
3- Bind the grid to a DataView object! By setting the RowFilter property of the DataView object, the grid will only display the rows which have not been filtered out by the DataView object.
Do you want to prevent columns from being sorted at runtime by the end-user? Set the ColumnManagerRow's or GroupByRow's AllowSort property to false.
Do you want to prevent columns from being sorted at both runtime and programmatically? Set the column's CanBeSorted property to false.
Do you want to prevent groups from being created according to the values of a specific column? Set the column's CanBeGrouped property to false.