React Data Grid Quickstart

Quickstart

Render your first CoreUI Data Grid for React in a few lines — columns, data, a stable row key, then your first feature.

This guide builds a working grid from scratch. It assumes you’ve installed @coreui/react-data-grid and loaded its stylesheet.

1. The component

The grid renders wherever you place <CDataGrid>:

import { CDataGrid } from '@coreui/react-data-grid'
import '@coreui/data-grid/dist/css/data-grid.css'

2. Columns and data

Define columns by key (the property to read from each item) and pass your items:

const items = [
  { id: 1, name: 'Alice', role: 'admin' },
  { id: 2, name: 'Bob', role: 'editor' },
  { id: 3, name: 'Carol', role: 'viewer' },
]

<CDataGrid
  columns={[
    { key: 'name', label: 'Name' },
    { key: 'role', label: 'Role' },
  ]}
  items={items}
  itemKey={(item) => String(item.id)}
/>

itemKey returns a stable id per row. It’s optional, but selection needs it to survive sorting and filtering — set it up front.

3. Turn on a feature

Every feature is a single prop. Add filtering and selection:

<CDataGrid
  columns={columns}
  items={items}
  itemKey={(item) => String(item.id)}
  columnFilters // per-column filter row
  rowSelection // checkbox column with select-all
/>

Sorting is on by default. From here, explore the feature matrix or jump to any feature page.

4. React to changes

The grid calls onXxx callback props with structured state:

<CDataGrid
  columns={columns}
  items={items}
  itemKey={(item) => String(item.id)}
  rowSelection
  onSelectionChange={(rowSelection, selectedItems) => {
    console.log(selectedItems)
  }}
/>

What’s next