gp-grid-logo
Guides

Styling

Customize the grid appearance

Styling

gp-grid includes built-in styles with dark mode support. You can customize the appearance using CSS.

Dark Mode

Enable dark mode with the darkMode prop:

<Grid darkMode={true} ... />

With next-themes

"use client";

import { useTheme } from "next-themes";

function ThemedGrid() {
  const { resolvedTheme } = useTheme();

  return (
    <Grid
      darkMode={resolvedTheme === "dark"}
      ...
    />
  );
}

CSS Classes

The grid uses these CSS classes for styling:

ClassDescription
.gp-gridGrid container
.gp-grid-headerHeader row
.gp-grid-header-cellIndividual header cell
.gp-grid-bodyBody container
.gp-grid-rowRow container
.gp-grid-cellIndividual cell
.gp-grid-cell--activeActive cell
.gp-grid-cell--selectedSelected cell
.gp-grid-cell--editingCell in edit mode

Custom Styling with CSS

Override styles in your global CSS:

/* Custom header styling */
.gp-grid-header {
  background: linear-gradient(to right, #667eea, #764ba2);
}

.gp-grid-header-cell {
  color: white;
  font-weight: 600;
}

/* Custom selection colors */
.gp-grid-cell--active {
  outline: 2px solid #3b82f6;
}

.gp-grid-cell--selected {
  background-color: rgba(59, 130, 246, 0.1);
}

/* Alternating row colors */
.gp-grid-row:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.02);
}

/* Dark mode adjustments */
.dark .gp-grid-row:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.02);
}

Tailwind CSS

With Tailwind, use @apply in your CSS:

@layer components {
  .gp-grid-header {
    @apply bg-gradient-to-r from-purple-500 to-pink-500;
  }

  .gp-grid-header-cell {
    @apply text-white font-semibold;
  }

  .gp-grid-cell--active {
    @apply ring-2 ring-blue-500;
  }
}

Dynamic Class Computation

Use the highlighting prop to dynamically compute CSS classes for rows, columns, or cells based on data or interaction state.

highlighting Prop

interface HighlightingOptions<TData> {
  computeRowClasses?: (context: HighlightContext<TData>) => string[];
  computeColumnClasses?: (context: HighlightContext<TData>) => string[];
  computeCellClasses?: (context: HighlightContext<TData>) => string[];
}

Row Classes

Apply classes to entire rows based on row data or hover state:

<Grid
  columns={columns}
  rowData={rowData}
  highlighting={{
    computeRowClasses: (context) => {
      const classes: string[] = [];

      // Zebra striping
      if (context.rowIndex !== null && context.rowIndex % 2 === 1) {
        classes.push("zebra-row");
      }

      // Hover effect
      if (context.isHovered) {
        classes.push("row-highlight");
      }

      return classes;
    },
  }}
/>

Column Classes

Apply classes to entire columns:

<Grid
  columns={columns}
  rowData={rowData}
  highlighting={{
    computeColumnClasses: (context) =>
      context.isHovered ? ["column-highlight"] : [],
  }}
/>

Cell Classes

Apply classes to individual cells:

<Grid
  columns={columns}
  rowData={rowData}
  highlighting={{
    computeCellClasses: (context) => {
      if (context.isHovered) {
        return ["cell-highlight"];
      }
      return [];
    },
  }}
/>

HighlightContext

All callbacks receive a context object with these properties:

PropertyTypeDescription
rowIndexnumber | nullRow index (null for column-only context)
colIndexnumber | nullColumn index (null for row-only context)
columnHighlightColumnInfoColumn definition (for column/cell contexts)
rowDataTDataRow data (for row/cell contexts)
isHoveredbooleanWhether this row/column/cell is hovered
isActivebooleanWhether this contains the active cell
isSelectedbooleanWhether this is in the selection range

For more examples, see the Highlighting Example.

Custom Cell Styling via Renderers

For dynamic styling based on data, use custom renderers:

const ConditionalRenderer = (params: CellRendererParams) => {
  const value = params.value as number;
  const color = value >= 100000 ? "text-green-600" : "text-red-600";

  return (
    <div className={`h-full flex items-center px-2 ${color}`}>
      ${value.toLocaleString()}
    </div>
  );
};

Container Styling

Style the grid container for borders, shadows, etc.:

<div className="rounded-lg overflow-hidden border shadow-lg">
  <Grid ... />
</div>

The overflow-hidden ensures rounded corners are visible.

On this page