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
HudsonLowe38relationship4233
LilaGleichner47complicated5313
ChristinaStehr41complicated858
AnjaliBoyer24relationship6022
DaisyKoss27complicated6448
GiaMcClure25complicated7097
SiennaMante38complicated4478
VellaBode35relationship8541
DeliaZiemann64single8060
CaylaLedner35complicated499
JoanneGerlach36complicated8474
AdonisGlover45complicated266
JerryHeller44relationship9811
AlleneOberbrunner28complicated4265
CecileSanford24single8775
KarianneVonRueden46single3426
HectorMohr57complicated6217
JenaPrice29relationship1811
AdelineGrimes26relationship928
EdgarLowe58relationship994
LuellaStrosin28single7465
AlexandrePurdy22complicated336
AmericaBaumbach36single6720
HollyGreenfelder47relationship9645
HerminiaLang43complicated416
MelissaSanford42complicated9633
NeldaJohns58relationship4472
AlbinaBrakus49complicated2820
TiaraVon51relationship5051
AbigaleMaggio60single6885