Skip to content

Commit 0624105

Browse files
added multi-sorting for table columns
1 parent fc9ee24 commit 0624105

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
RecordNode,
4747
RecordNodeToValue,
4848
routeByNameAction,
49+
ValueAndMsg,
4950
withFunction,
5051
wrapChildAction,
5152
} from "lowcoder-core";
@@ -55,7 +56,7 @@ import { lastValueIfEqual, shallowEqual } from "util/objectUtils";
5556
import { IContainer } from "../containerBase";
5657
import { getSelectedRowKeys } from "./selectionControl";
5758
import { compTablePropertyView } from "./tablePropertyView";
58-
import { RowColorComp, RowHeightComp, TableChildrenView, TableInitComp } from "./tableTypes";
59+
import { RowColorComp, RowHeightComp, SortValue, TableChildrenView, TableInitComp } from "./tableTypes";
5960

6061
import { useContext, useState } from "react";
6162
import { EditorContext } from "comps/editorState";
@@ -295,19 +296,37 @@ export class TableImplComp extends TableInitComp implements IContainer {
295296

296297
// handle sort: data -> sortedData
297298
sortDataNode() {
298-
const nodes = {
299+
const nodes: {
300+
data: Node<JSONObject[]>;
301+
sort: Node<SortValue[]>;
302+
dataIndexes: RecordNode<Record<string, Node<string>>>;
303+
sortables: RecordNode<Record<string, Node<ValueAndMsg<boolean>>>>;
304+
withParams: RecordNode<_.Dictionary<any>>,
305+
} = {
299306
data: this.children.data.exposingNode(),
300307
sort: this.children.sort.node(),
301308
dataIndexes: this.children.columns.getColumnsNode("dataIndex"),
302309
sortables: this.children.columns.getColumnsNode("sortable"),
310+
withParams: this.children.columns.withParamsNode(),
303311
};
304312
const sortedDataNode = withFunction(fromRecord(nodes), (input) => {
305313
const { data, sort, dataIndexes, sortables } = input;
306-
const columns = _(dataIndexes)
314+
const sortColumns = _(dataIndexes)
307315
.mapValues((dataIndex, idx) => ({ sortable: !!sortables[idx] }))
308316
.mapKeys((sortable, idx) => dataIndexes[idx])
309317
.value();
310-
const sortedData = sortData(data, columns, sort);
318+
const dataColumns = _(dataIndexes)
319+
.mapValues((dataIndex, idx) => ({
320+
dataIndex,
321+
render: input.withParams[idx] as any,
322+
}))
323+
.value();
324+
const updatedData: Array<RecordType> = data.map((row, index) => ({
325+
...row,
326+
[OB_ROW_ORI_INDEX]: index + "",
327+
}));
328+
const originalData = getOriDisplayData(updatedData, 1000, Object.values(dataColumns))
329+
const sortedData = sortData(originalData, sortColumns, sort);
311330
// console.info( "sortNode. data: ", data, " sort: ", sort, " columns: ", columns, " sortedData: ", sortedData);
312331
return sortedData;
313332
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export function columnsToAntdFormat(
340340
status: StatusType;
341341
}[];
342342
const title = renderTitle({ title: column.title, tooltip: column.titleTooltip, editable: column.editable });
343-
343+
344344
return {
345345
key: `${column.dataIndex}-${mIndex}`,
346346
title: column.showTitle ? title : '',
@@ -399,7 +399,7 @@ export function columnsToAntdFormat(
399399
},
400400
...(column.sortable
401401
? {
402-
sorter: true,
402+
sorter: { multiple: (sortedColumns.length - mIndex) + 1 },
403403
sortOrder: sortMap.get(column.dataIndex),
404404
showSorterTooltip: false,
405405
}

0 commit comments

Comments
 (0)