Conditional styles

Apply styles or CSS class names to rows and cells based on row data — no custom cell renderer required.

conditionalRowStyles

Pass an array of ConditionalStyles<T> objects to the conditionalRowStyles prop. Each entry runs its when predicate against every row; when it returns true the style or classNames are applied to that row.

import DataTable, { type ConditionalStyles } from 'react-data-table-component';

const conditionalRowStyles: ConditionalStyles<Deal>[] = [
  {
    when: row => row.stage === 'Closed Won',
    style: { backgroundColor: '#f0fdf4', borderLeft: '3px solid #16a34a' },
  },
  {
    when: row => row.stage === 'Closed Lost',
    style: { backgroundColor: '#fef2f2', opacity: 0.75 },
  },
];

<DataTable conditionalRowStyles={conditionalRowStyles} columns={columns} data={data} />

Style as a function

When the style values themselves depend on the row, pass a function instead of a plain object.

{
  when: row => row.salary > 100000,
  style: row => ({
    fontWeight: row.salary > 200000 ? 700 : 400,
    color: row.salary > 200000 ? '#15803d' : 'inherit',
  }),
}

CSS class names

Use classNames to apply Tailwind utilities or your own CSS classes instead of inline styles.

{
  when: row => row.flagged,
  classNames: ['bg-red-50', 'border-l-4', 'border-red-500'],
}

conditionalCellStyles

The same ConditionalStyles<T> shape applies at the cell level via the conditionalCellStyles prop on individual column definitions. This lets you highlight specific cells without changing the full row.

const columns: TableColumn<Deal>[] = [
  {
    name: 'Value',
    selector: r => r.value,
    format: r => fmt(r.value),
    right: true,
    conditionalCellStyles: [
      { when: r => r.value >= 200000, style: { fontWeight: 700, color: '#15803d' } },
      { when: r => r.value < 20000,   style: { color: '#9ca3af' } },
    ],
  },
  {
    name: 'Days open',
    selector: r => r.daysOpen,
    right: true,
    conditionalCellStyles: [
      { when: r => r.daysOpen > 90, style: { color: '#dc2626', fontWeight: 700 } },
      { when: r => r.daysOpen > 60, style: { color: '#d97706' } },
    ],
  },
];

Interaction with other row styles

Conditional row styles are applied after the base row style, so they override the default background. The hover highlight from highlightOnHover will override a conditional background on hover — which is usually the desired behavior. If you need the conditional color to persist on hover, set it via rows.highlightOnHoverStyle in customStyles.

To carry a parent row's conditional styles into its expanded panel, set expandableInheritConditionalStyles.

Conditional row and cell styles — sales pipeline

Won deals get a green left border; lost deals are dimmed. Value cells are bold-green for large deals, gray for small. Days Open cells turn amber then red as they age.

Company
Rep
Value
Stage
Days open
Massive Dynamic
Taylor Brooks
$175,000
Closed Won
33
Soylent GmbH
Sam Rivera
$38,000
Closed Lost
95
Initech LLC
Priya Kapoor
$15,000
Prospect
8
Globex Inc
Marcus Webb
$210,000
Negotiation
67
Umbrella Ltd
Jordan Ellis
$520,000
Proposal
120
Acme Corp
Aria Chen
$84,000
Closed Won
42
Vandelay Ind
Aria Chen
$62,000
Negotiation
89