Themes

Legacy Themes

The v19 release retired the old themes that are no longer shipped with ag-Grid. If you are using an old theme, you should change it to it's new version. See table below:

Old ThemeNew Theme
ag-freshag-theme-fresh
ag-darkag-theme-dark
ag-blueag-theme-blue
ag-materialag-theme-material
ag-bootstrapag-theme-bootstrap

ag-Grid is designed to have its look and feel derived from a theme. The following themes are available out of the box:

ag-theme-balham
The default flat light theme which is used in most of the examples in the documentation.
ag-theme-balham-dark
A dark variation of the balham theme, used in the enterprise examples in the documentation.
ag-theme-material
A theme designed according to the Google Material Language Specs.
ag-theme-fresh
A light gray theme.
ag-theme-dark
A dark grey theme.
ag-theme-blue
A light theme with blue headers.
ag-theme-bootstrap
Neutral / white theme that fits well in the context of bootstrap components. Notice: the theme does not have a bootstrap dependency.

To use a theme, add the theme class name to the div element where the ag-Grid directive is attached.

The following is an example of using the balham theme:

<div id="myGrid" class="ag-theme-balham"></div>

The following is an example of using the dark balham theme:

<div id="myGrid" class="ag-theme-balham-dark"></div>

When to Create a Theme

You have the following options when choosing a theme:

  1. Use one of the provided themes e.g. ag-theme-balham.
  2. Use one of the provided themes and tweak using the provided Sass variables.
  3. Create your own theme from scratch. This is the most complex approach and you are more exposed to breaking changes in ag-Grid releases.

You should only create your own theme when options 1 and 2 above don't suit, as it is the most difficult. If you do decide to create your own theme, then you can use one of the provided themes and use that as a template. They can be found on GitHub here: https://github.com/ceolter/ag-grid/tree/master/src/styles.

This section does not provide an example of building a theme as a number of themes are already provided with ag-Grid - these can be used as a basis for any additional themes you may wish to create.

When to Style via Themes

Themes are intended to change the overall look and feel of a grid. If you want to style a particular column, or a particular header, consider using either cell and header renderers, or applying CSS classes or styles at the column definition level.

Sometimes it is possible to achieve the same effect using custom renderers as it is with themes. If so, use whichever one makes more sense for you, there isn't a hard and fast rule.

What to Style via Themes

Any of the CSS classes described below can have style associated with them. However you should be cautious about overriding style that is associated outside of the theme. For example, the ag-pinned-cols-viewport, has the following style:

.ag-pinned-cols-viewport { float: left; position: absolute; overflow: hidden; }

The style attributes float, position and overflow are intrinsic to how the grid works. Changing these values will change how the grid operates. If unsure, take a look at the styles associated with an element using your browsers developer tools. If still unsure, try it out, if the style you want to apply breaks the grid, then it's not a good style to apply!

Structure Example

The exact structure of the DOM within ag-Grid is dependent on its configuration and what data is present. This page takes the below basic example grid, with one pinned column, as an example to demonstrate the DOM structure. The reader is encouraged to inspect the DOM (using your browsers developer tools) to dig deeper.

High Level Overview

The code below shows the hierarchy of the core div elements which form the four quadrants of the table. The four quadrants are as follows:

  • ag-pinned-header: Contains the pinned header cells. This container does not scroll.
  • ag-header-container: Contains the non-pinned header cells. This container is within a viewport (ag-header-viewport) that scrolls horizontally to match the position of the ag-body-viewport. This container does not scroll vertically.
  • ag-pinned-left-cols-container or ag-pinned-right-cols-container: Contains the pinned rows. This container is within a viewport (ag-body-viewport) that scrolls vertically. This container does not scroll horizontally.
  • ag-center-cols-container: Contains the non-pinned rows. This container is within a viewport (ag-center-cols-viewport) that scrolls horizontally.
The ag-header-viewport does not have scrollbars. It only scrolls in response to changes to the ag-center-cols-viewport.

Detailed Breakdown

Below gives a detailed breakdown of the DOM for the example. In the example, the following is highlighted:

  • Classes: These CSS classes can have style associated with them in a theme.
