Adaptable

#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.

#
A master detail grid

The Adaptable grid lists programming languages. Expand a language to see a detail grid with the developers who prefer it.

open
loading demo…

#Intercepting the Infinite Table rendering

Adaptable renders an Infinite Table <InfiniteTable /> component for you. To turn on master detail, replace it through the components.InfiniteTable prop of the Adaptable.Provider: your component receives the props Adaptable computed, and renders InfiniteTable with those props plus the master detail ones.

Intercepting the InfiniteTable rendering
const components: AdaptableProps<Language>['components'] = {
  InfiniteTable: (props) => {
    return <InfiniteTable<Language> {...props} rowDetailRenderer={renderDetail} />;
  },
};

function App() {
  return (
    <Adaptable.Provider
      data={languages}
      primaryKey="id"
      adaptableId="languages"
      defaultState={defaultState}
      components={components}
    >
      <Adaptable.UI />
    </Adaptable.Provider>
  );
}

Two props make master detail work:

  • rowDetailRenderer — renders the detail for a row;
  • renderRowDetailIcon: true on 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:

Showing the row detail icon in the first column
InfiniteTable: (props) => {
  const { columns, columnOrder } = props;
  const firstColumnId = Array.isArray(columnOrder) ? columnOrder[0] : Object.keys(columns)[0];

  return (
    <InfiniteTable<Language>
      {...props}
      columns={{
        ...columns,
        [firstColumnId]: { ...columns[firstColumnId], renderRowDetailIcon: true },
      }}
      rowDetailRenderer={renderDetail}
    />
  );
},
Note

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 any JSX — usually a nested DataSource and InfiniteTable:

The detail grid
function renderDetail(rowInfo: InfiniteTableRowInfo<Language>) {
  return (
    <div style={{ display: 'flex', flexFlow: 'column', height: '100%' }}>
      <b>{rowInfo.id} developers</b>
      <DataSource<Developer> data={detailData} primaryKey="id">
        <InfiniteTable<Developer> columns={detailColumns} />
      </DataSource>
    </div>
  );
}

// the detail DataSource receives the master row
const detailData: DataSourceData<Developer> = ({ 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.

Note

The detail grid above is a plain Infinite Table, so Adaptable features (views, styled cells, the dashboard, …) apply to the master grid only.