Skip to main content

sorting

Tables can be sorted by clicking on the sorting indicators in the column headers. Clicking once will sort the column in ascending order, clicking again will sort the column in descending order. Multiple columns can be sorted simultaneously with the first column clicked having the highest priority.

Disable Sorting

You can disable sorting entirely by setting tableOptions.enableSorting to false.

<DataTable tableOptions={{ enableSorting: false }} />
Name
Breed
Age
Birthdate
Last Checkup
Nationality
Microchip
Title
Identifier
Display Name
IP Address
Skills
Filter
Filter
Filter
Filter
Selkirk Rex
17
2008-02-08T18:48:47.009Z
2025-03-30T17:08:37.394Z
🇲🇵
Legacy Implementation Liaison
0
Aric35
177.221.104.53
Hunting
American Shorthair
3
2022-01-11T19:38:47.327Z
2025-09-20T18:22:06.143Z
🇵🇲
Principal Applications Developer
1
Jocelyn_Koelpin
183.178.38.10
Playing
Havana
17
2007-12-02T16:09:32.758Z
2025-03-27T23:53:33.990Z
🇳🇫
Investor Applications Administrator
2
Kathleen.Mosciski57
186.101.171.88
Hunting
Japanese Bobtail
2007-05-16T14:16:12.809Z
2025-07-02T10:03:51.929Z
🇬🇳
Internal Infrastructure Planner
3
Crystal49
a36a:a9ed:0bdc:1feb:1854:e72d:11a4:43cb
Purring
American Wirehair
20
2005-03-20T05:26:51.899Z
2025-11-01T17:56:07.953Z
🇰🇭
Customer Optimization Administrator
4
Beverly59
4b1b:da8f:8528:04a2:c454:39e4:da0f:b2bb
Climbing
Himalayan
2024-11-23T15:17:50.905Z
2025-02-26T09:06:36.021Z
🇻🇬
Forward Identity Assistant
5
May.Prosacco86
c73b:f2e2:f8db:0cef:aaa6:4d3c:8dcd:17e1
Sleeping
American Bobtail
12
2013-05-10T22:59:10.107Z
2025-03-20T13:16:31.031Z
🏴‍☠️
Legacy Group Manager
6
Audie.Hackett
193.225.156.126
Meowing
Exotic Shorthair
11
2014-02-03T02:29:26.148Z
2025-05-07T01:49:29.124Z
🇱🇹
International Mobility Architect
7
Christy.Bode-Lueilwitz11
203.128.8.19
Meowing
Peterbald
20
2025-01-08T03:41:04.126Z
🇺🇳
Chief Intranet Technician
8
Janae7
11.134.30.108
Jumping
American Shorthair
14
2011-05-14T02:26:51.612Z
2025-08-22T01:07:28.240Z
🇫🇷
Legacy Quality Analyst
9
Darrel.Simonis26
ae80:6f80:acc6:4188:fa52:edef:eefe:19f2
Scratching
Showing 1-10 of 1000
1 of 100......
10 Rows
Showing 1-10 of 1000
1 of 100......
10 Rows

Disable Sorting for Specific Columns

You can disable sorting for specific columns by setting enableSorting to false in the column definition.

