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 |
| Nya | Williamson | 40 | complicated | 65 | 92 |
| Foster | Corwin | 49 | complicated | 27 | 96 |
| Kenyon | McLaughlin | 65 | single | 29 | 49 |
| Charlene | Langworth-Davis | 57 | complicated | 40 | 57 |
| Ona | Schultz | 30 | single | 28 | 79 |
| Emely | Bednar | 25 | relationship | 65 | 27 |
| Tatyana | Becker | 38 | single | 84 | 78 |
| Conrad | Emard | 42 | single | 82 | 80 |
| Serenity | Gerlach-Hettinger | 58 | relationship | 87 | 38 |
| Boris | Greenholt | 59 | single | 7 | 3 |
| Anthony | Glover | 55 | relationship | 14 | 38 |
| Amelia | DuBuque | 35 | single | 16 | 59 |
| Tom | Predovic | 46 | relationship | 15 | 92 |
| Murray | Von | 64 | complicated | 30 | 9 |
| Carmella | Rath-Mayert | 52 | relationship | 54 | 91 |
| Emelia | Abshire | 36 | single | 45 | 72 |
| Zachariah | Ziemann | 64 | single | 47 | 13 |
| Javonte | Kuvalis | 33 | complicated | 66 | 60 |
| Myrtis | Leuschke | 44 | single | 79 | 39 |
| Frankie | Schinner | 24 | complicated | 39 | 68 |
| Christa | Rohan | 29 | complicated | 19 | 32 |
| Myrtie | Zieme | 57 | relationship | 9 | 6 |
| Jaylen | Dooley | 63 | complicated | 87 | 14 |
| Adeline | Lebsack | 54 | complicated | 6 | 45 |
| Daija | Hodkiewicz | 41 | complicated | 33 | 7 |
| Trycia | Quigley | 24 | relationship | 81 | 25 |
| Dee | Gulgowski | 31 | complicated | 43 | 76 |
| Lexie | Baumbach | 39 | single | 23 | 73 |
| Yazmin | Kertzmann | 52 | complicated | 12 | 56 |
| Oleta | Franey | 46 | complicated | 84 | 93 |