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

# Theming: Customising Selections

Control how selected rows and cells appear.

## Row Selections

When [row selection](https://www.ag-grid.com/javascript-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

```ts
import {
  AllCommunityModule,
  ColDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
  themeQuartz,
} from "ag-grid-community";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([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 columnDefs: ColDef[] = [
  { field: "athlete", minWidth: 170 },
  { field: "age" },
  { field: "country" },
  { field: "year" },
  { field: "date" },
  { field: "sport" },
  { field: "gold" },
  { field: "silver" },
  { field: "bronze" },
  { field: "total" },
];

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  theme: myTheme,
  columnDefs: columnDefs,
  rowSelection: { mode: "multiRow" },
  defaultColDef: {
    editable: true,
    filter: true,
  },
  onFirstDataRendered: (params) => {
    params.api.forEachNode((node) => {
      if (
        node.rowIndex === 2 ||
        node.rowIndex === 3 ||
        node.rowIndex === 4 ||
        node.rowIndex === 5 ||
        node.rowIndex === 6
      ) {
        node.setSelected(true);
      }
    });
  },
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => {
    gridApi.setGridOption("rowData", data);
  });
```

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

## Cell Selections

[Cell selections](https://www.ag-grid.com/javascript-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

```ts
import {
  GridApi,
  GridOptions,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
  themeQuartz,
} from "ag-grid-community";
import { AllEnterpriseModule } from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([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",
});

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  theme: myTheme,
  columnDefs: [
    { 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" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  cellSelection: true,
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => {
    gridApi!.setGridOption("rowData", data);
    gridApi.addCellRange({
      rowStartIndex: 1,
      rowEndIndex: 5,
      columns: ["age", "country", "year", "date"],
    });
  });
```

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

### Cell Selection for Integrated Charts

When using [integrated charts](https://www.ag-grid.com/javascript-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
