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 |
| Jason | Baumbach | 24 | single | 41 | 67 |
| Elian | Reichel | 39 | complicated | 7 | 58 |
| Columbus | Bergstrom | 50 | single | 45 | 1 |
| Providenci | Paucek | 65 | relationship | 67 | 68 |
| Brisa | Herman | 65 | single | 83 | 73 |
| Edna | Marvin | 27 | complicated | 100 | 2 |
| Matilda | Deckow | 19 | single | 89 | 83 |
| Adrienne | Gulgowski | 65 | single | 62 | 8 |
| Myriam | Jerde | 34 | relationship | 30 | 2 |
| Vince | Jaskolski | 46 | relationship | 80 | 13 |
| Fausto | Brekke | 47 | complicated | 73 | 23 |
| Tamia | Tillman | 57 | complicated | 57 | 42 |
| Eryn | Bradtke | 49 | relationship | 20 | 71 |
| Hipolito | Marquardt | 27 | complicated | 11 | 76 |
| Marianne | Doyle | 63 | relationship | 19 | 58 |
| Estefania | Sporer | 22 | complicated | 71 | 37 |
| Ewald | Dietrich | 37 | complicated | 49 | 36 |
| Katrina | Schuppe | 29 | complicated | 8 | 95 |
| Grayson | Williamson | 44 | complicated | 35 | 17 |
| Prince | Dibbert | 30 | relationship | 7 | 8 |
| Aubrey | Schulist | 43 | complicated | 60 | 53 |
| Isaiah | Gutkowski | 24 | relationship | 68 | 92 |
| Francesco | Christiansen-Cruickshank | 21 | single | 40 | 26 |
| Hermina | Treutel | 32 | single | 60 | 84 |
| Dameon | Trantow | 43 | single | 8 | 73 |
| Jayde | Rodriguez | 49 | complicated | 89 | 9 |
| Robbie | Berge | 49 | complicated | 94 | 37 |
| Kellen | Maggio | 29 | single | 30 | 27 |
| Elijah | Kuhlman | 42 | single | 93 | 95 |
| Gerald | Runolfsdottir-Veum | 60 | relationship | 97 | 38 |