Sorting in Code
Server
To apply sorting to a column(s), use one of the following methods.
- Set the column’s GridViewDataColumn.SortOrder property to ColumnSortOrder.Ascending or ColumnSortOrder.Descending.
- Call the column’s GridViewDataColumn.SortAscending or GridViewDataColumn.SortDescending method.
- Call ASPxGridView’s ASPxGridView.SortBy method.
The following sample code sorts data against the Department column in ascending order.
The number of columns involved in sorting is returned by the ASPxGridBase.SortCount property. A collection of sorted columns can be accessed via the ASPxGridView.GetSortedColumns method. The column’s position among sorted columns is specified by the GridViewDataColumn.SortIndex property.
To remove sorting, do one of the following.
- Set the column’s GridViewDataColumn.SortOrder property to ColumnSortOrder.None.
- Call the column’s GridViewDataColumn.UnSort method.
- Set the GridViewDataColumn.SortIndex property to -1.
To clear sorting applied to ASPxGridView, call the ASPxGridBase.ClearSort method.
Client
Use the ASPxClientGridView.SortBy client method to sort data by the values of the specified data column.
To prevent data from being sorted by the values of particular columns, handle the ASPxClientGridView.ColumnSorting client event. The processed client column is identified by the event parameter’s column property. To cancel sorting, set the cancel property to true.
Note
If sorting is disabled for a column, rows cannot be grouped by this column.