@@ -48,10 +48,17 @@ import { TableSummary } from "./tableSummaryComp";
4848import Skeleton from "antd/es/skeleton" ;
4949import { SkeletonButtonProps } from "antd/es/skeleton/Button" ;
5050import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext" ;
51- import { useUpdateEffect } from "react-use" ;
51+ import { useUpdateEffect } from "react-use" ; import {
52+ useTableMode ,
53+ useContainerHeight ,
54+ useVirtualization ,
55+ useScrollConfiguration
56+ } from './hooks/useTableConfiguration' ;
5257
5358export const EMPTY_ROW_KEY = 'empty_row' ;
5459
60+
61+
5562function genLinerGradient ( color : string ) {
5663 return isValidColor ( color ) ? `linear-gradient(${ color } , ${ color } )` : color ;
5764}
@@ -565,6 +572,11 @@ type CustomTableProps<RecordType> = Omit<TableProps<RecordType>, "components" |
565572 rowAutoHeight ?: boolean ;
566573 customLoading ?: boolean ;
567574 onCellClick : ( columnName : string , dataIndex : string ) => void ;
575+ virtual ?: boolean ;
576+ scroll ?: {
577+ x ?: number | string ;
578+ y ?: number | string ;
579+ } ;
568580} ;
569581
570582const TableCellView = React . memo ( ( props : {
@@ -798,9 +810,6 @@ function ResizeableTableComp<RecordType extends object>(props: CustomTableProps<
798810 { ...restProps }
799811 pagination = { false }
800812 columns = { memoizedColumns }
801- scroll = { {
802- x : COL_MIN_WIDTH * columns . length ,
803- } }
804813 />
805814 ) ;
806815}
@@ -848,7 +857,6 @@ export const TableCompView = React.memo((props: {
848857 const toolbarStyle = compChildren . toolbarStyle . getView ( ) ;
849858 const hideToolbar = compChildren . hideToolbar . getView ( )
850859 const rowAutoHeight = compChildren . rowAutoHeight . getView ( ) ;
851- const tableAutoHeight = comp . getTableAutoHeight ( ) ;
852860 const showHorizontalScrollbar = compChildren . showHorizontalScrollbar . getView ( ) ;
853861 const showVerticalScrollbar = compChildren . showVerticalScrollbar . getView ( ) ;
854862 const visibleResizables = compChildren . visibleResizables . getView ( ) ;
@@ -872,6 +880,7 @@ export const TableCompView = React.memo((props: {
872880 const onEvent = useMemo ( ( ) => compChildren . onEvent . getView ( ) , [ compChildren . onEvent ] ) ;
873881 const currentExpandedRows = useMemo ( ( ) => compChildren . currentExpandedRows . getView ( ) , [ compChildren . currentExpandedRows ] ) ;
874882 const dynamicColumn = compChildren . dynamicColumn . getView ( ) ;
883+
875884 const dynamicColumnConfig = useMemo (
876885 ( ) => compChildren . dynamicColumnConfig . getView ( ) ,
877886 [ compChildren . dynamicColumnConfig ]
@@ -1006,6 +1015,31 @@ export const TableCompView = React.memo((props: {
10061015
10071016 const childrenProps = childrenToProps ( comp . children ) ;
10081017
1018+ // Table mode and height configuration
1019+ const tableMode = useTableMode ( comp . getTableAutoHeight ( ) ) ;
1020+ const { containerHeight, containerRef } = useContainerHeight ( tableMode . isFixedMode ) ;
1021+
1022+ const virtualizationConfig = useVirtualization (
1023+ containerHeight ,
1024+ pageDataInfo . data . length ,
1025+ size as 'small' | 'middle' | 'large' ,
1026+ {
1027+ showToolbar : ! hideToolbar ,
1028+ showHeader : ! compChildren . hideHeader . getView ( ) ,
1029+ stickyToolbar : toolbar . fixedToolbar && toolbar . position === 'above' ,
1030+ isFixedMode : tableMode . isFixedMode
1031+ }
1032+ ) ;
1033+ const totalColumnsWidth = COL_MIN_WIDTH * antdColumns . length ;
1034+ const scrollConfig = useScrollConfiguration (
1035+ virtualizationConfig . enabled ,
1036+ virtualizationConfig . scrollY ,
1037+ totalColumnsWidth
1038+ ) ;
1039+
1040+
1041+
1042+
10091043 useMergeCompStyles (
10101044 childrenProps as Record < string , any > ,
10111045 comp . dispatch
@@ -1092,20 +1126,20 @@ export const TableCompView = React.memo((props: {
10921126 return (
10931127 < BackgroundColorContext . Provider value = { style . background } >
10941128 < BackgroundWrapper
1095- ref = { ref }
1129+ ref = { containerRef }
10961130 $style = { style }
1097- $tableAutoHeight = { tableAutoHeight }
1131+ $tableAutoHeight = { tableMode . isAutoMode }
10981132 $showHorizontalScrollbar = { showHorizontalScrollbar }
10991133 $showVerticalScrollbar = { showVerticalScrollbar }
11001134 $fixedToolbar = { toolbar . fixedToolbar }
11011135 >
1102- { toolbar . position === "above" && ! hideToolbar && ( toolbar . fixedToolbar || ( tableAutoHeight && showHorizontalScrollbar ) ) && toolbarView }
1136+ { toolbar . position === "above" && ! hideToolbar && ( toolbar . fixedToolbar || ( tableMode . isAutoMode && showHorizontalScrollbar ) ) && toolbarView }
11031137 < ScrollBar
11041138 className = "table-scrollbar-wrapper"
11051139 style = { { height : "100%" , margin : "0px" , padding : "0px" } }
11061140 hideScrollbar = { hideScrollbar }
1107- prefixNode = { toolbar . position === "above" && ! toolbar . fixedToolbar && ! ( tableAutoHeight && showHorizontalScrollbar ) && toolbarView }
1108- suffixNode = { toolbar . position === "below" && ! toolbar . fixedToolbar && ! ( tableAutoHeight && showHorizontalScrollbar ) && toolbarView }
1141+ prefixNode = { toolbar . position === "above" && ! toolbar . fixedToolbar && ! ( tableMode . isAutoMode && showHorizontalScrollbar ) && toolbarView }
1142+ suffixNode = { toolbar . position === "below" && ! toolbar . fixedToolbar && ! ( tableMode . isAutoMode && showHorizontalScrollbar ) && toolbarView }
11091143 >
11101144 < TableWrapper
11111145 $style = { style }
@@ -1162,13 +1196,15 @@ export const TableCompView = React.memo((props: {
11621196 } ) ;
11631197 } }
11641198 summary = { summaryView }
1199+ scroll = { scrollConfig . scroll }
1200+ virtual = { scrollConfig . virtual }
11651201 />
11661202 < SlotConfigContext . Provider value = { { modalWidth : width && Math . max ( width , 300 ) } } >
11671203 { expansion . expandModalView }
11681204 </ SlotConfigContext . Provider >
11691205 </ TableWrapper >
11701206 </ ScrollBar >
1171- { toolbar . position === "below" && ! hideToolbar && ( toolbar . fixedToolbar || ( tableAutoHeight && showHorizontalScrollbar ) ) && toolbarView }
1207+ { toolbar . position === "below" && ! hideToolbar && ( toolbar . fixedToolbar || ( tableMode . isAutoMode && showHorizontalScrollbar ) ) && toolbarView }
11721208 </ BackgroundWrapper >
11731209
11741210 </ BackgroundColorContext . Provider >
0 commit comments