Sorting is controlled by columns.
PropertyColumn
, sorting is enabled if you set Sortable="true"
.
You should do this only if your underlying data source supports sorting by this column's property expression.
TemplateColumn
, sorting is enabled if you
supply a value for the column's SortBy
parameter.
ColumnBase
, sorting is enabled if you set Sortable="true"
or if you override IsSortableByDefault
and return true
.
You can also specify InitialSortDirection
on a column with value SortDirection.Ascending
or
SortDirection.Descending
to indicate the grid's initial sort order.
If you are using an ItemsProvider
callback, the request
parameter gives you access
to the current sort order. It's up to you to translate this into whatever kind of parameters are supported
by your underlying data source.
In most cases you should do this by calling request.GetSortByProperties()
to get a list of
the sort property names and directions. This will work as long as:
ISortBuilderColumn
(the built-in ones do)PropertyColumn
with Property="@(x => x.Medals.Gold)"
is OK, and will give the sort property name "Medals.Gold"
PropertyColumn
with Property="@(x => x.Width * x.Length)"
is not OK, and will make GetSortByProperties
throw an exception.
If you have a column whose sort expression can't be expressed as a chain of property names, then instead
of calling GetSortByProperties
, you will need to read request.SortByColumn
and
request.SortByAscending
and use your own knowledge of the column to convert this into parameter values
for your underlying data source.