The 14.2.0 release (October 2017) included remakes of the themes with more consistent whitespace and easier customization through Sass variables. The previous ones are still shipped, but deprecated and likely to be removed after several releases. If you are using any of the themes below, give the new counterpart a try.
|Old Theme||New Theme|
If you move to a new theme you will notice the spacing is larger. Customising the new theme to have less spacing (so it looks more like an old theme) see the Github example ag-grid-customise-theme.
ag-Grid is designed to have its look and feel derived from a theme.
Out of the box, five themes are provided:
- The light / grey theme which is used in most of the examples in the documentation.
- The dark grey / inverted theme with light text, used in some of the enterprise examples.
- A light theme with blue headers.
- A theme designed according to the Google Material Language Specs
- 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 fresh theme:
The following is an example of using the dark theme:
When to Create a Theme
You have the following options when choosing a theme:
- Use one of the provided themes e.g.
- Use one of the provided themes and tweak using the provided Sass variables.
- 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:
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!
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 diagram 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-cols-container: Contains the pinned rows. This container is within a viewport (ag-pinned-cols-viewport) that scrolls vertically to match the position of the ag-body-viewport. This container does not scroll horizontally.
- ag-body-container: Contains the non-pinned rows. This container is within a viewport (ag-body-viewport) that scrolls both vertically and horizontally.
Core DIV Elements
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.
- Row & Col Attributes: These attributes can be used to identify rows and columns using CSS selectors.
- Position Attributes: Nothing to do with style, however they stick out below, so worth mentioning. These are set by ag-Grid to position the rows within the containers. Because rows are virtualised, and widths are dynamic, these attributes cannot be set as classes, they are set as dynamic styles by ag-Grid.
Styling with For Print
Styling with the option domLayout=forPrint 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.
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*
The example below is taken from Theme Customization Example Repository:
A runnable version of the example above is available in the ag-Grid Customize Theme repository.
Following is a list of the most common Sass variables used, their default values for the fresh theme, and a short explanation of their purpose.
- The color for the checked checkboxes.
rgba(120, 120, 120, 0.4)
- The selection background color.
- The default background color.
- The color used for all borders.
- The background color for the context menu and the column menu.
- The background color used when the cell flashes when data is changed.
2px solid darkgreen
- The border used to mark cells as being copied.
1px dotted silver
- The border delimiter between cells.
$grid-size * 3
- The cell horizontal padding.
- The background color of the column labels used in the grouping / pivoting.
- The opacity of the disabled / empty text elements.
- The color of the disabled / empty text elements.
- The border color of the focused cell.
'Helvetica Neue', sans-serif
- The grid font family.
- The grid font size.
- The grid font weight (400 equals 'normal').
- The foreground opacity.
- The default color of the text.
- The basic unit used for the grid spacing and dimensions. Changing this makes the grid UI more / less compact.
- The header background color.
- The header background gradient - you can also refer to an an image with `url(...)`.
$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.
- The header icon height.
- The background color of the row when hovered.
- The icon color.
- The icon width and height (icons are square).
- 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.
- The background color of the context / column menu items when hovered.
- The odd row background color.
- The background color of the column menu.
rgba(120, 120, 120, 0.4)
- The background color of the selected cells.
rgba(255, 255, 255, 0.4)
- The background color for the copied cells.
($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.
- The font family used in the header.
- The header font size.
- The header font weight.
- The header font color opacity.
- The header font color.
- The background color of the tab in the column menu
- The tool panel background color
- The color used when the cell value decreases.
- The color used when the cell value increases.
- The background color used when the cell value changes.
$grid-size * 3 + $icon-size
- The indent used for the row groups.
$grid-size + $icon-size
- The indent used for the tool panel hierarchy.
You can examine the full, up-to-date list of the Sass variables and their usage in the source code of the themes.
_ag-theme-common.scss file contains the actual implementation, while the
ag-theme-*.scss contain the default variable values for each theme.