diff --git a/packages/table/src/core/Table/Table.tsx b/packages/table/src/core/Table/Table.tsx index 32c183170..53868e619 100644 --- a/packages/table/src/core/Table/Table.tsx +++ b/packages/table/src/core/Table/Table.tsx @@ -35,10 +35,8 @@ export const Table: React.FC = ({ const ref = React.useRef(); - const refinedColumnDefs: ColDef[] = getCollatedColumns( - defaultColumnDef, - columnDefs, - types, + const refinedColumnDefs: ColDef[] = columnDefs.map((column) => + getCollatedColumns(defaultColumnDef, column, types), ); const sizes = getSizes(theme, visualOptions?.density ?? 'default'); diff --git a/packages/table/src/core/utils/columns.test.ts b/packages/table/src/core/utils/columns.test.ts index ba9960609..e0b8e1dc7 100644 --- a/packages/table/src/core/utils/columns.test.ts +++ b/packages/table/src/core/utils/columns.test.ts @@ -26,10 +26,18 @@ const getColDefByIDCases: [string, ColDef[], VirtualItem, ColDef][] = [ const getCollatedColumnsCases: [ string, DefaultColDef, - ColDef[], + ColDef, ColumnType[], - ColDef[], -][] = [['No column definitions', DEFAULT_COLDEF, [], [], []]]; + ColDef, +][] = [ + [ + 'No column definitions', + DEFAULT_COLDEF, + { id: 'null' }, + [], + { id: 'null', headerName: 'Column' }, + ], +]; describe('Table', () => { describe('Utils', () => { @@ -45,8 +53,8 @@ describe('Table', () => { describe('getCollatedColumns', () => { it.each(getCollatedColumnsCases)( '%s', - (_title, defaultColDef, colDefs, types, expected) => { - expect(getCollatedColumns(defaultColDef, colDefs, types)).toEqual( + (_title, defaultColDef, column, types, expected) => { + expect(getCollatedColumns(defaultColDef, column, types)).toEqual( expected, ); }, diff --git a/packages/table/src/core/utils/columns.ts b/packages/table/src/core/utils/columns.ts index bd135d7e4..4b7405bf7 100644 --- a/packages/table/src/core/utils/columns.ts +++ b/packages/table/src/core/utils/columns.ts @@ -13,15 +13,11 @@ export const getColDefByID = ( */ export const getCollatedColumns = ( defaultColumnDef: DefaultColDef, - columnDefs: ColDef[], + column: ColDef, types: ColumnType[], -): ColDef[] => { - return ( - columnDefs?.map((column) => { - const type = types.find((element) => element.id === column.type); - return { ...defaultColumnDef, ...type, ...column }; - }) ?? [] - ); +): ColDef => { + const type = types.find((element) => element.id === column.type); + return { ...defaultColumnDef, ...type, ...column }; }; export const getOccupiedWidthInfo = (colDefs: ColDef[]): [number, number] =>