---
title: "Theming: Customising Selections"
framework: react
version: "36.1.0"
---

# Theming: Customising Selections

Control how selected rows and cells appear.

## Row Selections

When [row selection](https://www.ag-grid.com/react-data-grid/row-selection/) is enabled, you can set the color of selected rows using the `selectedRowBackgroundColor` parameter. If your grid uses alternating row colours we recommend setting this to a semi-transparent colour so that the alternating row colours are visible below it.

```js
const myTheme = themeQuartz.withParams({
    // bright green, 10% opacity
    selectedRowBackgroundColor: 'rgba(0, 255, 0, 0.1)',

    // alternating row colours will be visible through the semi-transparent
    // selection background colour
    oddRowBackgroundColor: '#8881',
});
```

#### Custom Row Selection Colour

```tsx
"use client";

import React, {
  useCallback,
  useMemo,
  useRef,
  useState,
  StrictMode,
} from "react";
import { createRoot } from "react-dom/client";
import { AgGridReact, AgGridProvider } from "ag-grid-react";
import {
  AllCommunityModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowSelectionOptions,
  Theme,
  enableDevValidations,
  themeQuartz,
} from "ag-grid-community";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

const modules = [AllCommunityModule];

const myTheme = themeQuartz.withParams({
  // bright green, 10% opacity
  selectedRowBackgroundColor: "rgba(0, 255, 0, 0.1)",
  // alternating row colors will be visible through the semi-transparent
  // selection background color
  oddRowBackgroundColor: "#8881",
});

const GridExample = () => {
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { field: "athlete", minWidth: 170 },
    { field: "age" },
    { field: "country" },
    { field: "year" },
    { field: "date" },
    { field: "sport" },
    { field: "gold" },
    { field: "silver" },
    { field: "bronze" },
    { field: "total" },
  ]);
  const theme = useMemo<Theme | "legacy">(() => {
    return myTheme;
  }, []);
  const rowSelection = useMemo<
    RowSelectionOptions | "single" | "multiple"
  >(() => {
    return { mode: "multiRow" };
  }, []);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      editable: true,
      filter: true,
    };
  }, []);

  const { data, loading } = useFetchJson<IOlympicData>(
    "https://www.ag-grid.com/example-assets/olympic-winners.json",
  );

  const onFirstDataRendered = useCallback((params) => {
    params.api.forEachNode((node) => {
      if (
        node.rowIndex === 2 ||
        node.rowIndex === 3 ||
        node.rowIndex === 4 ||
        node.rowIndex === 5 ||
        node.rowIndex === 6
      ) {
        node.setSelected(true);
      }
    });
  }, []);

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div style={gridStyle}>
          <AgGridReact<IOlympicData>
            rowData={data}
            loading={loading}
            columnDefs={columnDefs}
            theme={theme}
            rowSelection={rowSelection}
            defaultColDef={defaultColDef}
            onFirstDataRendered={onFirstDataRendered}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Custom Row Selection Colour](https://www.ag-grid.com/examples/theming-selections/custom-row-selection-color/reactFunctionalTs/)

## Cell Selections

[Cell selections](https://www.ag-grid.com/react-data-grid/cell-selection/) can be created by clicking and dragging on the grid. Copying from a selection will briefly highlight the range of cells (`^ Ctrl`+`C`). There are several parameters to control the selection and highlight style:

```js
const myTheme = themeQuartz.withParams({
    // colour and style of border around selection
    rangeSelectionBorderColor: 'rgb(193, 0, 97)',
    rangeSelectionBorderStyle: 'dashed',
    // background colour of selection - you can use a semi-transparent colour
    // and it wil overlay on top of the existing cells
    rangeSelectionBackgroundColor: 'rgb(255, 0, 128, 0.1)',
    // colour used to indicate that data has been copied from the cell range
    rangeSelectionHighlightColor: 'rgb(60, 188, 0, 0.3)',

    // alternating row colours will be visible through the semi-transparent
    // selection background colour
    oddRowBackgroundColor: '#8881',
});
```

#### Custom Range Selection Style

```tsx
"use client";

import React, {
  useCallback,
  useMemo,
  useRef,
  useState,
  StrictMode,
} from "react";
import { createRoot } from "react-dom/client";
import { AgGridReact, AgGridProvider } from "ag-grid-react";
import {
  CellSelectionOptions,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  Theme,
  enableDevValidations,
  themeQuartz,
} from "ag-grid-community";
import { AllEnterpriseModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

const modules = [AllEnterpriseModule];

const myTheme = themeQuartz.withParams({
  // color and style of border around selection
  rangeSelectionBorderColor: "rgb(193, 0, 97)",
  rangeSelectionBorderStyle: "dashed",
  // background color of selection - you can use a semi-transparent color
  // and it wil overlay on top of the existing cells
  rangeSelectionBackgroundColor: "rgb(255, 0, 128, 0.1)",
  // color used to indicate that data has been copied form the cell range
  rangeSelectionHighlightColor: "rgb(60, 188, 0, 0.3)",
  // alternating row colors will be visible through the semi-transparent
  // selection background color
  oddRowBackgroundColor: "#8881",
});

const GridExample = () => {
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);
  const [rowData, setRowData] = useState<IOlympicData[]>();
  const theme = useMemo<Theme | "legacy">(() => {
    return myTheme;
  }, []);
  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { field: "athlete", minWidth: 150 },
    { field: "age", maxWidth: 90 },
    { field: "country", minWidth: 150 },
    { field: "year", maxWidth: 90 },
    { field: "date", minWidth: 150 },
    { field: "sport", minWidth: 150 },
    { field: "gold" },
    { field: "silver" },
    { field: "bronze" },
    { field: "total" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 100,
    };
  }, []);

  const onGridReady = useCallback((params: GridReadyEvent) => {
    fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
      .then((resp) => resp.json())
      .then((data: IOlympicData[]) => {
        setRowData(data);
        params.api.addCellRange({
          rowStartIndex: 1,
          rowEndIndex: 5,
          columns: ["age", "country", "year", "date"],
        });
      });
  }, []);

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div style={gridStyle}>
          <AgGridReact<IOlympicData>
            rowData={rowData}
            theme={theme}
            columnDefs={columnDefs}
            defaultColDef={defaultColDef}
            cellSelection={true}
            onGridReady={onGridReady}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

[Live example: Custom Range Selection Style](https://www.ag-grid.com/examples/theming-selections/custom-range-selection-style/reactFunctionalTs/)

### Cell Selection for Integrated Charts

When using [integrated charts](https://www.ag-grid.com/react-data-grid/integrated-charts/) with cell selections, the grid uses different colors to indicate the purpose of the cell ranges:

- `rangeSelectionChartBackgroundColor` - background color for cells used as chart data
- `rangeSelectionChartCategoryBackgroundColor` - background color for cells used as categories / axis labels
