Server-side Master Detail
This section shows how the Server-side Row Model can be configured with a Master / Detail view.
The ability to nest grids within grids is commonly referred to as Master / Detail. Here the top level grid is referred to as the 'master grid' and the nested grid is referred to as the 'detail grid'.
As this Server-side version of Master / Detail is configured in the same way as it's Client-side counterpart, this guide will focus on areas that are of particular interest to this Server-side version.
Enabling Master / Detail
To enable Master / Detail, you should set the following grid options:
- masterDetail: Set to true to inform the grid you want to allow expanding of rows to reveal detail grids.
- detailGridOptions: The grid options to set for the detail grid. The detail grid is a fully featured instance of ag-Grid, so any configuration can be set on the detail grid that you would set any other grid.
- getDetailRowData: A function you implement to provide the grid with rows for display in the detail grids.
These grid options are illustrated below:
Example: Infinite Scrolling with Master / Detail
This example shows a simple Master / Detail setup which includes the infinite scrolling capabilities provided with the Server-side Row Model. From this example notice the following:
- masterDetail - is set to
truein the master grid options. - detailCellRendererParams - specifies the
detailGridOptionsto use andgetDetailRowDataextracts the data for the detail row. - cellRenderer: 'agGroupCellRenderer' - is used to provide expand / collapse icons on the master rows.
Combining Row Grouping with Master Detail
It is possible to combine Server-side Grouping with Master Detail.
The following snippet shows rows grouping on the 'country' column by setting rowGroup = true:
Example: Row Grouping with Master Detail
Below shows Row Grouping combined with Master / Detail. From the example you can notice the following:
- rowGroup - is set to
trueon the 'country' column definition. - masterDetail - is set to
trueto enable Master / Detail. - detailCellRendererParams - specifies the
detailGridOptionsto use andgetDetailRowDataextracts the data for the detail row. - autoGroupColumnDef - is used to specify which column in the master row should be included in the group hierarchy.
Expanding Master Rows
Normally parent rows (groups) can be expanded and child rows cannot be expanded (unless they are themselves parents). This means that normally only parent rows have expand / collapse icons.
For Master / Detail, expand and collapse icons are also needed at the master level. When doing Master / Detail expand and collapse icons are also needed to expand the child rows where those rows are also master rows.
Rather than use the autoGroupColumnDef for the master rows as shown in the example above, simply
specify a group cell renderer on the column that should show the expand / collapse icons.
This is shown in the code snippet below:
Detail Row Height
The height of detail rows can be configured in one of the following two ways:
-
Use property
detailRowHeightto set a fixed height for each detail row. -
Use callback
getRowHeight()to set height for each row individually. One extra complication here is that this method is called for every row in the grid including master rows.
The following snippet compares both approaches:
Example: Dynamic Detail Row Height
The following example shows how the detail row height can be dynamically sized to fit the number of records. From the example you can notice the following:
- getRowHeight() - is implemented to size detail rows according to the number of records.
- node.detail - is used to identify 'detail' row nodes.
Lazy Loading Detail Rows
In the examples above, the data for the detail grid was returned with the master row. However it is also possible to lazy data for the detail row, see: Lazy Loading Detail Rows.
However note that detail rows will be purged once the master row is closed, or if the detail row leaves the viewport through scrolling. In both cases data will need to be fetched again.
Next Up
Continue to the next section to learn how to work with Tree Data when using the Server-side Row Model.