@@ -28,7 +28,7 @@ import { CompNameContext, EditorContext } from "comps/editorState";
2828import { BackgroundColorContext } from "comps/utils/backgroundColorContext" ;
2929import { PrimaryColor } from "constants/style" ;
3030import { trans } from "i18n" ;
31- import _ from "lodash" ;
31+ import _ , { isEqual } from "lodash" ;
3232import { darkenColor , isDarkColor , isValidColor , ScrollBar } from "lowcoder-design" ;
3333import React , { Children , useCallback , useContext , useEffect , useMemo , useRef , useState } from "react" ;
3434import { Resizable } from "react-resizable" ;
@@ -48,6 +48,7 @@ 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" ;
5152
5253export const EMPTY_ROW_KEY = 'empty_row' ;
5354
@@ -814,6 +815,7 @@ export const TableCompView = React.memo((props: {
814815 onRefresh : ( allQueryNames : Array < string > , setLoading : ( loading : boolean ) => void ) => void ;
815816 onDownload : ( fileName : string ) => void ;
816817} ) => {
818+ const [ expandedRowKeys , setExpandedRowKeys ] = useState < string [ ] > ( [ ] ) ;
817819 const [ emptyRowsMap , setEmptyRowsMap ] = useState < Record < string , RecordType > > ( { } ) ;
818820 const editorState = useContext ( EditorContext ) ;
819821 const currentTheme = useContext ( ThemeContext ) ?. theme ;
@@ -856,6 +858,7 @@ export const TableCompView = React.memo((props: {
856858 const size = useMemo ( ( ) => compChildren . size . getView ( ) , [ compChildren . size ] ) ;
857859 const editModeClicks = useMemo ( ( ) => compChildren . editModeClicks . getView ( ) , [ compChildren . editModeClicks ] ) ;
858860 const onEvent = useMemo ( ( ) => compChildren . onEvent . getView ( ) , [ compChildren . onEvent ] ) ;
861+ const currentExpandedRows = useMemo ( ( ) => compChildren . currentExpandedRows . getView ( ) , [ compChildren . currentExpandedRows ] ) ;
859862 const dynamicColumn = compChildren . dynamicColumn . getView ( ) ;
860863 const dynamicColumnConfig = useMemo (
861864 ( ) => compChildren . dynamicColumnConfig . getView ( ) ,
@@ -955,6 +958,18 @@ export const TableCompView = React.memo((props: {
955958 updateEmptyRows ( ) ;
956959 } , [ updateEmptyRows ] ) ;
957960
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+
958973 const pageDataInfo = useMemo ( ( ) => {
959974 // Data pagination
960975 let pagedData = data ;
@@ -1104,7 +1119,11 @@ export const TableCompView = React.memo((props: {
11041119 } else {
11051120 handleChangeEvent ( 'rowShrink' )
11061121 }
1107- }
1122+ } ,
1123+ onExpandedRowsChange : ( expandedRowKeys ) => {
1124+ setExpandedRowKeys ( expandedRowKeys as unknown as string [ ] ) ;
1125+ } ,
1126+ expandedRowKeys : expandedRowKeys ,
11081127 } }
11091128 // rowKey={OB_ROW_ORI_INDEX}
11101129 rowColorFn = { compChildren . rowColor . getView ( ) as any }
0 commit comments