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
LaverneHarris27relationship6230
CarlSchaden58relationship4985
HenryMetz28complicated1022
MargieHowell56single5816
StanleyKeebler38single7854
FrederickBalistreri29single6100
NilsLedner35complicated499
DominickRippin36relationship180
MathewJohns34relationship5598
NellieJohnson48single6617
SergioLittle28complicated9259
HelmerShanahan47complicated1759
DejaGoodwin18relationship6329
DeborahLowe58relationship994
SethO'Keefe56single323
GloriaBergstrom20relationship3967
LowellWilkinson39complicated2042
AmosQuigley55single7850
NinaStanton39relationship720
MathewHowell62single5792
DarnellMaggio60single6885
BrayanStroman56single3557
OtisBreitenberg38single2288
EsperanzaJohns62single6439
PaulettePouros65single2479
JailynGulgowski26complicated820
NoelRatke60complicated9965
ClaraSkiles33single99100
SchuylerNitzsche21relationship6235
JulietGibson37single441