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
KristyHarris27relationship6230
CamrenSchaden58relationship4985
HalMetz28complicated1022
MabelHowell56single5816
StephonKeebler38single7854
FrankBalistreri29single6100
OscarLedner35complicated499
DewayneRippin36relationship180
MajorJohns34relationship5598
MirandaJohnson48single6617
SedrickLittle28complicated9259
JammieShanahan47complicated1759
DemondGoodwin18relationship6329
CoralieLowe58relationship994
SergioO'Keefe56single323
FreidaBergstrom20relationship3967
LafayetteWilkinson39complicated2042
AmosQuigley55single7850
MozelleStanton39relationship720
MagnusHowell62single5792
DarnellMaggio60single6885
CaleStroman56single3557
NewtonBreitenberg38single2288
ErickJohns62single6439
OdessaPouros65single2479
JessicaGulgowski26complicated820
MustafaRatke60complicated9965
CaylaSkiles33single99100
ShemarNitzsche21relationship6235
JermeyGibson37single441