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 |
| Madelynn | Wilderman | 31 | complicated | 24 | 92 |
| Chaya | Howe | 48 | single | 40 | 50 |
| Mikel | Kassulke | 19 | relationship | 78 | 11 |
| Dannie | Windler | 18 | relationship | 73 | 7 |
| Dedrick | Witting | 36 | relationship | 67 | 100 |
| Linnea | Tremblay | 58 | complicated | 98 | 73 |
| Fredrick | Bernier | 65 | relationship | 50 | 12 |
| Fausto | Koelpin | 46 | complicated | 8 | 99 |
| Eliza | Schaden | 38 | relationship | 43 | 78 |
| Estrella | Dach-Rau | 59 | relationship | 73 | 8 |
| Grayce | Reichert | 54 | single | 85 | 21 |
| Grady | Brakus | 41 | single | 18 | 14 |
| Raymond | Kling | 27 | single | 44 | 37 |
| Hattie | Hickle | 39 | relationship | 27 | 49 |
| Janie | Batz | 43 | single | 88 | 42 |
| Jadon | Douglas | 52 | complicated | 73 | 88 |
| Olaf | Osinski | 56 | relationship | 83 | 93 |
| Elza | Hoeger | 48 | relationship | 86 | 82 |
| Domenic | Bayer | 60 | single | 50 | 61 |
| Jane | McDermott | 46 | single | 43 | 67 |
| Krista | Considine | 37 | complicated | 67 | 10 |
| Jody | Kuhn | 63 | relationship | 85 | 82 |
| Jerrell | McDermott | 63 | single | 100 | 11 |
| Maverick | West | 18 | single | 93 | 26 |
| Claude | Stoltenberg | 30 | single | 72 | 53 |
| Vito | Kuhlman | 35 | complicated | 11 | 2 |
| Kellen | Pacocha | 27 | relationship | 71 | 87 |
| Elmore | Daugherty | 43 | relationship | 54 | 1 |
| Francisca | Nader | 60 | single | 1 | 73 |
| Andre | Grant | 21 | relationship | 22 | 16 |