diff --git a/packages/mantine-react-table/src/column.utils.ts b/packages/mantine-react-table/src/column.utils.ts index ebd879b60..63168e446 100644 --- a/packages/mantine-react-table/src/column.utils.ts +++ b/packages/mantine-react-table/src/column.utils.ts @@ -53,6 +53,7 @@ export const prepareColumns = = {}>({ defaultDisplayColumn, filterFns, sortingFns, + isLoading, }: { aggregationFns: typeof MRT_AggregationFns & MRT_TableOptions['aggregationFns']; @@ -61,6 +62,7 @@ export const prepareColumns = = {}>({ defaultDisplayColumn: Partial>; filterFns: typeof MRT_FilterFns & MRT_TableOptions['filterFns']; sortingFns: typeof MRT_SortingFns & MRT_TableOptions['sortingFns']; + isLoading?: boolean; }): MRT_DefinedColumnDef[] => columnDefs.map((columnDef) => { //assign columnId @@ -98,6 +100,11 @@ export const prepareColumns = = {}>({ ); } + if (columnDef?.accessorFn) { + columnDef.accessorFn = (...args) => + !isLoading && columnDef.accessorFn!(...args); + } + //assign filterFns if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) { columnDef.filterFn = diff --git a/packages/mantine-react-table/src/hooks/useMRT_TableInstance.ts b/packages/mantine-react-table/src/hooks/useMRT_TableInstance.ts index 1042e3a45..687bee114 100644 --- a/packages/mantine-react-table/src/hooks/useMRT_TableInstance.ts +++ b/packages/mantine-react-table/src/hooks/useMRT_TableInstance.ts @@ -139,12 +139,16 @@ export const useMRT_TableInstance: = {}>( defaultDisplayColumn: tableOptions.defaultDisplayColumn ?? {}, filterFns: tableOptions.filterFns as any, sortingFns: tableOptions.sortingFns as any, + isLoading: + tableOptions.state?.isLoading || tableOptions.state?.showSkeletons, }), [ columnFilterFns, displayColumns, tableOptions.columns, tableOptions.state?.columnFilterFns, + tableOptions.state?.isLoading, + tableOptions.state?.showSkeletons, ], ); diff --git a/packages/mantine-react-table/stories/fixed-bugs/loading.stories.tsx b/packages/mantine-react-table/stories/fixed-bugs/loading.stories.tsx index 76d740b43..1a73e4a88 100644 --- a/packages/mantine-react-table/stories/fixed-bugs/loading.stories.tsx +++ b/packages/mantine-react-table/stories/fixed-bugs/loading.stories.tsx @@ -212,3 +212,42 @@ export const NestedLoadingDataWithInitialSort = () => { /> ); }; + +export const EmtpyDataAndLoadingAccessorFn = () => { + const columns = useMemo[]>( + () => [ + { + accessorFn: (row) => row.name.firstName, + header: 'First Name', + }, + { + accessorKey: 'name.lastName', + header: 'Last Name', + }, + { + accessorKey: 'address', + header: 'Address', + }, + { + accessorKey: 'city', + header: 'City', + }, + { + accessorKey: 'state', + header: 'State', + }, + ], + [], + ); + + return ( + + ); +};