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 |
| Lauren | Harris | 27 | relationship | 62 | 30 |
| Carroll | Schaden | 58 | relationship | 49 | 85 |
| Hubert | Metz | 28 | complicated | 10 | 22 |
| Margaret | Howell | 56 | single | 58 | 16 |
| Stanley | Keebler | 38 | single | 78 | 54 |
| Gary | Balistreri | 29 | single | 6 | 100 |
| Norwood | Ledner | 35 | complicated | 4 | 99 |
| Donnie | Rippin | 36 | relationship | 1 | 80 |
| Martin | Johns | 34 | relationship | 55 | 98 |
| Natasha | Johnson | 48 | single | 66 | 17 |
| Seth | Little | 28 | complicated | 92 | 59 |
| Hector | Shanahan | 47 | complicated | 17 | 59 |
| Dejuan | Goodwin | 18 | relationship | 63 | 29 |
| Delia | Lowe | 58 | relationship | 99 | 4 |
| Shane | O'Keefe | 56 | single | 3 | 23 |
| Gwendolyn | Bergstrom | 20 | relationship | 39 | 67 |
| Loren | Wilkinson | 39 | complicated | 20 | 42 |
| Andre | Quigley | 55 | single | 78 | 50 |
| Nina | Stanton | 39 | relationship | 72 | 0 |
| Marshall | Howell | 62 | single | 57 | 92 |
| Darrell | Maggio | 60 | single | 68 | 85 |
| Brendan | Stroman | 56 | single | 35 | 57 |
| Oscar | Breitenberg | 38 | single | 22 | 88 |
| Ervin | Johns | 62 | single | 64 | 39 |
| Paula | Pouros | 65 | single | 24 | 79 |
| Jake | Gulgowski | 26 | complicated | 8 | 20 |
| Nicolas | Ratke | 60 | complicated | 99 | 65 |
| Chet | Skiles | 33 | single | 99 | 100 |
| Sebastian | Nitzsche | 21 | relationship | 62 | 35 |
| Julianne | Gibson | 37 | single | 44 | 1 |