const columns: Columns<Cat> = [
  {
    accessorKey: 'name',
    enableSorting: false, // Disable sorting for this column
    header: 'Name',
  },
  {
    accessorKey: 'age',
    enableSorting: false, // Disable sorting for this column
    header: 'Age',
  },
]
Name
Breed
Age
Birthdate
Last Checkup
Nationality
Microchip
Title
Identifier
Display Name
IP Address
Skills
Filter
Filter
Filter
Filter
Selkirk Rex
17
2008-02-08T18:48:47.009Z
2025-03-30T17:08:37.394Z
🇲🇵
Legacy Implementation Liaison
0
Aric35
177.221.104.53
Hunting
American Shorthair
3
2022-01-11T19:38:47.327Z
2025-09-20T18:22:06.143Z
🇵🇲
Principal Applications Developer
1
Jocelyn_Koelpin
183.178.38.10
Playing
Havana
17
2007-12-02T16:09:32.758Z
2025-03-27T23:53:33.990Z
🇳🇫
Investor Applications Administrator
2
Kathleen.Mosciski57
186.101.171.88
Hunting
Japanese Bobtail
2007-05-16T14:16:12.809Z
2025-07-02T10:03:51.929Z
🇬🇳
Internal Infrastructure Planner
3
Crystal49
a36a:a9ed:0bdc:1feb:1854:e72d:11a4:43cb
Purring
American Wirehair
20
2005-03-20T05:26:51.899Z
2025-11-01T17:56:07.953Z
🇰🇭
Customer Optimization Administrator
4
Beverly59
4b1b:da8f:8528:04a2:c454:39e4:da0f:b2bb
Climbing
Himalayan
2024-11-23T15:17:50.905Z
2025-02-26T09:06:36.021Z
🇻🇬
Forward Identity Assistant
5
May.Prosacco86
c73b:f2e2:f8db:0cef:aaa6:4d3c:8dcd:17e1
Sleeping
American Bobtail
12
2013-05-10T22:59:10.107Z
2025-03-20T13:16:31.031Z
🏴‍☠️
Legacy Group Manager
6
Audie.Hackett
193.225.156.126
Meowing
Exotic Shorthair
11
2014-02-03T02:29:26.148Z
2025-05-07T01:49:29.124Z
🇱🇹
International Mobility Architect
7
Christy.Bode-Lueilwitz11
203.128.8.19
Meowing
Peterbald
20
2025-01-08T03:41:04.126Z
🇺🇳
Chief Intranet Technician
8
Janae7
11.134.30.108
Jumping
American Shorthair
14
2011-05-14T02:26:51.612Z
2025-08-22T01:07:28.240Z
🇫🇷
Legacy Quality Analyst
9
Darrel.Simonis26
ae80:6f80:acc6:4188:fa52:edef:eefe:19f2
Scratching
Showing 1-10 of 1000
1 of 100......
10 Rows
Showing 1-10 of 1000
1 of 100......
10 Rows

Default Sort State

You can set the default sort state of the table by setting the tableOptions.initialState.sorting prop.

<DataTable
  tableOptions={{
    initialState: {
      sorting: [
        { id: 'name', desc: false }, // Sort by 'name' in ascending order
        { id: 'breed', desc: true }, // Then sort by 'breed' in descending order
      ],
    },
  }}
/>
Column ID

id in the sorting state above is the id of the column, which unless explicitly set in the column definition, will be the header value formatted as camelCase.

Name
Breed
Age
Birthdate
Sex
Last Checkup
Next Checkup
Nationality
Microchip
Weight
Title
Identifier
Display Name
IP Address
MAC Address
Webpage
Skills
Filter
Filter
Filter
Filter
American Wirehair
8
female
2025-03-29T03:55:56.796Z
2025-12-19T18:27:47.396Z
🇰🇮
Legacy Quality Developer
16
Vallie19
73.131.51.218
95:4d:7f:f5:9e:08
trustworthy-adaptation.biz
American Wirehair
2024-04-15T20:12:28.156Z
male
2025-11-13T12:03:43.869Z
2026-07-31T02:14:17.616Z
🇩🇴
Forward Intranet Technician
855
Patience.Auer
165.153.38.115
54:bd:80:33:c0:5c
caring-final.org
British Shorthair
18
2007-05-09T08:46:42.851Z
female
2025-07-04T08:40:24.171Z
2025-12-07T01:27:00.012Z
🇲🇫
Chief Accountability Coordinator
190
Aurelie85
ef43:fbb2:4eef:d82f:cf67:6099:5de2:884a
f1:e2:b0:0f:23:44
mushy-vestment.org
Hunting
Chartreux
10
2015-06-18T01:22:28.578Z
male
2025-06-10T09:48:25.097Z
2026-04-28T10:40:40.616Z
🇨🇦
Product Intranet Assistant
702
Ozella_Lindgren41
ebba:dca2:3dda:c3bc:f86d:315a:e5bd:bd0f
ae:5d:40:78:66:07
grim-pinstripe.name
Climbing
Japanese Bobtail
1
2024-05-12T21:45:18.840Z
female
2025-02-08T20:11:06.975Z
2025-11-29T22:33:14.290Z
🇹🇴
Principal Operations Technician
478
Reinhold_OHara
18.67.64.81
e1:6e:ca:f8:b5:df
trusty-membership.info
Hiding
Maine Coon
4
2021-11-24T11:24:37.473Z
male
2025-08-21T16:03:31.044Z
2025-12-14T22:59:56.674Z
🇹🇼
Global Intranet Developer
66
Agustin81
121.251.177.177
ad:03:58:10:23:84
sniveling-ribbon.name
Scratching
Pixiebob
1
female
2025-09-01T15:57:26.748Z
2026-10-05T06:05:12.609Z
🇨🇺
Future Infrastructure Manager
137
Alysha_Champlin
119.23.4.10
de:76:46:1b:57:fe
fantastic-slide.net
Hiding
Ragdoll
2025-02-15T00:54:29.939Z
female
2025-01-01T01:05:12.838Z
2026-03-21T23:37:23.597Z
🇻🇦
Internal Communications Supervisor
367
Samara.Leffler35
157.11.226.33
cc:a3:b9:ea:98:7f
crowded-vein.org
Meowing
Singapura
2020-04-02T00:40:58.585Z
female
2024-12-12T14:05:23.701Z
2026-01-28T16:23:53.237Z
🇻🇨
Future Implementation Strategist
318
Mitchell.Murazik
1aeb:bcbc:e8d0:ccb2:6e09:79f5:dfd8:2638
46:00:b0:e4:58:7e
boiling-disposer.net
Climbing
Turkish Van
0
2025-06-15T11:25:45.542Z
male
2025-06-06T19:35:53.569Z
2026-11-23T04:01:58.354Z
🇱🇾
Dynamic Applications Technician
450
Haskell.Renner5
210.109.144.188
dc:ab:b0:a8:fe:8c
warlike-bran.info
Sleeping
Showing 1-10 of 1000
1 of 100......
10 Rows
Showing 1-10 of 1000
1 of 100......
10 Rows

Descending Sort

You can set descending sort as the default (i.e. sort order on first click) by setting tableOptions.sortDescFirst to true.

<DataTable tableOptions={{ sortDescFirst: true }} />
Name
Breed
Age
Birthdate
Last Checkup
Nationality
Microchip
Title
Identifier
Display Name
IP Address
Skills
Filter
Filter
Filter
Filter
Selkirk Rex
17
2008-02-08T18:48:47.009Z
2025-03-30T17:08:37.394Z
🇲🇵
Legacy Implementation Liaison
0
Aric35
177.221.104.53
Hunting
American Shorthair
3
2022-01-11T19:38:47.327Z
2025-09-20T18:22:06.143Z
🇵🇲
Principal Applications Developer
1
Jocelyn_Koelpin
183.178.38.10
Playing
Havana
17
2007-12-02T16:09:32.758Z
2025-03-27T23:53:33.990Z
🇳🇫
Investor Applications Administrator
2
Kathleen.Mosciski57
186.101.171.88
Hunting
Japanese Bobtail
2007-05-16T14:16:12.809Z
2025-07-02T10:03:51.929Z
🇬🇳
Internal Infrastructure Planner
3
Crystal49
a36a:a9ed:0bdc:1feb:1854:e72d:11a4:43cb
Purring
American Wirehair
20
2005-03-20T05:26:51.899Z
2025-11-01T17:56:07.953Z
🇰🇭
Customer Optimization Administrator
4
Beverly59
4b1b:da8f:8528:04a2:c454:39e4:da0f:b2bb
Climbing
Himalayan
2024-11-23T15:17:50.905Z
2025-02-26T09:06:36.021Z
🇻🇬
Forward Identity Assistant
5
May.Prosacco86
c73b:f2e2:f8db:0cef:aaa6:4d3c:8dcd:17e1
Sleeping
American Bobtail
12
2013-05-10T22:59:10.107Z
2025-03-20T13:16:31.031Z
🏴‍☠️
Legacy Group Manager
6
Audie.Hackett
193.225.156.126
Meowing
Exotic Shorthair
11
2014-02-03T02:29:26.148Z
2025-05-07T01:49:29.124Z
🇱🇹
International Mobility Architect
7
Christy.Bode-Lueilwitz11
203.128.8.19
Meowing
Peterbald
20
2025-01-08T03:41:04.126Z
🇺🇳
Chief Intranet Technician
8
Janae7
11.134.30.108
Jumping
American Shorthair
14
2011-05-14T02:26:51.612Z
2025-08-22T01:07:28.240Z
🇫🇷
Legacy Quality Analyst
9
Darrel.Simonis26
ae80:6f80:acc6:4188:fa52:edef:eefe:19f2
Scratching
Showing 1-10 of 1000
1 of 100......
10 Rows
Showing 1-10 of 1000
1 of 100......
10 Rows

Descending Sort for Specific Columns

You can set descending sort as the default for specific columns by setting sortDescFirst to true in the column definition.

const columns: Columns<Cat> = [
  {
    accessorKey: 'name',
    header: 'Name',
    sortDescFirst: true, // Descending sort on first click for this column
  },
  {
    accessorKey: 'age',
    header: 'Age',
    sortDescFirst: true, // Descending sort on first click for this column
  },
]
Name
Breed
Age
Birthdate
Last Checkup
Nationality
Microchip
Title
Identifier
Display Name
IP Address
Skills
Filter
Filter
Filter
Filter
Selkirk Rex
17
2008-02-08T18:48:47.009Z
2025-03-30T17:08:37.394Z
🇲🇵
Legacy Implementation Liaison
0
Aric35
177.221.104.53
Hunting
American Shorthair
3
2022-01-11T19:38:47.327Z
2025-09-20T18:22:06.143Z
🇵🇲
Principal Applications Developer
1
Jocelyn_Koelpin
183.178.38.10
Playing
Havana
17
2007-12-02T16:09:32.758Z
2025-03-27T23:53:33.990Z
🇳🇫
Investor Applications Administrator
2
Kathleen.Mosciski57
186.101.171.88
Hunting
Japanese Bobtail
2007-05-16T14:16:12.809Z
2025-07-02T10:03:51.929Z
🇬🇳
Internal Infrastructure Planner
3
Crystal49
a36a:a9ed:0bdc:1feb:1854:e72d:11a4:43cb
Purring
American Wirehair
20
2005-03-20T05:26:51.899Z
2025-11-01T17:56:07.953Z
🇰🇭
Customer Optimization Administrator
4
Beverly59
4b1b:da8f:8528:04a2:c454:39e4:da0f:b2bb
Climbing
Himalayan
2024-11-23T15:17:50.905Z
2025-02-26T09:06:36.021Z
🇻🇬
Forward Identity Assistant
5
May.Prosacco86
c73b:f2e2:f8db:0cef:aaa6:4d3c:8dcd:17e1
Sleeping
American Bobtail
12
2013-05-10T22:59:10.107Z
2025-03-20T13:16:31.031Z
🏴‍☠️
Legacy Group Manager
6
Audie.Hackett
193.225.156.126
Meowing
Exotic Shorthair
11
2014-02-03T02:29:26.148Z
2025-05-07T01:49:29.124Z
🇱🇹
International Mobility Architect
7
Christy.Bode-Lueilwitz11
203.128.8.19
Meowing
Peterbald
20
2025-01-08T03:41:04.126Z
🇺🇳
Chief Intranet Technician
8
Janae7
11.134.30.108
Jumping
American Shorthair
14
2011-05-14T02:26:51.612Z
2025-08-22T01:07:28.240Z
🇫🇷
Legacy Quality Analyst
9
Darrel.Simonis26
ae80:6f80:acc6:4188:fa52:edef:eefe:19f2
Scratching
Showing 1-10 of 1000
1 of 100......
10 Rows
Showing 1-10 of 1000
1 of 100......
10 Rows

Multi-Column Sorting

Disable Multi-Column Sorting

You can disable multi-column sorting by setting tableOptions.enableMultiSort to false. This will make it so that only one column can be sorted at a time.

