DocsBlog
  • 1.1.2

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Data Grid
Signals
Styling
Theming

Get Started

OverviewQuick StartColumnsContextThemeNew

Layout

DimensionsSizingSlotsToolbarFooterNewPagination

Features

PinningSorting

Reference

API

On this page

  • Edit this page on Github

Data Grid Theme

Learn how to customize the theme for the Data Grid component.

  • source

Overview

A its core, the Data Grid controls little to nothing regarding how it looks.

Essentially, the visual style is controlled by the cell content, Cerberus React primitives it uses (e.g., menus, pagination, etc.), and the Cerberus theme that is active from your Panda CSS config.

Having said that, what little things are visually styled, can be customized via the theme prop of the DataGrid component.

Usage

To customize the theme, pass an Object of options to the theme prop in the DataGrid component.

In the example below, we change six properties in addition to creating a vertical legend to show to the left of the Data Grid.

Take note of how the Column definitions are also providing customized cell content in a way that also changes the appearance of the layout.

Type Safety

To provide the best typescript experience, we recommend assigning the ThemeOptions type to a constant that will define your theme. This will enforce auto-completion while holding the constant accountable to fulfill the ThemeOptions type.

Theme Options

The theme prop takes an Object with the following properties:

ParamsTypeDescription
borderColorstringThe external border of the Data Grid container. The default is page.border.initial
borderstringThe border width and style of the Data Grid component. Default is 1px solid.
roundedstringThe border radius of the Data Grid component. Default is lg.
rowBgColorstringThe background color of the row. Default is page.surface.100.
rowHoverBgColorstringThe background color of the row on hover. Default is page.surface.200.
rowEvenBgColorstringThe background color of the even rows. Default is page.surface.initial.
headCellBgColorstringThe background color of the head cell. Default is page.bg.initial.
headCellBorderBottomColorstringThe border color for the bottom border of the head cell. Default is page.border.200.
gridCellBorderColorstringThe border color of the grid cell. Default is page.border.200.
gridCellPinnedBorderColorstringThe border color of the pinned grid cell. Default is page.border.200.

Note

Manipulating any values outside of the ones provided in ThemeOptions could yield to the layout breaking and virtualization no longer working. Do so with extreme caution.

Copy
'use client'

import { DataGrid, ThemeOptions } from '@cerberus/data-grid'
import { For, Text } from '@cerberus/react'
import { Center, HStack, VStack } from 'styled-system/jsx'
import { createFakeQuery } from '../quick-start/data'
import { columnHelper } from '../quick-start/helper.demo'

const customTheme: ThemeOptions = {
  border: 'none',
  borderColor: 'transparent',
  rowBgColor: 'var(--cerberus-colors-page-surface-initial)',
  rowEvenBgColor: 'var(--cerberus-colors-page-surface-initial)',
  rowHoverBgColor: 'transparent',
  headCellBorderBottomColor: 'transparent',
}

const columns = Array.from({ length: 4 }, (_, i) =>
  columnHelper.display({
    id: `col-${i}`,
    header: () => (
      <Text
        as="strong"
        display="block"
        ms="lg"
        fontWeight="bold"
        textStyle="label-sm"
      >{`Column ${i + 1}`}</Text>
    ),
    cell: () => (
      <HStack bgColor="black" justify="center" h="full" me="sm" p="sm" w="full">
        <Center bgColor="red" p="sm" rounded="md" w="full">
          1.0
        </Center>
      </HStack>
    ),
  }),
)

export function BasicDemo() {
  // Normally this would be from useQuery or a server-side API call
  const data = createFakeQuery(10)

  return (
    <HStack h="20rem" w="3/4">
      <Legend />
      <DataGrid columns={columns} data={data()} rowSize="lg" theme={customTheme} />
    </HStack>
  )
}

function Legend() {
  return (
    <VStack gap="0" justify="center" h="full" pt="15px">
      <For each={columns}>
        {(column) => (
          <Center key={column.id} h="56px" w="full">
            <Text
              as="strong"
              display="block"
              fontWeight="bold"
              textStyle="label-sm"
              transform="rotate(-90deg)"
            >
              Kewl
            </Text>
          </Center>
        )}
      </For>
    </VStack>
  )
}
import { type ThemeOptions } from '@cerberus/data-grid'

const _customTheme: ThemeOptions = {
  border: 'none',
  borderColor: 'transparent',
  rowBgColor: 'var(--cerberus-colors-page-surface-initial)',
  rowEvenBgColor: 'var(--cerberus-colors-page-surface-initial)',
  rowHoverBgColor: 'transparent',
  headCellBorderBottomColor: 'transparent',
}
Kewl
Kewl
Kewl
Kewl