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
JasonBaumbach24single4167
ElianReichel39complicated758
ColumbusBergstrom50single451
ProvidenciPaucek65relationship6768
BrisaHerman65single8373
EdnaMarvin27complicated1002
MatildaDeckow19single8983
AdrienneGulgowski65single628
MyriamJerde34relationship302
VinceJaskolski46relationship8013
FaustoBrekke47complicated7323
TamiaTillman57complicated5742
ErynBradtke49relationship2071
HipolitoMarquardt27complicated1176
MarianneDoyle63relationship1958
EstefaniaSporer22complicated7137
EwaldDietrich37complicated4936
KatrinaSchuppe29complicated895
GraysonWilliamson44complicated3517
PrinceDibbert30relationship78
AubreySchulist43complicated6053
IsaiahGutkowski24relationship6892
FrancescoChristiansen-Cruickshank21single4026
HerminaTreutel32single6084
DameonTrantow43single873
JaydeRodriguez49complicated899
RobbieBerge49complicated9437
KellenMaggio29single3027
ElijahKuhlman42single9395
GeraldRunolfsdottir-Veum60relationship9738