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
NyaWilliamson40complicated6592
FosterCorwin49complicated2796
KenyonMcLaughlin65single2949
CharleneLangworth-Davis57complicated4057
OnaSchultz30single2879
EmelyBednar25relationship6527
TatyanaBecker38single8478
ConradEmard42single8280
SerenityGerlach-Hettinger58relationship8738
BorisGreenholt59single73
AnthonyGlover55relationship1438
AmeliaDuBuque35single1659
TomPredovic46relationship1592
MurrayVon64complicated309
CarmellaRath-Mayert52relationship5491
EmeliaAbshire36single4572
ZachariahZiemann64single4713
JavonteKuvalis33complicated6660
MyrtisLeuschke44single7939
FrankieSchinner24complicated3968
ChristaRohan29complicated1932
MyrtieZieme57relationship96
JaylenDooley63complicated8714
AdelineLebsack54complicated645
DaijaHodkiewicz41complicated337
TryciaQuigley24relationship8125
DeeGulgowski31complicated4376
LexieBaumbach39single2373
YazminKertzmann52complicated1256
OletaFraney46complicated8493