gridcn2.0.0
Selection and shortcuts

Keyboard navigation

Move, extend, edit, and select with the keyboard, and find the key chords for rows, headers, and select all.

The keymap is one data table that binds keys to grid actions. The grid handles a key only while DOM focus is inside the grid. Tab moves focus into the grid. Outside an edit, Tab and Shift+Tab leave the grid.

Last chord: none yet

Name
Role
Score
Silent Tiger
Viewer
4
Quick Lion
Viewer
89
Swift Wolf
Manager
80
Eager Lion
User
51
Eager Tiger
Viewer
83
Silent Wolf
User
15
Swift Lion
Viewer
62
Eager Lion
Manager
42
Eager Eagle
Editor
35
Bold Tiger
Editor
52
Bold Bear
User
28
Swift Wolf
Manager
9
Swift Bear
Viewer
45
Eager Wolf
Editor
44
Swift Eagle
Viewer
51
Quick Lion
Manager
28
Bold Wolf
Editor
76
Swift Eagle
Admin
26
Eager Eagle
Manager
70
Eager Bear
Editor
67
Silent Lion
Manager
89
Silent Tiger
Manager
40
Eager Tiger
Manager
82
Silent Lion
Admin
16
Bold Eagle
Admin
38
Bold Lion
Viewer
3
Quick Tiger
Viewer
41
Bold Eagle
Editor
10
Swift Tiger
Editor
6
Silent Lion
Viewer
42

With zero rows, no cell can take focus. Each column header then has one tab stop. It is the filter button, or the menu button when the column has no filter button. Press Enter or Space on the filter button to open it and clear the filter that emptied the grid.

Keyboard map

The table lists the default bindings, generated from DEFAULT_KEYMAP:

Navigation

Open or close group
EnterSpace
Open group
→
Close group
←
Move up
↑
Move down
↓
Move left
←
Move right
→
Move up (keep selection)
Alt↑
Move down (keep selection)
Alt↓
Move left (keep selection)
Alt←
Move right (keep selection)
Alt→
Scroll active cell into view
CtrlEnter
Move to row start
Home
Move to row end
End
Jump to edge (up)
Ctrl↑
Jump to edge (down)
Ctrl↓
Jump to edge (left)
Ctrl←
Jump to edge (right)
Ctrl→
Move to first cell
CtrlHome
Move to last cell
CtrlEnd
Page up
PageUp
Page down
PageDown

Selection

Extend selection up
Shift↑
Extend selection down
Shift↓
Extend selection left
Shift←
Extend selection right
Shift→
Extend selection to edge (up)
CtrlShift↑
Extend selection to edge (down)
CtrlShift↓
Extend selection to edge (left)
CtrlShift←
Extend selection to edge (right)
CtrlShift→
Extend selection to first cell
CtrlShiftHome
Extend selection to last cell
CtrlShiftEnd
Check rows up to the first row
ShiftHome
Check rows down to the last row
ShiftEnd
Check rows up one page
ShiftPageUp
Check rows down one page
ShiftPageDown
Select row
ShiftSpace
Select column
CtrlSpace
Select all
CtrlA
Check or uncheck row
CtrlShiftSpace
Check or uncheck all rows
CtrlShiftEnter
Open column menu
ShiftAlt↓
Open column filter
ShiftAlt↑
Search
CtrlF

Editing

Edit cell
EnterF2Space
Cancel edit
Escape
Delete contents
DeleteBackspace
Insert row below
CtrlShiftF
Duplicate row
CtrlShiftX
Insert row above
CtrlShiftU
Delete row(s)
CtrlShiftBackspace
Move rows up
ShiftAltPageUp
Move rows down
ShiftAltPageDown
Open link
AltEnter

Clipboard & Fill

Fill down
CtrlD
Fill right
CtrlR
Copy
CtrlC
Cut
CtrlX
Paste
CtrlV

History

Undo
CtrlZ
Redo
CtrlYCtrlShiftZ