<div class="ag-root"> <!-- header --> <div class="ag-header"> <div class="ag-pinned-left-header"> <div class="ag-header-row"> <!-- pinned header cell --> <div class="ag-header-cell"> <div class="ag-cell-label-container"> <div class="ag-header-cell-label"> <span class="ag-header-cell-text">Athlete</span> </div> </div> </div> <div class="ag-header-cell"> <div class="ag-cell-label-container"> <div class="ag-header-cell-label"> <span class="ag-header-cell-text">Age</span> </div> </div> </div> </div> </div> <div class="ag-header-viewport"> <div class="ag-header-container"> <div class="ag-header-row"> <!-- main header cell --> <div class="ag-header-cell"> <div class="ag-cell-label-container"> <div class="ag-header-cell-label"> <span class="ag-header-cell-text">Country</span> </div> </div> </div> <div class="ag-header-cell"> <div class="ag-cell-label-container"> <div class="ag-header-cell-label"> <span class="ag-header-cell-text">Year</span> </div> </div> </div> <!-- the other header cells... --> </div> </div> </div> </div> <!-- body --> <div class="ag-body-viewport> <div class="ag-pinned-left-cols-container"> <div class="ag-row"> <div class="ag-cell">Michael Phelps</div> <div class="ag-cell">23</div> </div> <div class="ag-row"> <div class="ag-cell">Michael Phelps</div> <div class="ag-cell">19</div> </div> <!-- the other pinned rows... --> </div> <div class="ag-center-cols-viewport"> <div class="ag-center-cols-container"> <div class="ag-row"> <div class="ag-cell">United States</div> <div class="ag-cell">2008</div> <!-- the other row cells... --> </div> <div class="ag-row"> <div class="ag-cell">United States</div> <div class="ag-cell">2004</div> <!-- the other row cells... --> </div> <!-- the other body rows... --> </div> </div> </div> </div>

Styling with For Print

Styling with the option domLayout='print' is similar to styling as normal, however the dom layout is much simpler. When laying out for printing, there are no pinned columns and no viewports for scrolling.

<div class="ag-root ag-layout-print"> <!-- header --> <div class="ag-header"> <div class="ag-header-viewport"> <div class="ag-header-container"> <div class="ag-header-row"> <!-- main header cell --> <div class="ag-header-cell"> <div class="ag-cell-label-container"> <div class="ag-header-cell-label"> <span class="ag-header-cell-text">Athlete</span> </div> </div> </div> <div class="ag-header-cell"> <div class="ag-cell-label-container"> <div class="ag-header-cell-label"> <span class="ag-header-cell-text">Age</span> </div> </div> </div> <div class="ag-header-cell"> <div class="ag-cell-label-container"> <div class="ag-header-cell-label"> <span class="ag-header-cell-text">Country</span> </div> </div> </div> <div class="ag-header-cell"> <div class="ag-cell-label-container"> <div class="ag-header-cell-label"> <span class="ag-header-cell-text">Year</span> </div> </div> </div> <!-- the other header cells... --> </div> </div> </div> </div> <!-- body --> <div class="ag-body-viewport> <div class="ag-center-cols-viewport"> <div class="ag-center-cols-container"> <div class="ag-row"> <div class="ag-cell">Michael Phelps</div> <div class="ag-cell">23</div> <div class="ag-cell">United States</div> <div class="ag-cell">2008</div> <!-- the other row cells... --> </div> <div class="ag-row"> <div class="ag-cell">Michael Phelps</div> <div class="ag-cell">19</div> <div class="ag-cell">United States</div> <div class="ag-cell">2004</div> <!-- the other row cells... --> </div> <!-- the other body rows... --> </div> </div> </div> </div>

Highlighting Rows and Columns

The class ag-row-hover and ag-column-hover are added to cells as the mouse is dragged over the cells row or column.

The example below demonstrates the following:

  • CSS class ag-row-hover has background color added to it, so when you hover over a cell, the row will be highlighted.
  • CSS class ag-column-hover has background color added to it, so when you hover over a cell or a header, the column will be highlighted.
  • If you hover over a header group, all columns in the group will be highlighted.

Customizing the themes with Sass variables

ag-Grid themes are build using Sass. This means that you can change the looks of the theme you use using Sass, by overriding the theme variables value and referencing the Sass source files afterwards.

Some of the things you can change in the theme include:

  • Changing the text / header / tool panel foreground and background colors
  • Changing the icons size and color
  • Changing the cell / row spacing*
* If you are going to change the row or header height, you should also modify the respective options in the JavaScript grid configuration. This is a redundant step we are looking into removing in the future.

