Replies: 3 comments 2 replies
-
Use a proper dependency array in your useMemo, or don't memoize the columns. Make sure to provide an empty fallback array while loading. |
Beta Was this translation helpful? Give feedback.
-
Finally works. - when empty it does produce empty array... This is just an example. forcing fields edited to be in error... const columns = useMemo(
); MUCH Appreciated. |
Beta Was this translation helpful? Give feedback.
-
Thanks again. works. I am not sure if it is the best approach. but i need to modify the Edit functionality. muiEditTextFieldProps dynamically. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I understand the columns need to be in a useMemo or useState. However I have a case where the columns definitions are not static. They need to be built dynamically.
Example if you want to generate. muiEditTextFieldProps dynamically.
The problem is that initial the columns will be null until the columns are pre-processed and passed.
Obtain error
material-react-table/src/utils/column.utils.ts
column.utils.ts:23 Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')
at getLeafColumns (column.utils.ts:23:1)
at getAllLeafColumnDefs (column.utils.ts:31:1)
at getDefaultColumnOrderIds (displayColumn.utils.ts:126:1)
at useMRT_TableInstance.ts:60:1
at mountMemo (react-dom.development.js:17225:1)
at Object.useMemo (react-dom.development.js:17670:1)
at useMemo (react.development.js:1650:1)
at useMRT_TableInstance (useMRT_TableInstance.ts:58:1)
at useMaterialReactTable (useMaterialReactTable.ts:9:1)
at Example (TableMainExample2.jsx:212:1)
import { type Row } from '@tanstack/react-table';
import {
type MRT_Column,
type MRT_ColumnDef,
type MRT_ColumnOrderState,
type MRT_DefinedColumnDef,
type MRT_DefinedTableOptions,
type MRT_FilterOption,
type MRT_RowData,
type MRT_TableInstance,
} from '../types';
export const getColumnId = (
columnDef: MRT_ColumnDef,
): string =>
columnDef.id ?? columnDef.accessorKey?.toString?.() ?? columnDef.header;
export const getAllLeafColumnDefs = (
columns: MRT_ColumnDef[],
): MRT_ColumnDef[] => {
const allLeafColumnDefs: MRT_ColumnDef[] = [];
const getLeafColumns = (cols: MRT_ColumnDef[]) => {
cols.forEach((col) => {
if (col.columns) {
getLeafColumns(col.columns);
} else {
allLeafColumnDefs.push(col);
}
});
};
How to work around this issue ?
Beta Was this translation helpful? Give feedback.
All reactions