Skip to content

Commit 05eacdc

Browse files
table events added for columnEdited and search
1 parent 342c9da commit 05eacdc

File tree

10 files changed

+30
-5
lines changed

10 files changed

+30
-5
lines changed

client/packages/lowcoder/src/components/table/EditableCell.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface CellProps {
3535
candidateTags?: string[];
3636
candidateStatus?: { text: string; status: StatusType }[];
3737
textOverflow?: boolean;
38+
onTableEvent?: (eventName: any) => void;
3839
}
3940

4041
export type CellViewReturn = (props: CellProps) => ReactNode;
@@ -71,6 +72,7 @@ export function EditableCell<T extends JSONValue>(props: EditableCellProps<T>) {
7172
baseValue,
7273
candidateTags,
7374
candidateStatus,
75+
onTableEvent,
7476
} = props;
7577
const status = _.isNil(changeValue) ? "normal" : "toSave";
7678
const editable = editViewFn ? props.editable : false;
@@ -96,6 +98,9 @@ export function EditableCell<T extends JSONValue>(props: EditableCellProps<T>) {
9698
false
9799
)
98100
);
101+
if(!_.isEqual(tmpValue, value)) {
102+
onTableEvent?.('columnEdited');
103+
}
99104
}, [dispatch, baseValue, tmpValue]);
100105
const editView = useMemo(
101106
() => editViewFn?.({ value, onChange, onChangeEnd }) ?? <></>,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ export function newPrimaryColumn(
323323
title?: string,
324324
isTag?: boolean
325325
): ConstructorToDataType<typeof ColumnComp> {
326-
console.log('newPrimaryColumn', title);
327326
return {
328327
title: title ?? key,
329328
dataIndex: key,

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ export class TableImplComp extends TableInitComp implements IContainer {
176176

177177
override reduce(action: CompAction): this {
178178
let comp = super.reduce(action);
179-
180179
let dataChanged = false;
181180
if (action.type === CompActionTypes.UPDATE_NODES_V2) {
182181
const nextRowExample = tableDataRowExample(comp.children.data.getView());
@@ -316,10 +315,18 @@ export class TableImplComp extends TableInitComp implements IContainer {
316315
filter: this.children.toolbar.children.filter.node(),
317316
showFilter: this.children.toolbar.children.showFilter.node(),
318317
};
318+
let context = this;
319319
const filteredDataNode = withFunction(fromRecord(nodes), (input) => {
320320
const { data, searchValue, filter, showFilter } = input;
321321
const filteredData = filterData(data, searchValue.value, filter, showFilter.value);
322322
// console.info("filterNode. data: ", data, " filter: ", filter, " filteredData: ", filteredData);
323+
// if data is changed on search then trigger event
324+
if(Boolean(searchValue.value) && data.length !== filteredData.length) {
325+
const onEvent = context.children.onEvent.getView();
326+
setTimeout(() => {
327+
onEvent("dataSearch");
328+
});
329+
}
323330
return filteredData.map((row) => tranToTableRecord(row, row[OB_ROW_ORI_INDEX]));
324331
});
325332
return lastValueIfEqual(this, "filteredDataNode", [filteredDataNode, nodes] as const, (a, b) =>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ export function TableCompView(props: {
680680
dynamicColumn,
681681
dynamicColumnConfig,
682682
columnsAggrData,
683+
onEvent,
683684
),
684685
[
685686
columnViews,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ const expectColumn = (
3636
// with dynamic config
3737
const dynamicColumnConfig = comp.children.dynamicColumnConfig.getView();
3838
if (dynamicColumnConfig?.length > 0) {
39+
const onEvent = (eventName: any) => {};
3940
const antdColumns = columnsToAntdFormat(
4041
columnViews,
4142
comp.children.sort.getView(),
4243
comp.children.toolbar.getView().columnSetting,
4344
comp.children.size.getView(),
4445
comp.children.dynamicColumn.getView(),
4546
dynamicColumnConfig,
46-
comp.columnAggrData
47+
comp.columnAggrData,
48+
onEvent,
4749
);
4850
expect(columnViews.length).toBeGreaterThanOrEqual(antdColumns.length);
4951
antdColumns.forEach((column) => {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ export const TableEventOptions = [
8383
value: "rowShrink",
8484
description: trans("table.rowShrink"),
8585
},
86+
{
87+
label: trans("table.columnEdited"),
88+
value: "columnEdited",
89+
description: trans("table.columnEdited"),
90+
},
8691
{
8792
label: trans("table.search"),
88-
value: "search",
93+
value: "dataSearch",
8994
description: trans("table.search"),
9095
},
9196
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export function columnsToAntdFormat(
269269
dynamicColumn: boolean,
270270
dynamicColumnConfig: Array<string>,
271271
columnsAggrData: ColumnsAggrData,
272+
onTableEvent: (eventName: any) => void,
272273
): Array<CustomColumnType<RecordType>> {
273274
const sortMap: Map<string | undefined, SortOrder> = new Map(
274275
sort.map((s) => [s.column, s.desc ? "descend" : "ascend"])
@@ -346,9 +347,11 @@ export function columnsToAntdFormat(
346347
.getView()
347348
.view({
348349
editable: column.editable,
349-
size, candidateTags: tags,
350+
size,
351+
candidateTags: tags,
350352
candidateStatus: status,
351353
textOverflow: column.textOverflow,
354+
onTableEvent,
352355
});
353356
},
354357
...(column.sortable

client/packages/lowcoder/src/i18n/locales/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ export const de = {
11941194
"rowShrink": "Zeilenverkleinerung",
11951195
"search": "Suchen",
11961196
"download": "Herunterladen",
1197+
"columnEdited": "Spalte bearbeitet",
11971198
"filterChange": "Filterwechsel",
11981199
"sortChange": "Sortieren Ändern",
11991200
"pageChange": "Seitenwechsel",

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,7 @@ export const en = {
12991299
"rowShrink": "Row Shrink",
13001300
"search": "Search",
13011301
"download": "Download",
1302+
"columnEdited": "Column Edited",
13021303
"filterChange": "Filter Change",
13031304
"sortChange": "Sort Change",
13041305
"pageChange": "Page Change",

client/packages/lowcoder/src/i18n/locales/zh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ table: {
12701270
rowShrink: "行收缩",
12711271
search: "搜索",
12721272
download: "下载",
1273+
columnEdited: "栏目已编辑",
12731274
filterChange: "筛选变化",
12741275
sortChange: "排序变化",
12751276
pageChange: "分页变化",

0 commit comments

Comments
 (0)