Skip to content

Commit 9a1295e

Browse files
added currentExpandedRow, currentExpandedRows and setExpandedRows in table comp
1 parent 6cf8dc0 commit 9a1295e

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,24 @@ TableTmpComp = withMethodExposing(TableTmpComp, [
724724
comp.children.columns.dispatchClearInsertSet();
725725
},
726726
},
727+
{
728+
method: {
729+
name: "setExpandedRows",
730+
description: "",
731+
params: [
732+
{ name: "expandedRows", type: "arrayString"},
733+
],
734+
},
735+
execute: (comp, values) => {
736+
const expandedRows = values[0];
737+
if (!isArray(expandedRows)) {
738+
return Promise.reject("setExpandedRows function only accepts array of string i.e. ['1', '2', '3']")
739+
}
740+
if (expandedRows && isArray(expandedRows)) {
741+
comp.children.currentExpandedRows.dispatchChangeValueAction(expandedRows as string[]);
742+
}
743+
},
744+
}
727745
]);
728746

729747
// exposing data
@@ -978,5 +996,24 @@ export const TableComp = withExposingConfigs(TableTmpComp, [
978996
},
979997
trans("table.selectedCellDesc")
980998
),
999+
depsConfig({
1000+
name: "currentExpandedRow",
1001+
desc: trans("table.sortDesc"),
1002+
depKeys: ["currentExpandedRows"],
1003+
func: (input) => {
1004+
if (input.currentExpandedRows.length > 0) {
1005+
return input.currentExpandedRows[input.currentExpandedRows.length - 1];
1006+
}
1007+
return "";
1008+
},
1009+
}),
1010+
depsConfig({
1011+
name: "currentExpandedRows",
1012+
desc: trans("table.sortDesc"),
1013+
depKeys: ["currentExpandedRows"],
1014+
func: (input) => {
1015+
return input.currentExpandedRows;
1016+
},
1017+
}),
9811018
new NameConfig("data", trans("table.dataDesc")),
9821019
]);

client/packages/lowcoder/src/comps/comps/tableComp/tableCompView.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { CompNameContext, EditorContext } from "comps/editorState";
2828
import { BackgroundColorContext } from "comps/utils/backgroundColorContext";
2929
import { PrimaryColor } from "constants/style";
3030
import { trans } from "i18n";
31-
import _ from "lodash";
31+
import _, { isEqual } from "lodash";
3232
import { darkenColor, isDarkColor, isValidColor, ScrollBar } from "lowcoder-design";
3333
import React, { Children, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3434
import { Resizable } from "react-resizable";
@@ -48,6 +48,7 @@ import { TableSummary } from "./tableSummaryComp";
4848
import Skeleton from "antd/es/skeleton";
4949
import { SkeletonButtonProps } from "antd/es/skeleton/Button";
5050
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
51+
import { useUpdateEffect } from "react-use";
5152

5253
export 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}

client/packages/lowcoder/src/comps/comps/tableComp/tableTypes.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ const tableChildrenMap = {
265265
selectedCell: stateComp<JSONObject>({}),
266266
inlineAddNewRow: BoolControl,
267267
editModeClicks: dropdownControl(editModeClickOptions, "single"),
268+
currentExpandedRows: stateComp<string[]>([]),
268269
};
269270

270271
export const TableInitComp = (function () {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy