gridcn1.2.2

Sort list

The data-grid-sort-list add-on: a toolbar button and popover to add, remove, and reorder sorts.

Click-to-sort headers work without any add-on, but data-grid-sort-list gives users a toolbar button and popover to add, remove, and reorder sorts without touching the headers. This is useful when columns are narrow, or when you prefer not to rely on shift-click for multi-column sort.

Name
Email
Role
Score
Silent Tiger
user0@example.com
Viewer
4
Quick Lion
user1@example.com
Viewer
89
Swift Wolf
user2@example.com
Manager
80
Eager Lion
user3@example.com
User
51
Eager Tiger
user4@example.com
Viewer
83
Silent Wolf
user5@example.com
User
15
Swift Lion
user6@example.com
Viewer
62
Eager Lion
user7@example.com
Manager
42
Eager Eagle
user8@example.com
Editor
35
Bold Tiger
user9@example.com
Editor
52
Bold Bear
user10@example.com
User
28
Swift Wolf
user11@example.com
Manager
9
Swift Bear
user12@example.com
Viewer
45
Eager Wolf
user13@example.com
Editor
44
Swift Eagle
user14@example.com
Viewer
51
Quick Lion
user15@example.com
Manager
28
Bold Wolf
user16@example.com
Editor
76
Swift Eagle
user17@example.com
Admin
26
Eager Eagle
user18@example.com
Manager
70
Eager Bear
user19@example.com
Editor
67
Silent Lion
user20@example.com
Manager
89
Silent Tiger
user21@example.com
Manager
40
Eager Tiger
user22@example.com
Manager
82
Silent Lion
user23@example.com
Admin
16
Bold Eagle
user24@example.com
Admin
38
Bold Lion
user25@example.com
Viewer
3
Quick Tiger
user26@example.com
Viewer
41
Bold Eagle
user27@example.com
Editor
10
Swift Tiger
user28@example.com
Editor
6
Silent Lion
user29@example.com
Viewer
42
pnpm dlx shadcn@latest add @gridcn/data-grid-sort-list
import { DataGridSortList } from "@/components/data-grid-sort-list/data-grid-sort-list";

<DataGridProvider {...grid} columns={columns}>
  <DataGridToolbar>
    <DataGridSortList />
  </DataGridToolbar>
  <DataGridRoot>
    <DataGridHeader />
    <DataGridBody />
  </DataGridRoot>
</DataGridProvider>;

Each row has a column select, an ascending/descending select, a remove button, and a drag handle. Precedence is array order in SortSpec[], changed by dragging the drag handle (@dnd-kit/react) or through the keyboard (see below). It reads and writes the same useDataGridSortState() and useDataGridActions().setSorts() as click-to-sort headers, so the two UIs stay in sync automatically. The button shows a count badge once one or more sorts are applied, matching the badge of DataGridFilterMenu.

PropTypeDefaultDescription
allColumnsbooleanfalseLists every column in the select, including hidden ones, instead of only the visible columns.

Keyboard & accessibility

KeyAction
TabMoves through a row's controls, in order: column select, direction select, remove, drag handle
ArrowUp / ArrowDown (drag handle focused)Moves that sort row one position up/down, which changes precedence
Space / Enter (drag handle focused)Picks up/drops the row for pointer-equivalent keyboard dragging (@dnd-kit/react's keyboard sensor)
Backspace / Delete (drag handle focused)Removes that sort row

Plain ArrowUp or ArrowDown on a focused drag handle always moves the row by exactly one position. The keyboard sensor of @dnd-kit/react also offers its own gesture for that key, but gridcn checks the plain arrow press first, and it wins. Every reorder announces the change through a polite aria-live region (labels.sort.sortReorderAnnouncement, for example "Age sort moved to position 1 of 2"). Focus never gets lost. After a reorder, focus stays on the moved row's drag handle. After deleting a row, focus moves to the next row's drag handle, or to the "Add sort" button once the list is empty.

On this page