@@ -28,7 +28,7 @@ import { CompNameContext, EditorContext } from "comps/editorState";
28
28
import { BackgroundColorContext } from "comps/utils/backgroundColorContext" ;
29
29
import { PrimaryColor } from "constants/style" ;
30
30
import { trans } from "i18n" ;
31
- import _ from "lodash" ;
31
+ import _ , { isEqual } from "lodash" ;
32
32
import { darkenColor , isDarkColor , isValidColor , ScrollBar } from "lowcoder-design" ;
33
33
import React , { Children , useCallback , useContext , useEffect , useMemo , useRef , useState } from "react" ;
34
34
import { Resizable } from "react-resizable" ;
@@ -48,6 +48,7 @@ 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
52
52
53
export const EMPTY_ROW_KEY = 'empty_row' ;
53
54
@@ -814,6 +815,7 @@ export const TableCompView = React.memo((props: {
814
815
onRefresh : ( allQueryNames : Array < string > , setLoading : ( loading : boolean ) => void ) => void ;
815
816
onDownload : ( fileName : string ) => void ;
816
817
} ) => {
818
+ const [ expandedRowKeys , setExpandedRowKeys ] = useState < string [ ] > ( [ ] ) ;
817
819
const [ emptyRowsMap , setEmptyRowsMap ] = useState < Record < string , RecordType > > ( { } ) ;
818
820
const editorState = useContext ( EditorContext ) ;
819
821
const currentTheme = useContext ( ThemeContext ) ?. theme ;
@@ -856,6 +858,7 @@ export const TableCompView = React.memo((props: {
856
858
const size = useMemo ( ( ) => compChildren . size . getView ( ) , [ compChildren . size ] ) ;
857
859
const editModeClicks = useMemo ( ( ) => compChildren . editModeClicks . getView ( ) , [ compChildren . editModeClicks ] ) ;
858
860
const onEvent = useMemo ( ( ) => compChildren . onEvent . getView ( ) , [ compChildren . onEvent ] ) ;
861
+ const currentExpandedRows = useMemo ( ( ) => compChildren . currentExpandedRows . getView ( ) , [ compChildren . currentExpandedRows ] ) ;
859
862
const dynamicColumn = compChildren . dynamicColumn . getView ( ) ;
860
863
const dynamicColumnConfig = useMemo (
861
864
( ) => compChildren . dynamicColumnConfig . getView ( ) ,
@@ -955,6 +958,18 @@ export const TableCompView = React.memo((props: {
955
958
updateEmptyRows ( ) ;
956
959
} , [ updateEmptyRows ] ) ;
957
960
961
+ useUpdateEffect ( ( ) => {
962
+ if ( ! isEqual ( currentExpandedRows , expandedRowKeys ) ) {
963
+ compChildren . currentExpandedRows . dispatchChangeValueAction ( expandedRowKeys ) ;
964
+ }
965
+ } , [ expandedRowKeys ] ) ;
966
+
967
+ useUpdateEffect ( ( ) => {
968
+ if ( ! isEqual ( currentExpandedRows , expandedRowKeys ) ) {
969
+ setExpandedRowKeys ( currentExpandedRows ) ;
970
+ }
971
+ } , [ currentExpandedRows ] ) ;
972
+
958
973
const pageDataInfo = useMemo ( ( ) => {
959
974
// Data pagination
960
975
let pagedData = data ;
@@ -1104,7 +1119,11 @@ export const TableCompView = React.memo((props: {
1104
1119
} else {
1105
1120
handleChangeEvent ( 'rowShrink' )
1106
1121
}
1107
- }
1122
+ } ,
1123
+ onExpandedRowsChange : ( expandedRowKeys ) => {
1124
+ setExpandedRowKeys ( expandedRowKeys as unknown as string [ ] ) ;
1125
+ } ,
1126
+ expandedRowKeys : expandedRowKeys ,
1108
1127
} }
1109
1128
// rowKey={OB_ROW_ORI_INDEX}
1110
1129
rowColorFn = { compChildren . rowColor . getView ( ) as any }
0 commit comments