logo

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
KathlynLind42complicated8781
ElodyLedner35complicated025
ShaneSipes-Jakubowski48single6556
StephaniaWeber59relationship2682
MartinaMarks-Runolfsdottir22single976
RachaelKunze30single10100
MyrlKshlerin41complicated1027
DemarioSipes46single5082
MadgeMitchell60single134
DaphneBrown53relationship2158
VernBecker62single9395
ErnieWeber-Dickinson51single4614
VerdieUllrich27complicated6949
GabriellaBradtke23relationship8168
KieranSchowalter63relationship9178
ChristopBlick20relationship8825
GeneralKunde60complicated9562
UriahGleason53relationship3668
LucioKlein49relationship6113
GiaWeimann58complicated4311
DayanaLeffler62single9131
ChayaBreitenberg-Feil44single3998
KylerJacobson25complicated5155
SimoneDaniel51relationship8217
KurtPadberg61complicated4935
LoriStanton60complicated2669
GilbertHodkiewicz42relationship4954
HeavenVon40complicated709
NobleWillms50single733
SheaMurazik55relationship418