Examples › Sorting
To enable sorting, you’ll have to:
- add a
sortable: trueproperty to each column that should be sortable; - set the DataTable
sortStatusproperty to an object describing the current sort status (the column accessor and the sort direction,'asc'or'desc'); - provide an
onSortStatusChangehandler, which is invoked with the new sort status when the user clicks a sortable column header.
Sorting by a different key
Sometimes the value you want to sort by is not the one designated by the column accessor — for instance, when a column renders a value computed from several record properties. In this case, set the column’s sortKey property; it will be included in the sort status object received by onSortStatusChange, so you can use it in your sorting logic.
In the example below, the Name column renders the employee’s full name, but is sorted by last name. Notice that dot-notation accessors such as department.name can be sortable too:
Custom sort icons
To use custom sort icons, pass an object with sorted and unsorted keys to the sortIcons property. The sorted icon should point up; it will be flipped vertically automatically when the sort direction is descending:
Head over to the next example to discover more features.














