Basic example
Add sort: true
to column options to enable sorting for a given column.
Multi sort
It is possible to sort data by multiple columns. To activate multi sort hold the Shift
key while
clicking the column header. You can change the default multi sort key to Ctrl
by using the
following option: multiSortKey: 'ctrl'
Custom sorting logic
It is possible to define custom sort comparator for a column by setting a new comparator
function
in the sortOptions
.
In the following example we use custom dateComparator
for Year column to
transform dates from strings to JavaScript Date Objects before sorting.
Sorting order
The default sorting order is:
ascending -> descending -> none (['asc', 'desc', null]
)
That means when you first time use sorting on a column that is not sorted, it will sort ascending
(asc
). The next click will make it sort descending (desc
) and another click will
remove the sort (null
), reverting to the original data order.
Use sortOrder
option to modify the default sorting order. In the following example we use
different, custom order for each column:
- Column car: descending -> ascending -> none
- Column model: ascending -> descending
- Column car: descending -> ascending
- Column car: ascending -> none
Sorting order
Use defaultSort
option to specify the default sorting state for a column. By default this option
is set to null
.
In the following example we apply default descending sort to the Car column.