For a live example, see: Theme Customization Example Repository:

Following is a list of Sass variables, their default values, and a short explanation of their purpose.

Base Variables
Balham Theme
Material Theme
Variable Name Default Value Description
foreground-opacity 1 The foreground opacity.
secondary-foreground-color-opacity 1 The header font color opacity.
disabled-foreground-color-opacity 0.5 The opacity of the disabled / empty text elements.
icon-color <no default> The icon color.
alt-icon-color <no default> The secondary icon, used on icons with two colors (eg. checkbox background).
foreground-color <no default> The default color of the text.
secondary-foreground-color <no default> The header font color.
disabled-foreground-color <no default> The color of the disabled / empty text elements.
menu-option-active-color <no default> The background color of the context / column menu items when hovered.
input-disabled-background-color #ebebeb The color of disabled input field
card-background-color <no default> The background color for the context menu and the column menu.
border-color <no default> The color used for all borders.
primary-color <no default> The main color associated with selected cells and other items (eg. cell border color, sidbar selected tab border).
accent-color <no default> The color for the checked checkboxes.
background-color <no default> The default background color.
odd-row-background-color <no default> The odd row background color.
editor-background-color <no default> The background color of cells being edited.
header-background-color <no default> The header background color.
header-cell-hover-background-color $header-background-color The header background color while hovering
header-cell-moving-background-color #bebebe The header background color while being moved.
header-foreground-color <no default> The header text color.
header-background-image <no default> The header background gradient - you can also refer to an an image with `url(...)`.
panel-background-color <no default> The background color of the column menu.
tool-panel-background-color <no default> The tool panel background color
chip-background-color <no default> The background color of the column labels used in the grouping / pivoting.
range-selection-background-color <no default> The background color of the selected cells.
hover-color <no default> The background color of the row when hovered.
selected-color <no default> The background color of selected rows.
cell-data-changed-color <no default> The background color used when the cell flashes when data is changed.
focused-cell-border-color <no default> The border color of the focused cell.
tab-background-color <no default> The background color of the tab in the column menu
cell-highlight-border <no default> The border used to mark cells as being copied.
cell-horizontal-border <no default> The border delimiter between cells.
ag-range-selected-color-1 <no default> The selection background color.
ag-range-selected-color-2 <no default> The selection background color when it overlaps with another selection (range) 1 level.
ag-range-selected-color-3 <no default> The selection background color when it overlaps with another selection (range) 2 levels.
ag-range-selected-color-4 <no default> The selection background color when it overlaps with another selection (range) 3 levels.
value-change-delta-up-color <no default> The color used when the cell value increases.
value-change-delta-down-color <no default> The color used when the cell value decreases.
value-change-value-highlight-background-color <no default> The background color used when the cell value changes.
row-floating-background-color <no default> The background color of the pinned rows.
row-stub-background-color <no default> The color of row stub background (see: Row Node)
grid-size 4px The basic unit used for the grid spacing and dimensions. Changing this makes the grid UI more / less compact.
icon-size 12px The icon width and height (icons are square).
header-height grid-size * 6 + 1 The header row height - if you change this, you also have to change the value of the `headerHeight` in the grid options. We are looking into removing this redundant step in the future.
row-height grid-size * 6 + 1 The row height - if you change this, you also have to change the value of the `rowHeight` in the grid options. We are looking into removing this redundant step in the future.
cell-horizontal-padding grid-size * 3 The cell horizontal padding.
virtual-item-height grid-size * 5 The height of virtual items (eg. Set Filter items).
header-icon-size 14px The header icon height.
icons-path ../../ag-theme-base/icons/ The path to the icon svg files. If you are to change that, make sure that the directory you point to contains the complete set of icons.
font-family 'Helvetica Neue', sans-serif The grid font family.
font-size 14px The grid font size.
font-weight 400 The grid font weight
secondary-font-family font-family The font family used in the header.
secondary-font-size 14px The header font size.
secondary-font-weight 400 The header font weight.
card-shadow none Box shadow value for the context menu and the column menu.
card-radius 0 Border radius for the context menu and the column menu.
row-border-width 0 the row border width.
toolpanel-indent-size grid-size * icon-size The indent used for the tool panel hierarchy.
row-group-indent-size grid-size * 3 + icon-size The indent used for the row groups.

You can examine the full, up-to-date list of the Sass variables and their usage in the source code of the themes.