Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae4a1a2

Browse files
Merge pull request #2040 from iamfaran/feat/1979-table-columns
[Feat]: #1979 expose hide/showcolumns methods
2 parents 62e1afa + adccc16 commit ae4a1a2

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,55 @@ TableTmpComp = withMethodExposing(TableTmpComp, [
822822
}
823823
},
824824
}
825+
,
826+
{
827+
method: {
828+
name: "hideColumns",
829+
description: "Hide specified columns by dataIndex or title",
830+
params: [
831+
{ name: "columns", type: "arrayString" },
832+
],
833+
},
834+
execute: (comp, values) => {
835+
const columns = values[0];
836+
if (!isArray(columns)) {
837+
return Promise.reject("hideColumns expects an array of strings, e.g. ['id','name']");
838+
}
839+
const targets = new Set((columns as any[]).map((c) => String(c)));
840+
comp.children.columns.getView().forEach((c) => {
841+
const view = c.getView();
842+
if (targets.has(view.dataIndex) || targets.has(view.title)) {
843+
// Ensure both persistent and temporary flags are updated
844+
c.children.hide.dispatchChangeValueAction(true);
845+
c.children.tempHide.dispatchChangeValueAction(true);
846+
}
847+
});
848+
},
849+
}
850+
,
851+
{
852+
method: {
853+
name: "showColumns",
854+
description: "Show specified columns by dataIndex or title",
855+
params: [
856+
{ name: "columns", type: "arrayString" },
857+
],
858+
},
859+
execute: (comp, values) => {
860+
const columns = values[0];
861+
if (!isArray(columns)) {
862+
return Promise.reject("showColumns expects an array of strings, e.g. ['id','name']");
863+
}
864+
const targets = new Set((columns as any[]).map((c) => String(c)));
865+
comp.children.columns.getView().forEach((c) => {
866+
const view = c.getView();
867+
if (targets.has(view.dataIndex) || targets.has(view.title)) {
868+
c.children.hide.dispatchChangeValueAction(false);
869+
c.children.tempHide.dispatchChangeValueAction(false);
870+
}
871+
});
872+
},
873+
}
825874
]);
826875

827876
// exposing data
@@ -1052,6 +1101,30 @@ export const TableComp = withExposingConfigs(TableTmpComp, [
10521101
},
10531102
trans("table.displayDataDesc")
10541103
),
1104+
new CompDepsConfig(
1105+
"hiddenColumns",
1106+
(comp) => {
1107+
return {
1108+
dataIndexes: comp.children.columns.getColumnsNode("dataIndex"),
1109+
hides: comp.children.columns.getColumnsNode("hide"),
1110+
tempHides: comp.children.columns.getColumnsNode("tempHide"),
1111+
columnSetting: comp.children.toolbar.children.columnSetting.node(),
1112+
};
1113+
},
1114+
(input) => {
1115+
const hidden: string[] = [];
1116+
_.forEach(input.dataIndexes, (dataIndex, idx) => {
1117+
const isHidden = columnHide({
1118+
hide: input.hides[idx].value,
1119+
tempHide: input.tempHides[idx],
1120+
enableColumnSetting: input.columnSetting.value,
1121+
});
1122+
if (isHidden) hidden.push(dataIndex);
1123+
});
1124+
return hidden;
1125+
},
1126+
trans("table.displayDataDesc")
1127+
),
10551128
new DepsConfig(
10561129
"filter",
10571130
(children) => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /