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'.
Master / Details is configured the same way for the Server-Side Row Model and the Client-Side Row Model. For a comprehensive look at Master / Detail configurations, see: Client-Side Master / Detail.
Because the configuation is already discussed in Client-Side Master / Detail, this pages focuses on areas that are of particular interest to this Server-Side version.
To enable Master / Detail, you should set the following grid options:
true
to inform the grid you want to allow expanding of rows to reveal detail grids.These grid options are illustrated below:
const gridOptions = {
// master grid columns
columnDefs: [],
// use the server-side row model
rowModelType: 'serverSide',
// enable master detail
masterDetail: true,
detailCellRendererParams: {
detailGridOptions: {
// detail grid columns
columnDefs: [],
},
getDetailRowData: params => {
// supply data to the detail grid
params.successCallback(params.data);
}
},
// other grid options ...
}
Note that the nested detail grid can be configured to use any Row Model.
This example shows a simple Master / Detail with the Server-Side Row Model. From this example notice the following:
true
in the master grid options.detailGridOptions
to use and getDetailRowData
extracts the data for the detail row.It is possible to combine Server-Side Grouping with Master Detail.
The following snippet shows row grouping on the 'country' column by setting rowGroup = true
:
columnDefs: [
{ field: 'country', rowGroup: true },
// more column definitions
],
Below shows Row Grouping combined with Master / Detail. From the example you can notice the following:
true
on the 'country' column definition.true
to enable Master / Detail.detailGridOptions
to use and getDetailRowData
extracts the data for the detail row.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:
columnDefs: [
{ field: 'country', rowGroup: true },
{ field: 'accountId', maxWidth: 200, cellRenderer: 'agGroupCellRenderer' },
// more column definitions
],
The height of detail rows can be configured in one of the following ways:
detailRowHeight
grid option property to set a fixed height for each detail row.getRowHeight()
grid option callback to explicitly set height for each row individually. This callback will need to work out the pixel height of each detail row.detailRowAutoHeight=true
property to let the grid automatically size the detail rows / grids to fit their rows.The following snippets compares these approaches:
const gridOptions = {
detailRowHeight: 500,
// other grid options ...
}
const gridOptions = {
getRowHeight: params => {
const isDetailRow = params.node.detail;
// not that this callback gets called for all rows, not just the detail row
if (isDetailRow) {
// dynamically calculate detail row height
return params.data.children.length * 50;
}
// for all non-detail rows, return 25, the default row height
return 25;
},
// other grid options ...
}
const gridOptions = {
detailCellRendererParams: {
autoHeight: true,
},
// other grid options ...
}
Purging the cache and dynamic row heights do not work together for the Server-Side Row Model.
If you are using dynamic row height, ensure maxBlocksInCache
is not set.
The following example explicitly sets detail row heights based on the number of detail rows. Note the following:
See Master Detail Dynamic Height for more details.
The following example gets the grid to auto-size all details sections to fit their rows. This is done by setting masterGridOptions.detailRowAutoHeight = true
.
See Master Detail Auto Height for more details.
In the examples above, the data for the detail grid was returned with the master row. However it is also possible to lazy-load data for the detail row, see: Providing 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.
Continue to the next section to learn how to work with Tree Data.