1- import { Device } from '@ui5/webcomponents-react-base/lib/Device' ;
21import { Event } from '@ui5/webcomponents-react-base/lib/Event' ;
32import { StyleClassHelper } from '@ui5/webcomponents-react-base/lib/StyleClassHelper' ;
43import { usePassThroughHtmlProps } from '@ui5/webcomponents-react-base/lib/usePassThroughHtmlProps' ;
@@ -16,8 +15,7 @@ import React, {
1615 useCallback ,
1716 useEffect ,
1817 useMemo ,
19- useRef ,
20- useState
18+ useRef
2119} from 'react' ;
2220import { createUseStyles } from 'react-jss' ;
2321import {
@@ -37,7 +35,7 @@ import { CommonProps } from '../../interfaces/CommonProps';
3735import { JSSTheme } from '../../interfaces/JSSTheme' ;
3836import styles from './AnayticalTable.jss' ;
3937import { ColumnHeader } from './ColumnHeader' ;
40- import { DEFAULT_COLUMN_WIDTH , DefaultColumn } from './defaults/Column' ;
38+ import { DefaultColumn } from './defaults/Column' ;
4139import { DefaultLoadingComponent } from './defaults/LoadingComponent' ;
4240import { TablePlaceholder } from './defaults/LoadingComponent/TablePlaceholder' ;
4341import { DefaultNoDataComponent } from './defaults/NoDataComponent' ;
@@ -52,6 +50,9 @@ import { useToggleRowExpand } from './hooks/useToggleRowExpand';
5250import { stateReducer } from './tableReducer/stateReducer' ;
5351import { TitleBar } from './TitleBar' ;
5452import { VirtualTableBody } from './virtualization/VirtualTableBody' ;
53+ import { useDynamicColumnWidths } from './hooks/useDynamicColumnWidths' ;
54+ import { TableScaleWidthMode } from '../../enums/TableScaleWidthMode' ;
55+ import { useColumnsDependencies } from "./hooks/useColumnsDependencies" ;
5556
5657export interface ColumnConfiguration extends Column {
5758 accessor ?: string ;
@@ -100,6 +101,7 @@ export interface TableProps extends CommonProps {
100101 groupable ?: boolean ;
101102 groupBy ?: string [ ] ;
102103 selectionMode ?: TableSelectionMode ;
104+ scaleWidthMode ?: TableScaleWidthMode ;
103105 columnOrder ?: object [ ] ;
104106
105107 // events
@@ -157,7 +159,8 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
157159 minRows,
158160 isTreeTable,
159161 alternateRowColor,
160- overscanCount
162+ overscanCount,
163+ scaleWidthMode
161164 } = props ;
162165
163166 const classes = useStyles ( { rowHeight : props . rowHeight } ) ;
@@ -167,18 +170,6 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
167170
168171 const getSubRows = useCallback ( ( row ) => row [ subRowsKey ] || [ ] , [ subRowsKey ] ) ;
169172
170- const [ columnWidth , setColumnWidth ] = useState ( null ) ;
171-
172- const defaultColumn = useMemo ( ( ) => {
173- if ( columnWidth ) {
174- return {
175- width : columnWidth ,
176- ...DefaultColumn
177- } ;
178- }
179- return DefaultColumn ;
180- } , [ columnWidth ] ) ;
181-
182173 const data = useMemo ( ( ) => {
183174 if ( minRows > props . data . length ) {
184175 const missingRows = minRows - props . data . length ;
@@ -190,6 +181,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
190181 return props . data ;
191182 } , [ props . data , minRows ] ) ;
192183
184+
193185 const {
194186 getTableProps,
195187 headerGroups,
@@ -204,15 +196,17 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
204196 {
205197 columns,
206198 data,
207- defaultColumn,
199+ defaultColumn : DefaultColumn ,
208200 getSubRows,
209201 stateReducer,
210202 webComponentsReactProperties : {
211203 selectionMode,
212204 classes,
213205 onRowSelected,
214206 onRowExpandChange,
215- isTreeTable
207+ isTreeTable,
208+ // tableClientWidth,
209+ scaleWidthMode
216210 } ,
217211 ...reactTableOptions
218212 } ,
@@ -228,45 +222,30 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
228222 useTableHeaderGroupStyling ,
229223 useTableHeaderStyling ,
230224 useTableRowStyling ,
225+ useDynamicColumnWidths ,
226+ useColumnsDependencies ,
231227 useTableCellStyling ,
232228 useToggleRowExpand ,
233229 ...tableHooks
234230 ) ;
235231
236- const updateTableSizes = useCallback ( ( ) => {
237- const visibleColumns = columns . filter ( Boolean ) . filter ( ( item ) => {
238- return ( item . isVisible ?? true ) && ! tableState . hiddenColumns . includes ( item . accessor ) ;
239- } ) ;
240- const columnsWithFixedWidth = visibleColumns . filter ( ( { width } ) => width ?? false ) . map ( ( { width } ) => width ) ;
241- const fixedWidth = columnsWithFixedWidth . reduce ( ( acc , val ) => acc + val , 0 ) ;
242-
243- const tableClientWidth = tableRef . current . clientWidth ;
244- const defaultColumnsCount = visibleColumns . length - columnsWithFixedWidth . length ;
245-
246- //check if columns are visible and table has width
247- if ( visibleColumns . length > 0 && tableClientWidth > 0 ) {
248- //set fixedWidth as defaultWidth if visible columns have fixed value
249- if ( visibleColumns . length === columnsWithFixedWidth . length ) {
250- setColumnWidth ( fixedWidth / visibleColumns . length ) ;
251- return ;
232+ const updateTableClientWidth = useCallback ( ( ) => {
233+ requestAnimationFrame ( ( ) => {
234+ if ( tableRef . current ) {
235+ dispatch ( { type : 'TABLE_RESIZE' , payload : { tableClientWidth : tableRef . current . clientWidth } } ) ;
252236 }
253- //spread default columns
254- if ( tableClientWidth >= fixedWidth + defaultColumnsCount * DEFAULT_COLUMN_WIDTH ) {
255- setColumnWidth ( ( tableClientWidth - fixedWidth ) / defaultColumnsCount ) ;
256- } else {
257- //set defaultWidth for default columns if table is overflowing
258- setColumnWidth ( DEFAULT_COLUMN_WIDTH ) ;
259- }
260- } else {
261- setColumnWidth ( DEFAULT_COLUMN_WIDTH ) ;
262- }
263- } , [ tableRef . current , columns , tableState . hiddenColumns , DEFAULT_COLUMN_WIDTH ] ) ;
237+ } ) ;
238+ } , [ ] ) ;
239+
240+ // @ts -ignore
241+ const tableWidthObserver = useRef ( new ResizeObserver ( updateTableClientWidth ) ) ;
264242
265243 useEffect ( ( ) => {
266- updateTableSizes ( ) ;
267- Device . resize . attachHandler ( updateTableSizes , null ) ;
268- return ( ) => Device . resize . detachHandler ( updateTableSizes , null ) ;
269- } , [ updateTableSizes ] ) ;
244+ tableWidthObserver . current . observe ( tableRef . current ) ;
245+ return ( ) => {
246+ tableWidthObserver . current . disconnect ( ) ;
247+ } ;
248+ } , [ tableWidthObserver . current , tableRef . current ] ) ;
270249
271250 useEffect ( ( ) => {
272251 dispatch ( { type : 'SET_GROUP_BY' , payload : groupBy } ) ;
@@ -347,7 +326,7 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
347326 { title && < TitleBar > { title } </ TitleBar > }
348327 { typeof renderExtension === 'function' && < div > { renderExtension ( ) } </ div > }
349328 < div className = { tableContainerClasses . valueOf ( ) } ref = { tableRef } >
350- { columnWidth && (
329+ { (
351330 < div { ...getTableProps ( ) } role = "table" aria-rowcount = { rows . length } >
352331 { headerGroups . map ( ( headerGroup ) => {
353332 let headerProps = { } ;
@@ -430,6 +409,7 @@ AnalyticalTable.defaultProps = {
430409 filterable : false ,
431410 groupable : false ,
432411 selectionMode : TableSelectionMode . NONE ,
412+ scaleWidthMode : TableScaleWidthMode . Default ,
433413 data : [ ] ,
434414 columns : [ ] ,
435415 title : null ,
0 commit comments