addSortBy
addSortBy sorts table rows by column values.
Options
Information:
Options passed into
addSortBy.const table = createTable(data, {
sort: addSortBy({ ... }),
});const table = createTable(data, {
sort: addSortBy({ ... }),
});initialSortKeys?: SortKey[]
Sets the initial sort keys.
Defaults to [].
disableMultiSort?: boolean
Disables multi-sorting for the table.
Defaults to false.
isMultiSortEvent?: (event: Event) => boolean
Allows overriding the default multi-sort behavior.
Takes an Event and returns whether the action triggers a multi-sort.
Defaults to multi-sort on shift-click.
toggleOrder?: ()[]
Allows customization of the toggling order. This cannot contain duplicate values. Set this to ['asc', 'desc'] to disable toggling to an unsorted column.
Defaults to ['asc', 'desc', undefined].
serverSide?: boolean
If true, the sort plugin will have no effect on the rows of the table. Instead, you can control sorting by updating $data. The plugin’s state can be used as variables in your data-fetching query to get sorted data from the server directly.
Defaults to false.
Column Options
Information:
Options passed into column definitions.
const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
plugins: {
sort: { ... },
},
}),
]);const columns = table.createColumns([
table.column({
header: 'Name',
accessor: 'name',
plugins: {
sort: { ... },
},
}),
]);Examples
$sortKeys = []
| Name | Info | ||||
|---|---|---|---|---|---|
| First Name | Last Name | Age | Status | Visits | Profile Progress |
| Kathlyn | Lind | 42 | complicated | 87 | 81 |
| Elody | Ledner | 35 | complicated | 0 | 25 |
| Shane | Sipes-Jakubowski | 48 | single | 65 | 56 |
| Stephania | Weber | 59 | relationship | 26 | 82 |
| Martina | Marks-Runolfsdottir | 22 | single | 97 | 6 |
| Rachael | Kunze | 30 | single | 10 | 100 |
| Myrl | Kshlerin | 41 | complicated | 10 | 27 |
| Demario | Sipes | 46 | single | 50 | 82 |
| Madge | Mitchell | 60 | single | 1 | 34 |
| Daphne | Brown | 53 | relationship | 21 | 58 |
| Vern | Becker | 62 | single | 93 | 95 |
| Ernie | Weber-Dickinson | 51 | single | 46 | 14 |
| Verdie | Ullrich | 27 | complicated | 69 | 49 |
| Gabriella | Bradtke | 23 | relationship | 81 | 68 |
| Kieran | Schowalter | 63 | relationship | 91 | 78 |
| Christop | Blick | 20 | relationship | 88 | 25 |
| General | Kunde | 60 | complicated | 95 | 62 |
| Uriah | Gleason | 53 | relationship | 36 | 68 |
| Lucio | Klein | 49 | relationship | 61 | 13 |
| Gia | Weimann | 58 | complicated | 43 | 11 |
| Dayana | Leffler | 62 | single | 91 | 31 |
| Chaya | Breitenberg-Feil | 44 | single | 39 | 98 |
| Kyler | Jacobson | 25 | complicated | 51 | 55 |
| Simone | Daniel | 51 | relationship | 82 | 17 |
| Kurt | Padberg | 61 | complicated | 49 | 35 |
| Lori | Stanton | 60 | complicated | 26 | 69 |
| Gilbert | Hodkiewicz | 42 | relationship | 49 | 54 |
| Heaven | Von | 40 | complicated | 70 | 9 |
| Noble | Willms | 50 | single | 73 | 3 |
| Shea | Murazik | 55 | relationship | 4 | 18 |