By default the grid renders values into the cells as strings. If you want something more complex you use a cell renderer.
The cell editor for a column is set via
colDef.cellRenderer and can
be any of the following types:
undefined / null: Grid renders the value as a string.
String: The name of a cell renderer registered with the grid.
Class: Provide your own cell renderer component directly without registering.
Function: A function that returns either an HTML string or DOM element for display.
This remainder of this documentation page goes through the grid provided cell renderer's. To build your own cell renderer see the section Cell Rendering Components.
No Cell Renderer
If you have no requirements for custom cells, then you should use no cell renderer. Having no custom cell renderers will result in the fastest possible grid (which might be important to you if using Internet Explorer) as even the simplest cell renderer will result in some extra div's in the DOM.
If you just want to do simple formatting of the data (eg currency or date formatting)
then you can use
Many Renderers One Column
It is also possible to use different renderers for different rows in the same column.
Typically an application might check the rows contents and choose a renderer accordingly.
To configure this set
to a function that returns the name of the component to be used as a renderer and optionally
the custom params to be passed into it
The parameters that this functions will receive the same parameters than a renderer would receive:
The following example illustrates how to use different renderers and parameters in the same column. Note that:
- The column 'Value' holds data of different types as shown in the column 'Type' (numbers/genders/moods).
colDef.cellRendererSelectoris a function that selects the renderer based on the row data
The column 'Rendered Value' show the data rendered applying the component and params specified by
Grid Provided Renderers
The grid comes with three built-in renderers which are:
- agGroupCellRenderer: For displaying group values with expand / collapse functionality.
- agAnimateShowChangeCellRenderer and agAnimateSlideCellRenderer: For animating changes in data.
The following sections goes through each one in detail.
Grid Renderers - agAnimateShowChangeCellRenderer and agAnimateSlideCellRenderer
The grid provides two cell renderers for animating changes to data. They are:
agAnimateShowChangeCellRenderer:The previous value is temporarily shown beside the old value with a directional arrow showing increase or decrease in value. The old value is then faded out.
agAnimateSlideCellRenderer:The previous value shown in a faded fashion and slides, giving a ghosting effect as the old value fades adn slides away.
The example below shows both types of animation cell renders in action. To test, try the following:
- Columns A, B and C are editable.
- Columns D and E are updated via clicking the button.
- Changes to any of the first 5 columns results in animations in the Total and Average column.
- Changes to D and E also result in animations.
animateShowChangecell renderer for showing changes in values. Not many people like the animateSlide one. So if you are trying to impress someone, probably best show them the
Grid Renderer - agGroupCellRenderer
If you are grouping in the grid, then you will need to provide a group cell renderer as the group cell renderer is what provides the user with the expand and collapse functionality.
The grid's group cell renderer takes many parameters to configure it. Here is an example of a column and it's configuration:
The set of parameters for the group cell renderer are:
- suppressCount: One of [true, false], if true, count is not displayed beside the name.
- checkbox: One of [true,false], if true, a selection checkbox is included.
- suppressPadding: Set to true to node including any padding (indentation) in the child rows.
- innerRenderer: The renderer to use for inside the cell (after grouping functions are added).
- footerValueGetter: The value getter for the footer text. Can be a function or expression.
Example Group cellRenderer
Below shows an example of configuring a group cell renderer. The example setup is not realistic as it has many columns configured for the showing the groups. The reason for this is to demonstrate different group column configurations side by side. In your application, you will typically have one column for showing the groups.
The example is built up as follows:
- The data is grouped by two columns: Type (one of 'Fiction' or 'Non-Fiction') and Country (a country name, eg Ireland or United Kingdom).
The column 'Country Group - No Renderer' configures the grid to put the 'Country' group data
only into this column by setting
showRowGroup='country'. All rows that are not this group are blank. There is no cell renderer configured, so the grid just places the text for the group into the cell, there is not expand / collapse functionality.
The column 'All Groups - no Renderer' builds on before, but adds all groups by setting
showRowGroup=true. This gets the column to display all groups, but again no cell renderer so not expand / collapse functionality.
The column Group Renderer A builds on before, but adds the group cell renderer with
cellRenderer='group'. The values are exactly as per the previous column, except now we have expand and collapse functionality.
The column Group Renderer B builds on before, but adds
field=cityso that the city is displayed in the leave nodes in the group column.
The column Group Renderer C builds on before, but adds the following
suppressCount=true: Suppresses the row count.
checkbox=true: Adds a selection checkbox.
padding=20: Changes the padding (indentation) of the levels.
innerRenderer=SimpleCellRenderer: Puts custom rendering for displaying the value. The group cellRenderer will take care of all the expand / collapse, selection etc, but then allow you to customise the display of the value. In this example we add a border when the value is a group, and we add the Ireland flag (because Niall Crosby is from Ireland) to the leaf levels.