diff --git a/packages/react-datagrid/src/grid/createDataGrid.tsx b/packages/react-datagrid/src/grid/createDataGrid.tsx index e4fbfa4a67..e1bc595869 100644 --- a/packages/react-datagrid/src/grid/createDataGrid.tsx +++ b/packages/react-datagrid/src/grid/createDataGrid.tsx @@ -35,7 +35,7 @@ const dummyStateMethods: DataGridStateMethods = { } const createInitialState = (props: DataGridProps<{}>, environment: Environment): DataGridState => { - const columns = extractDataGridColumns(props.children) + const columns = extractDataGridColumns(props.children, environment) return { columns, paging: { diff --git a/packages/react-datagrid/src/internal/gridTemplateAnalyzer.ts b/packages/react-datagrid/src/internal/gridTemplateAnalyzer.ts index b22ce59747..011374c148 100644 --- a/packages/react-datagrid/src/internal/gridTemplateAnalyzer.ts +++ b/packages/react-datagrid/src/internal/gridTemplateAnalyzer.ts @@ -2,6 +2,7 @@ import { ChildrenAnalyzer, Leaf } from '@contember/react-multipass-rendering' import type { ReactNode } from 'react' import { DataGridColumnProps, DataGridColumns } from '../types' import { DataGridColumn } from '../grid' +import { Environment } from '@contember/react-binding' class BoxedGridColumnProps { public constructor(public readonly value: DataGridColumnProps) {} @@ -9,13 +10,13 @@ class BoxedGridColumnProps { const gridColumnLeaf = new Leaf(node => new BoxedGridColumnProps(node.props), DataGridColumn) -const gridTemplateAnalyzer = new ChildrenAnalyzer([gridColumnLeaf], { +const gridTemplateAnalyzer = new ChildrenAnalyzer([gridColumnLeaf], { ignoreUnhandledNodes: false, unhandledNodeErrorMessage: `DataGrid: encountered an illegal child node.`, }) -export const extractDataGridColumns = (nodes: ReactNode): DataGridColumns => { - const processed = gridTemplateAnalyzer.processChildren(nodes, undefined) +export const extractDataGridColumns = (nodes: ReactNode, env: Environment): DataGridColumns => { + const processed = gridTemplateAnalyzer.processChildren(nodes, env) let counter = 0 const suffixes: Record = {} diff --git a/packages/react-datagrid/src/internal/useDataGridState.ts b/packages/react-datagrid/src/internal/useDataGridState.ts index 294d10942c..e72940b1f6 100644 --- a/packages/react-datagrid/src/internal/useDataGridState.ts +++ b/packages/react-datagrid/src/internal/useDataGridState.ts @@ -18,7 +18,7 @@ export const DATA_GRID_DEFAULT_ITEMS_PER_PAGE = 50 export const useDataGridState = (props: Pick, 'children' | 'itemsPerPage' | 'entities' | 'dataGridKey' | 'tile'>): [DataGridState, DataGridStateMethods] => { const dataGridKey = useDataGridKey(props) const environment = useEnvironment() - const columns = useMemo(() => extractDataGridColumns(props.children), [props.children]) + const columns = useMemo(() => extractDataGridColumns(props.children, environment), [environment, props.children]) const [pageState, updatePaging] = useGridPagingState(props.itemsPerPage ?? DATA_GRID_DEFAULT_ITEMS_PER_PAGE, dataGridKey) const [hiddenColumns, setIsColumnHidden] = useHiddenColumnsState(columns, dataGridKey) const [orderDirections, setOrderBy] = useOrderBys(columns, updatePaging, dataGridKey)