#Master Detail
Master detail shows a detail area — typically another grid — under a row of the main grid, when the user expands that row. Adaptable builds on the master detail support of Infinite Table, the grid engine underneath.
The Adaptable grid lists programming languages. Expand a language to see a detail grid with the developers who prefer it.
#Intercepting the Infinite Table rendering
Adaptable renders an Infinite Table <infinite-table> component for you. To
turn on master detail, replace it through components.InfiniteTable of
<adaptable-provider>: a component with a props input receives the props
Adaptable computed, and renders the engine table with those props plus the
master detail ones, in <ng-container [adaptableEngineTable]="…" />.
@Component({
selector: 'languages-table',
imports: [AdaptableEngineTable],
template: `<ng-container [adaptableEngineTable]="tableProps()" />`,
})
class LanguagesTable {
// the props Adaptable computed for the engine table
readonly props = input.required<InfiniteTableProps<Language>>();
protected readonly tableProps = computed((): InfiniteTableProps<Language> => ({
...this.props(),
rowDetailRenderer: renderDetail,
}));
}
const components: AdaptableProps<Language>['components'] = {
InfiniteTable: LanguagesTable,
};
@Component({
selector: 'app-root',
imports: [AdaptableProvider, AdaptableUI],
template: `
<adaptable-provider [components]="components"
[data]="languages"
primaryKey="id"
adaptableId="languages"
[defaultState]="defaultState"
>
<adaptable-ui />
</adaptable-provider>
`,
})
export class App {
protected readonly languages = languages;
protected readonly defaultState = defaultState;
protected readonly components = components;
}Two props make master detail work:
rowDetailRenderer— renders the detail for a row;renderRowDetailIcon: trueon one of the columns — shows the expand/collapse icon in that column.
Adaptable builds the columns from your views, so set the icon on the column object you receive, without changing the original:
protected readonly tableProps = computed((): InfiniteTableProps<Language> => {
const props = this.props();
const { columns, columnOrder } = props;
const firstColumnId = Array.isArray(columnOrder) ? columnOrder[0] : Object.keys(columns)[0];
return {
...props,
columns: {
...columns,
[firstColumnId]: { ...columns[firstColumnId], renderRowDetailIcon: true },
},
rowDetailRenderer: renderDetail,
};
});Always pass the incoming props through: they carry the columns, sorting,
selection, menus and editing that Adaptable manages. Other Infinite Table master
detail props — such as rowDetailHeight or isRowDetailEnabled — can be added
the same way.
#Rendering the detail
rowDetailRenderer is called with the Infinite Table row info of the expanded
row and returns what to render — usually an <ng-template> of the wrapper
component (its let- variable is the row info), with a nested
<infinite-data-source> and <infinite-table>, from
@adaptabletools/datagrid-angular/infinite:
@Component({
selector: 'languages-table',
imports: [AdaptableEngineTable, DataSource, InfiniteTable],
template: `
<ng-container [adaptableEngineTable]="tableProps()" />
<!-- the detail of a row: let-rowInfo is its row info -->
<ng-template #detail let-rowInfo>
<div style="display: flex; flex-flow: column; height: 100%">
<b>{{ rowInfo.id }} developers</b>
<infinite-data-source [data]="detailData" primaryKey="id">
<infinite-table [columns]="detailColumns" />
</infinite-data-source>
</div>
</ng-template>
`,
})
export class LanguagesTableWithDetail {
readonly props = input.required<InfiniteTableProps<Language>>();
protected readonly detailData = detailData;
protected readonly detailColumns = detailColumns;
private readonly detail = viewChild.required<TemplateRef<unknown>>('detail');
// a field, so the table gets the same function every time
private readonly renderDetail = () => this.detail();
protected readonly tableProps = computed((): InfiniteTableProps<Language> => ({
...this.props(),
rowDetailRenderer: this.renderDetail,
}));
}
// the detail DataSource receives the master row
const detailData: DataSourceProps<Developer>['data'] = ({ masterRowInfo }) =>
developers.filter((d) => d.preferredLanguage === masterRowInfo!.id);The data function of the detail DataSource receives masterRowInfo, the row
being expanded, and can return an array or a Promise — so the detail rows can
be loaded from a server on demand. See
loading the detail DataSource
in the Infinite Table docs.
The detail grid above is a plain Infinite Table, so Adaptable features (views, styled cells, the dashboard, …) apply to the master grid only.