<DataTable tableOptions={{ enableMultiSort: false }} />
Name
Breed
Age
Birthdate
Last Checkup
Nationality
Microchip
Title
Identifier
Display Name
IP Address
Skills
Filter
Filter
Filter
Filter
Selkirk Rex
17
2008-02-08T18:48:47.009Z
2025-03-30T17:08:37.394Z
🇲🇵
Legacy Implementation Liaison
0
Aric35
177.221.104.53
Hunting
American Shorthair
3
2022-01-11T19:38:47.327Z
2025-09-20T18:22:06.143Z
🇵🇲
Principal Applications Developer
1
Jocelyn_Koelpin
183.178.38.10
Playing
Havana
17
2007-12-02T16:09:32.758Z
2025-03-27T23:53:33.990Z
🇳🇫
Investor Applications Administrator
2
Kathleen.Mosciski57
186.101.171.88
Hunting
Japanese Bobtail
2007-05-16T14:16:12.809Z
2025-07-02T10:03:51.929Z
🇬🇳
Internal Infrastructure Planner
3
Crystal49
a36a:a9ed:0bdc:1feb:1854:e72d:11a4:43cb
Purring
American Wirehair
20
2005-03-20T05:26:51.899Z
2025-11-01T17:56:07.953Z
🇰🇭
Customer Optimization Administrator
4
Beverly59
4b1b:da8f:8528:04a2:c454:39e4:da0f:b2bb
Climbing
Himalayan
2024-11-23T15:17:50.905Z
2025-02-26T09:06:36.021Z
🇻🇬
Forward Identity Assistant
5
May.Prosacco86
c73b:f2e2:f8db:0cef:aaa6:4d3c:8dcd:17e1
Sleeping
American Bobtail
12
2013-05-10T22:59:10.107Z
2025-03-20T13:16:31.031Z
🏴‍☠️
Legacy Group Manager
6
Audie.Hackett
193.225.156.126
Meowing
Exotic Shorthair
11
2014-02-03T02:29:26.148Z
2025-05-07T01:49:29.124Z
🇱🇹
International Mobility Architect
7
Christy.Bode-Lueilwitz11
203.128.8.19
Meowing
Peterbald
20
2025-01-08T03:41:04.126Z
🇺🇳
Chief Intranet Technician
8
Janae7
11.134.30.108
Jumping
American Shorthair
14
2011-05-14T02:26:51.612Z
2025-08-22T01:07:28.240Z
🇫🇷
Legacy Quality Analyst
9
Darrel.Simonis26
ae80:6f80:acc6:4188:fa52:edef:eefe:19f2
Scratching
Showing 1-10 of 1000
1 of 100......
10 Rows
Showing 1-10 of 1000
1 of 100......
10 Rows

Limit Number of Sorted Columns

You can limit the number of columns that can be sorted simultaneously by setting tableOptions.maxMultiSortColCount, the default is 3.

<DataTable tableOptions={{ maxMultiSortColCount: 2 }} />
Name
Breed
Age
Birthdate
Last Checkup
Nationality
Microchip
Title
Identifier
Display Name
IP Address
Skills
Filter
Filter
Filter
Filter
Selkirk Rex
17
2008-02-08T18:48:47.009Z
2025-03-30T17:08:37.394Z
🇲🇵
Legacy Implementation Liaison
0
Aric35
177.221.104.53
Hunting
American Shorthair
3
2022-01-11T19:38:47.327Z
2025-09-20T18:22:06.143Z
🇵🇲
Principal Applications Developer
1
Jocelyn_Koelpin
183.178.38.10
Playing
Havana
17
2007-12-02T16:09:32.758Z
2025-03-27T23:53:33.990Z
🇳🇫
Investor Applications Administrator
2
Kathleen.Mosciski57
186.101.171.88
Hunting
Japanese Bobtail
2007-05-16T14:16:12.809Z
2025-07-02T10:03:51.929Z
🇬🇳
Internal Infrastructure Planner
3
Crystal49
a36a:a9ed:0bdc:1feb:1854:e72d:11a4:43cb
Purring
American Wirehair
20
2005-03-20T05:26:51.899Z
2025-11-01T17:56:07.953Z
🇰🇭
Customer Optimization Administrator
4
Beverly59
4b1b:da8f:8528:04a2:c454:39e4:da0f:b2bb
Climbing
Himalayan
2024-11-23T15:17:50.905Z
2025-02-26T09:06:36.021Z
🇻🇬
Forward Identity Assistant
5
May.Prosacco86
c73b:f2e2:f8db:0cef:aaa6:4d3c:8dcd:17e1
Sleeping
American Bobtail
12
2013-05-10T22:59:10.107Z
2025-03-20T13:16:31.031Z
🏴‍☠️
Legacy Group Manager
6
Audie.Hackett
193.225.156.126
Meowing
Exotic Shorthair
11
2014-02-03T02:29:26.148Z
2025-05-07T01:49:29.124Z
🇱🇹
International Mobility Architect
7
Christy.Bode-Lueilwitz11
203.128.8.19
Meowing
Peterbald
20
2025-01-08T03:41:04.126Z
🇺🇳
Chief Intranet Technician
8
Janae7
11.134.30.108
Jumping
American Shorthair
14
2011-05-14T02:26:51.612Z
2025-08-22T01:07:28.240Z
🇫🇷
Legacy Quality Analyst
9
Darrel.Simonis26
ae80:6f80:acc6:4188:fa52:edef:eefe:19f2
Scratching
Showing 1-10 of 1000
1 of 100......
10 Rows
Showing 1-10 of 1000
1 of 100......
10 Rows

