@@ -48,10 +48,17 @@ import { TableSummary } from "./tableSummaryComp";
48
48
import Skeleton from "antd/es/skeleton" ;
49
49
import { SkeletonButtonProps } from "antd/es/skeleton/Button" ;
50
50
import { 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' ;
52
57
53
58
export const EMPTY_ROW_KEY = 'empty_row' ;
54
59
60
+
61
+
55
62
function genLinerGradient ( color : string ) {
56
63
return isValidColor ( color ) ? `linear-gradient(${ color } , ${ color } )` : color ;
57
64
}
@@ -565,6 +572,11 @@ type CustomTableProps<RecordType> = Omit<TableProps<RecordType>, "components" |
565
572
rowAutoHeight ?: boolean ;
566
573
customLoading ?: boolean ;
567
574
onCellClick : ( columnName : string , dataIndex : string ) => void ;
575
+ virtual ?: boolean ;
576
+ scroll ?: {
577
+ x ?: number | string ;
578
+ y ?: number | string ;
579
+ } ;
568
580
} ;
569
581
570
582
const TableCellView = React . memo ( ( props : {
@@ -798,9 +810,6 @@ function ResizeableTableComp<RecordType extends object>(props: CustomTableProps<
798
810
{ ...restProps }
799
811
pagination = { false }
800
812
columns = { memoizedColumns }
801
- scroll = { {
802
- x : COL_MIN_WIDTH * columns . length ,
803
- } }
804
813
/>
805
814
) ;
806
815
}
@@ -848,7 +857,6 @@ export const TableCompView = React.memo((props: {
848
857
const toolbarStyle = compChildren . toolbarStyle . getView ( ) ;
849
858
const hideToolbar = compChildren . hideToolbar . getView ( )
850
859
const rowAutoHeight = compChildren . rowAutoHeight . getView ( ) ;
851
- const tableAutoHeight = comp . getTableAutoHeight ( ) ;
852
860
const showHorizontalScrollbar = compChildren . showHorizontalScrollbar . getView ( ) ;
853
861
const showVerticalScrollbar = compChildren . showVerticalScrollbar . getView ( ) ;
854
862
const visibleResizables = compChildren . visibleResizables . getView ( ) ;
@@ -872,6 +880,7 @@ export const TableCompView = React.memo((props: {
872
880
const onEvent = useMemo ( ( ) => compChildren . onEvent . getView ( ) , [ compChildren . onEvent ] ) ;
873
881
const currentExpandedRows = useMemo ( ( ) => compChildren . currentExpandedRows . getView ( ) , [ compChildren . currentExpandedRows ] ) ;
874
882
const dynamicColumn = compChildren . dynamicColumn . getView ( ) ;
883
+
875
884
const dynamicColumnConfig = useMemo (
876
885
( ) => compChildren . dynamicColumnConfig . getView ( ) ,
877
886
[ compChildren . dynamicColumnConfig ]
@@ -1006,6 +1015,31 @@ export const TableCompView = React.memo((props: {
1006
1015
1007
1016
const childrenProps = childrenToProps ( comp . children ) ;
1008
1017
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
+
1009
1043
useMergeCompStyles (
1010
1044
childrenProps as Record < string , any > ,
1011
1045
comp . dispatch
@@ -1092,20 +1126,20 @@ export const TableCompView = React.memo((props: {
1092
1126
return (
1093
1127
< BackgroundColorContext . Provider value = { style . background } >
1094
1128
< BackgroundWrapper
1095
- ref = { ref }
1129
+ ref = { containerRef }
1096
1130
$style = { style }
1097
- $tableAutoHeight = { tableAutoHeight }
1131
+ $tableAutoHeight = { tableMode . isAutoMode }
1098
1132
$showHorizontalScrollbar = { showHorizontalScrollbar }
1099
1133
$showVerticalScrollbar = { showVerticalScrollbar }
1100
1134
$fixedToolbar = { toolbar . fixedToolbar }
1101
1135
>
1102
- { toolbar . position === "above" && ! hideToolbar && ( toolbar . fixedToolbar || ( tableAutoHeight && showHorizontalScrollbar ) ) && toolbarView }
1136
+ { toolbar . position === "above" && ! hideToolbar && ( toolbar . fixedToolbar || ( tableMode . isAutoMode && showHorizontalScrollbar ) ) && toolbarView }
1103
1137
< ScrollBar
1104
1138
className = "table-scrollbar-wrapper"
1105
1139
style = { { height : "100%" , margin : "0px" , padding : "0px" } }
1106
1140
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 }
1109
1143
>
1110
1144
< TableWrapper
1111
1145
$style = { style }
@@ -1162,13 +1196,15 @@ export const TableCompView = React.memo((props: {
1162
1196
} ) ;
1163
1197
} }
1164
1198
summary = { summaryView }
1199
+ scroll = { scrollConfig . scroll }
1200
+ virtual = { scrollConfig . virtual }
1165
1201
/>
1166
1202
< SlotConfigContext . Provider value = { { modalWidth : width && Math . max ( width , 300 ) } } >
1167
1203
{ expansion . expandModalView }
1168
1204
</ SlotConfigContext . Provider >
1169
1205
</ TableWrapper >
1170
1206
</ ScrollBar >
1171
- { toolbar . position === "below" && ! hideToolbar && ( toolbar . fixedToolbar || ( tableAutoHeight && showHorizontalScrollbar ) ) && toolbarView }
1207
+ { toolbar . position === "below" && ! hideToolbar && ( toolbar . fixedToolbar || ( tableMode . isAutoMode && showHorizontalScrollbar ) ) && toolbarView }
1172
1208
</ BackgroundWrapper >
1173
1209
1174
1210
</ BackgroundColorContext . Provider >
0 commit comments