diff --git a/packages/main/src/components/AnalyticalTable/__snapshots__/AnalyticalTable.test.tsx.snap b/packages/main/src/components/AnalyticalTable/__snapshots__/AnalyticalTable.test.tsx.snap index c9368a18c3c..0edcd54d430 100644 --- a/packages/main/src/components/AnalyticalTable/__snapshots__/AnalyticalTable.test.tsx.snap +++ b/packages/main/src/components/AnalyticalTable/__snapshots__/AnalyticalTable.test.tsx.snap @@ -23,13 +23,13 @@ exports[`AnalyticalTable Alternate Row Color 1`] = `
= forwardRef((props: TableProps, ref: Ref< const visibleColumns = columns.filter(Boolean).filter((item) => { return (item.isVisible ?? true) && !tableState.hiddenColumns.includes(item.accessor); }); - const columnsWithFixedWidth = visibleColumns - .filter(({ width, minWidth }) => width ?? minWidth ?? false) - .map(({ width, minWidth }) => width ?? minWidth); + const columnsWithFixedWidth = visibleColumns.filter(({ width }) => width ?? false).map(({ width }) => width); const fixedWidth = columnsWithFixedWidth.reduce((acc, val) => acc + val, 0); - if (visibleColumns.length > 0 && tableRef.current.clientWidth > 0) { - setColumnWidth( - (tableRef.current.clientWidth - fixedWidth) / (visibleColumns.length - columnsWithFixedWidth.length) - ); + + const tableClientWidth = tableRef.current.clientWidth; + const defaultColumnsCount = visibleColumns.length - columnsWithFixedWidth.length; + + //check if columns are visible and table has width + if (visibleColumns.length > 0 && tableClientWidth > 0) { + //set fixedWidth as defaultWidth if visible columns have fixed value + if (visibleColumns.length === columnsWithFixedWidth.length) { + setColumnWidth(fixedWidth / visibleColumns.length); + return; + } + //spread default columns + if (tableClientWidth >= fixedWidth + defaultColumnsCount * DEFAULT_COLUMN_WIDTH) { + setColumnWidth((tableClientWidth - fixedWidth) / defaultColumnsCount); + } else { + //set defaultWidth for default columns if table is overflowing + setColumnWidth(DEFAULT_COLUMN_WIDTH); + } } else { - setColumnWidth(150); + setColumnWidth(DEFAULT_COLUMN_WIDTH); } - }, [tableRef.current, columns, tableState.hiddenColumns]); + }, [tableRef.current, columns, tableState.hiddenColumns, DEFAULT_COLUMN_WIDTH]); useEffect(() => { updateTableSizes(); @@ -333,7 +345,7 @@ const AnalyticalTable: FC = forwardRef((props: TableProps, ref: Ref<