Or you can increase the default limit:

<DataTable tableOptions={{ maxMultiSortColCount: 5 }} />
Name
Breed
Age
Birthdate
Last Checkup
Nationality
Microchip
Title
Identifier
Display Name
IP Address
Skills
Filter
Filter
Filter
Filter
Selkirk Rex
17
2008-02-08T18:48:47.009Z
2025-03-30T17:08:37.394Z
🇲🇵
Legacy Implementation Liaison
0
Aric35
177.221.104.53
Hunting
American Shorthair
3
2022-01-11T19:38:47.327Z
2025-09-20T18:22:06.143Z
🇵🇲
Principal Applications Developer
1
Jocelyn_Koelpin
183.178.38.10
Playing
Havana
17
2007-12-02T16:09:32.758Z
2025-03-27T23:53:33.990Z
🇳🇫
Investor Applications Administrator
2
Kathleen.Mosciski57
186.101.171.88
Hunting
Japanese Bobtail
2007-05-16T14:16:12.809Z
2025-07-02T10:03:51.929Z
🇬🇳
Internal Infrastructure Planner
3
Crystal49
a36a:a9ed:0bdc:1feb:1854:e72d:11a4:43cb
Purring
American Wirehair
20
2005-03-20T05:26:51.899Z
2025-11-01T17:56:07.953Z
🇰🇭
Customer Optimization Administrator
4
Beverly59
4b1b:da8f:8528:04a2:c454:39e4:da0f:b2bb
Climbing
Himalayan
2024-11-23T15:17:50.905Z
2025-02-26T09:06:36.021Z
🇻🇬
Forward Identity Assistant
5
May.Prosacco86
c73b:f2e2:f8db:0cef:aaa6:4d3c:8dcd:17e1
Sleeping
American Bobtail
12
2013-05-10T22:59:10.107Z
2025-03-20T13:16:31.031Z
🏴‍☠️
Legacy Group Manager
6
Audie.Hackett
193.225.156.126
Meowing
Exotic Shorthair
11
2014-02-03T02:29:26.148Z
2025-05-07T01:49:29.124Z
🇱🇹
International Mobility Architect
7
Christy.Bode-Lueilwitz11
203.128.8.19
Meowing
Peterbald
20
2025-01-08T03:41:04.126Z
🇺🇳
Chief Intranet Technician
8
Janae7
11.134.30.108
Jumping
American Shorthair
14
2011-05-14T02:26:51.612Z
2025-08-22T01:07:28.240Z
🇫🇷
Legacy Quality Analyst
9
Darrel.Simonis26
ae80:6f80:acc6:4188:fa52:edef:eefe:19f2
Scratching
Showing 1-10 of 1000
1 of 100......
10 Rows
Showing 1-10 of 1000
1 of 100......
10 Rows

Query Parameters

Sorting state is pushed to the URL as a query parameter sort, so that when users can share links any sorting they have applied to the table will be preserved for anyone opening the link.

Sort query is encoded as a comma-separated list of column ids, with a - prefix for descending sort.

For example, navigating to ?sort=-age,name will sort the table by age descending and then by name ascending.

Custom Query Parameter Name

You can customize the query parameter name used for pagination by setting tableOptions.queryKeys.sort.

Generally we recommend keeping the default sort value to ensure consistency across your application and user familiarity, however if you are using multiple tables on the same page you need to customize the query parameter names to avoid conflicts.

<DataTable tableOptions={{ queryKeys: { sort: 'my-custom-table-sort' } }} />

Disable Query Parameters

You can also disable query parameters for sorting by setting tableOptions.queryKeys.sort to false.

<DataTable tableOptions={{ queryKeys: { sort: false } }} />