diff --git a/apps/material-react-table-docs/components/prop-tables/rootProps.ts b/apps/material-react-table-docs/components/prop-tables/rootProps.ts index d9ebca70f..c51a2854a 100644 --- a/apps/material-react-table-docs/components/prop-tables/rootProps.ts +++ b/apps/material-react-table-docs/components/prop-tables/rootProps.ts @@ -1895,4 +1895,14 @@ export const rootProps: PropRow[] = [ source: 'MRT', type: 'MutableRefObject', }, + { + propName: 'tableFeatures', + defaultValue: '', + description: '', + link: '', + linkText: '', + required: false, + source: '', + type: 'Array<(table: MRT_TableInstance) => any>', + }, ]; diff --git a/packages/material-react-table/src/MaterialReactTable.tsx b/packages/material-react-table/src/MaterialReactTable.tsx index a43b1ff9f..25b28e946 100644 --- a/packages/material-react-table/src/MaterialReactTable.tsx +++ b/packages/material-react-table/src/MaterialReactTable.tsx @@ -567,6 +567,11 @@ export type MRT_DisplayColumnIds = | 'mrt-row-numbers' | 'mrt-row-select'; +export type MRT_CreateTableFeature< + TData extends Record = {}, + TFeature = any, +> = (table: MRT_TableInstance) => TFeature; + /** * `columns` and `data` props are the only required props, but there are over 150 other optional props. * @@ -949,6 +954,10 @@ export type MaterialReactTableProps = {}> = * @deprecated Use `rowVirtualizerProps` instead */ virtualizerProps?: any; + /** + * Sequence of features important any dependent feature must be defined first + */ + tableFeatures?: Array>; }; const MaterialReactTable = = {}>({ diff --git a/packages/material-react-table/src/table/MRT_TableRoot.tsx b/packages/material-react-table/src/table/MRT_TableRoot.tsx index 63b5119db..9011669d9 100644 --- a/packages/material-react-table/src/table/MRT_TableRoot.tsx +++ b/packages/material-react-table/src/table/MRT_TableRoot.tsx @@ -332,6 +332,12 @@ export const MRT_TableRoot: any = = {}>( props.onShowToolbarDropZoneChange ?? setShowToolbarDropZone, } as MRT_TableInstance; + if (props.tableFeatures) { + props.tableFeatures.forEach(feature => { + Object.assign(table, feature(table)); + }); + } + if (props.tableInstanceRef) { props.tableInstanceRef.current = table; }