Skip to content

Commit 5c225cc

Browse files
column data mapping
1 parent 2344a04 commit 5c225cc

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CellProps } from "components/table/EditableCell";
22
import { DateTimeComp } from "comps/comps/tableComp/column/columnTypeComps/columnDateTimeComp";
33
import { ButtonComp } from "comps/comps/tableComp/column/simpleColumnTypeComps";
4-
import { withType } from "comps/generators";
4+
import { MultiCompBuilder, withDefault, withType } from "comps/generators";
55
import { trans } from "i18n";
66
import { Dropdown } from "lowcoder-design";
77
import { BooleanComp } from "./columnTypeComps/columnBooleanComp";
@@ -17,6 +17,31 @@ import { ColumnTagsComp } from "./columnTypeComps/columnTagsComp";
1717
import { ColumnSelectComp } from "./columnTypeComps/columnSelectComp";
1818
import { SimpleTextComp } from "./columnTypeComps/simpleTextComp";
1919
import { ColumnNumberComp } from "./columnTypeComps/ColumnNumberComp";
20+
import { useState } from "react";
21+
import { dropdownControl } from "@lowcoder-ee/index.sdk";
22+
23+
const columnValueOptions = [
24+
{
25+
label: "ID",
26+
value: "{{currentRow.id}}",
27+
},
28+
{
29+
label: "Name",
30+
value: "{{currentRow.name}}",
31+
},
32+
{
33+
label: "Department",
34+
value: "{{currentRow.department}}",
35+
},
36+
{
37+
label: "Date",
38+
value: "{{currentRow.date}}",
39+
},
40+
{
41+
label: "Other",
42+
value: "",
43+
},
44+
] as const;
2045

2146
const actionOptions = [
2247
{
@@ -104,6 +129,15 @@ export type ColumnTypeKeys = keyof ColumnTypeMapType;
104129

105130
const TypedColumnTypeComp = withType(ColumnTypeCompMap, "text");
106131

132+
const childrenMap = {
133+
comp: TypedColumnTypeComp,
134+
valueMap: dropdownControl(columnValueOptions, "")
135+
};
136+
137+
const TmpColumnTypeComp = new MultiCompBuilder(childrenMap, (props) => {
138+
return props;
139+
}).build();
140+
107141
export class ColumnTypeComp extends TypedColumnTypeComp {
108142
override getView() {
109143
const childView = this.children.comp.getView();

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ const columnFixOptions = [
5757
},
5858
] as const;
5959

60+
const columnValueOptions = [
61+
{
62+
label: "ID",
63+
value: "{{currentRow.id}}",
64+
},
65+
{
66+
label: "Name",
67+
value: "{{currentRow.name}}",
68+
},
69+
{
70+
label: "Department",
71+
value: "{{currentRow.department}}",
72+
},
73+
{
74+
label: "Date",
75+
value: "{{currentRow.date}}",
76+
},
77+
{
78+
label: "Other",
79+
value: "",
80+
},
81+
] as const;
82+
6083
const cellColorLabel = trans("table.cellColor");
6184
const CellColorTempComp = withContext(
6285
new MultiCompBuilder({ color: ColorOrBoolCodeControl }, (props) => props.color)
@@ -94,6 +117,7 @@ export const columnChildrenMap = {
94117
sortable: BoolControl,
95118
width: NumberControl,
96119
autoWidth: dropdownControl(columnWidthOptions, "auto"),
120+
columnMapping: dropdownControl(columnValueOptions, ""),
97121
render: RenderComp,
98122
align: HorizontalAlignmentControl,
99123
tempHide: stateComp<boolean>(false),
@@ -195,6 +219,21 @@ export class ColumnComp extends ColumnInitComp {
195219
label: trans("table.columnTitle"),
196220
placeholder: this.children.dataIndex.getView(),
197221
})}
222+
{this.children.columnMapping.propertyView({
223+
label: "Data Mapping",
224+
onChange: (value) => {
225+
console.log(value)
226+
const comp = this.children.render.getSelectedComp().getComp();
227+
// let textRawData = "{{currentCell}}";
228+
// if (comp.children.hasOwnProperty("text")) {
229+
// textRawData = (comp.children as any).text.toJsonValue();
230+
// }
231+
this.children.render.dispatchChangeValueAction({
232+
compType: columnType,
233+
comp: { text: value },
234+
} as any);
235+
}
236+
})}
198237
{/* FIXME: cast type currently, return type of withContext should be corrected later */}
199238
{this.children.render.getPropertyView()}
200239
{this.children.showTitle.propertyView({

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ export function columnsToAntdFormat(
271271
columnsAggrData: ColumnsAggrData,
272272
onTableEvent: (eventName: any) => void,
273273
): Array<CustomColumnType<RecordType>> {
274+
console.log(columnsAggrData);
274275
const sortMap: Map<string | undefined, SortOrder> = new Map(
275276
sort.map((s) => [s.column, s.desc ? "descend" : "ascend"])
276277
);

client/packages/lowcoder/src/comps/controls/dropdownControl.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,16 @@ export function dropdownAbstractControl<T extends OptionsType>(
9292
return controlItem(
9393
{ filterText: params.label },
9494
<DropdownPropertyView<T>
95+
{...params}
9596
value={this.value}
9697
options={finalOptions}
9798
onChange={(value) => {
99+
console.log(value);
98100
if (!params.disableDispatchValueChange) {
99101
this.dispatchChangeValueAction(value);
100102
}
101103
params.onChange?.(value);
102104
}}
103-
{...params}
104105
/>
105106
);
106107
}

0 commit comments

Comments
 (0)