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
LaurenHarris27relationship6230
CarrollSchaden58relationship4985
HubertMetz28complicated1022
MargaretHowell56single5816
StanleyKeebler38single7854
GaryBalistreri29single6100
NorwoodLedner35complicated499
DonnieRippin36relationship180
MartinJohns34relationship5598
NatashaJohnson48single6617
SethLittle28complicated9259
HectorShanahan47complicated1759
DejuanGoodwin18relationship6329
DeliaLowe58relationship994
ShaneO'Keefe56single323
GwendolynBergstrom20relationship3967
LorenWilkinson39complicated2042
AndreQuigley55single7850
NinaStanton39relationship720
MarshallHowell62single5792
DarrellMaggio60single6885
BrendanStroman56single3557
OscarBreitenberg38single2288
ErvinJohns62single6439
PaulaPouros65single2479
JakeGulgowski26complicated820
NicolasRatke60complicated9965
ChetSkiles33single99100
SebastianNitzsche21relationship6235
JulianneGibson37single441