mod is Cmd on macOS, iOS, and iPadOS, and Ctrl elsewhere. Copy, cut, and paste (Ctrl/Cmd+C, X, V) are native browser clipboard events, not keymap entries. The table lists them for completeness. Shortcut remapping changes any binding. The built-in editors handle Enter, Escape, and Tab themselves. A keymap entry changes no editor key. In the text, number, url, and date editors, Shift+Enter commits and moves down, like Enter.

Header buttons

A focused header button takes only Enter and Space, with or without Shift. Every other key, such as ArrowRight and Delete, still goes to the grid.

Shift+Alt+ArrowDown on a focused header button opens the column menu of that column, even when a cell in another column is active. It works with DataGridHeaderDropdown alone, without DataGridContextMenu. Without a focused header button, the grid uses the column of the active cell.

Move and edit

  • Arrow keys move the active cell. In a right-to-left grid, ArrowRight moves one column to the right on the screen.
  • Alt+Arrow moves the active cell and keeps the selection.
  • Ctrl/Cmd+Arrow jumps along the row or column. From a non-empty cell whose neighbor is non-empty, it stops at the last non-empty cell of the run. From an empty cell, or from a non-empty cell whose neighbor is empty, it stops at the next non-empty cell. If there is none, it stops at the grid edge. With Shift, it scans from the far end of the selection and extends the selection to that cell.
  • PageUp and PageDown move by the visible rows minus four.
  • Ctrl/Cmd+Enter scrolls the active cell into view without moving it.
  • Enter, F2, and Space start an edit. On a checkbox cell they toggle the value. A read-only grid does not edit.
  • A printable key on the active cell starts an edit seeded with that character. A checkbox cell ignores it.
  • Alt+Enter opens the link of a link cell in a new tab.
  • Shift+F10 opens the cell menu of the active cell on Windows and Linux. It needs DataGridContextMenu.

Row move keys

Shift+Alt+PageUp (moveRowsUp) and Shift+Alt+PageDown (moveRowsDown) move rows one place. They move the checked rows. Without checked rows, they move the rows of every selected range, or the active row.

They need a reorder family rowMarkers mode. A read-only grid ignores them. See Row order.

Column filter and menu keys

Shift+Alt+ArrowUp (openColumnFilter) opens the header filter of the focused header button's column, or else the active cell's column. It needs a renderHeaderFilter slot on the root and a column that offers a set filter. Otherwise it does nothing.

Shift+Alt+ArrowDown (openColumnMenu) opens the column menu, which needs a renderHeaderMenu slot. It opens the menu of the focused header button's column, or else the active cell's column.

Two-stage Ctrl+A

The first Ctrl/Cmd+A selects the data region around the active cell: the rectangle of adjacent rows and columns that hold values. When the active cell is empty, the region is that cell. Press the keys again to select the whole grid. On a paged grid, the whole grid is the shown page. When the data fills the whole grid, the first press selects everything.

Ctrl/Cmd+A selects cells and never checks rows. It unchecks the checked rows, also with 'until-cleared' and 'across-filters'. It also clears the hidden checked rows and ends "all matching". The header checkbox and the marker checkboxes show checked rows only, so a range over every row leaves them unchecked. With enableRangeSelection={false}, the keys do nothing.

Escape key

With no editor open, Esc (cancel) clears the whole selection: the cell range and its stack, the checked rows, and the selected columns. To keep a selection across Esc, unbind cancel. The built-in text editors still cancel an edit on Esc.

The following example unbinds cancel:

import { DataGrid, defineColumns } from "@/components/data-grid/data-grid";

type Task = { id: string; title: string };

const columns = defineColumns<Task>()([
  { id: "title", header: "Title", accessorKey: "title", type: "text" },
] as const);

export function Tasks({ tasks }: { tasks: Task[] }) {
  return (
    <DataGrid
      data={tasks}
      columns={columns}
      keymap={{ cancel: [] }}
    />
  );
}

On this page