Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

304 accessorfn causes exception when stateisloading is true and data is empty array v1 #309

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/mantine-react-table/src/column.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const prepareColumns = <TData extends Record<string, any> = {}>({
defaultDisplayColumn,
filterFns,
sortingFns,
isLoading,
}: {
aggregationFns: typeof MRT_AggregationFns &
MRT_TableOptions<TData>['aggregationFns'];
Expand All @@ -61,6 +62,7 @@ export const prepareColumns = <TData extends Record<string, any> = {}>({
defaultDisplayColumn: Partial<MRT_ColumnDef<TData>>;
filterFns: typeof MRT_FilterFns & MRT_TableOptions<TData>['filterFns'];
sortingFns: typeof MRT_SortingFns & MRT_TableOptions<TData>['sortingFns'];
isLoading?: boolean;
}): MRT_DefinedColumnDef<TData>[] =>
columnDefs.map((columnDef) => {
//assign columnId
Expand Down Expand Up @@ -98,6 +100,11 @@ export const prepareColumns = <TData extends Record<string, any> = {}>({
);
}

if (columnDef?.accessorFn) {
columnDef.accessorFn = (...args) =>
!isLoading && columnDef.accessorFn!(...args);
}

//assign filterFns
if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
columnDef.filterFn =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,16 @@ export const useMRT_TableInstance: <TData extends Record<string, any> = {}>(
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,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,42 @@ export const NestedLoadingDataWithInitialSort = () => {
/>
);
};

export const EmtpyDataAndLoadingAccessorFn = () => {
const columns = useMemo<MRT_ColumnDef<Person>[]>(
() => [
{
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 (
<MantineReactTable
columns={columns}
data={[]}
state={{
sorting: [{ id: 'name.lastName', desc: false }],
isLoading: true,
}}
/>
);
};
Loading