Master Detail

View as Markdown
The Angular DataGrid that Infinite Table offers has native support for master-detail rows.
The single most important property for the master-detail DataGrid configuration is the rowDetailRenderer function prop - which makes the DataGrid be considered master-detail.
In addition, make sure you have a column with the renderRowDetailIcon: true flag set. columns.renderRowDetailIcon on a column makes the column display the row detail expand icon.
The row detail in the DataGrid can contain another DataGrid or any other custom content.
It's very imporant that the rowDetailRenderer function you pass into <infinite-table> is stable. Make it a field of your component (an arrow function), not a method called in the template, so the grid gets a reference to the same function every time - except of course if you want the row detail to change based on some other state.
The rowDetailRenderer function returns the content of the row detail: usually an ng-template of your component (a TemplateRef, read with viewChild), which gets the master row as its context (let-rowInfo). For a detail DataGrid, the template holds an <infinite-data-source> with an <infinite-table> inside.
#
Basic master detail DataGrid example
This example shows a master DataGrid with cities & countries.
The details for each city shows a DataGrid with developers in that city.
The detail DataGrid is configured with remote sorting.
open
loading demo…
If you want to use a component instead of the rowDetailRenderer function, you can use the components.RowDetail property. This works similarly and makes the DataGrid be considered master-detail. Inside the component, injectMasterRowInfo gives you the master row information, as a signal.

Loading the Detail DataSource#

When master-detail is configured and the row detail renders a DataGrid, the data function for the detail <DataSource /> will be called with the masterRowInfo as a property available in the object passed as argument.
Loading the detail DataGrid data
const detailDataFn: DataSourceData<Developer> = ({
  masterRowInfo,
  sortInfo,
  // ...
}) => {
  return Promise.resolve([
    /* ... */
  ]);
};

// the detail DataSource, in the template the rowDetailRenderer returns:
// <ng-template #detail>
//   <infinite-data-source [data]="detailDataFn" primaryKey="id">
//     ...
//   </infinite-data-source>
// </ng-template>
You can see the live example above for more details.

Rendering a detail DataGrid#

Using the rowDetailRenderer prop, you can render any custom content for the row details.
The content doesn't need to include Infinite Table.
You can, however, render an Infinite Table Angular DataGrid, at any level of nesting inside the row detail content.
#
Master detail with custom content & DataGrid
In this example, the row detail contains custom content, along with another Infinite Table DataGrid. You can nest a child DataGrid inside the row details at any level of nesting.
open
loading demo…

Configuring the master-detail height#

In order to configure the height of the row details, you can use the rowDetailHeight prop.
Configuring the row detail height
<infinite-table [columns]="masterColumns" [rowDetailHeight]="500" [rowDetailRenderer]="renderDetail" />
The default value for the rowDetailHeight is 300 px.
rowDetailHeight can be one of the following:
  • number - the height in pixels
  • string - the name of a CSS variable that configures the height - eg: --master-detail-height
  • (rowInfo) => number - a function that can return a different height for each row. The sole argument is the rowInfo object.
#
Master detail DataGrid with custom height for row details
This master-detail DataGrid is configured with a custom rowDetailHeight of 200px.
open
loading demo…

Conditional row details#

Not all rows in a DataGrid need to have details. To configure which rows have details, you can use the isRowDetailEnabled function prop.
Using conditional row details
// <infinite-table
//   [columns]="masterColumns"
//   [rowDetailHeight]="500"
//   [rowDetailRenderer]="renderDetail"
//   [isRowDetailEnabled]="isRowDetailEnabled"
// />
protected readonly isRowDetailEnabled = (
  rowInfo: InfiniteTableRowInfo<City>,
) => rowInfo.data?.cityName?.includes('i') ?? false;
The isRowDetailEnabled function prop is called with the rowInfo object and is expected to return a boolean value.
#
Master detail DataGrid with conditional details
This example shows a master DataGrid with cities & countries.
Not all rows have details - every other row is configured without details via the isRowDetailEnabled function prop.
open
loading demo…