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
MadelynnWilderman31complicated2492
ChayaHowe48single4050
MikelKassulke19relationship7811
DannieWindler18relationship737
DedrickWitting36relationship67100
LinneaTremblay58complicated9873
FredrickBernier65relationship5012
FaustoKoelpin46complicated899
ElizaSchaden38relationship4378
EstrellaDach-Rau59relationship738
GrayceReichert54single8521
GradyBrakus41single1814
RaymondKling27single4437
HattieHickle39relationship2749
JanieBatz43single8842
JadonDouglas52complicated7388
OlafOsinski56relationship8393
ElzaHoeger48relationship8682
DomenicBayer60single5061
JaneMcDermott46single4367
KristaConsidine37complicated6710
JodyKuhn63relationship8582
JerrellMcDermott63single10011
MaverickWest18single9326
ClaudeStoltenberg30single7253
VitoKuhlman35complicated112
KellenPacocha27relationship7187
ElmoreDaugherty43relationship541
FranciscaNader60single173
AndreGrant21relationship2216