es-grid-template 1.7.40 → 1.7.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/grid-component/hooks/utils.d.ts +1 -0
- package/es/grid-component/hooks/utils.js +11 -0
- package/es/table-component/InternalTable.js +29 -11
- package/es/table-component/hook/utils.d.ts +5 -1
- package/es/table-component/hook/utils.js +84 -5
- package/es/table-component/table/Grid.d.ts +1 -0
- package/es/table-component/table/Grid.js +10 -1
- package/lib/grid-component/hooks/utils.d.ts +1 -0
- package/lib/grid-component/hooks/utils.js +14 -2
- package/lib/table-component/InternalTable.js +26 -8
- package/lib/table-component/hook/utils.d.ts +5 -1
- package/lib/table-component/hook/utils.js +90 -6
- package/lib/table-component/table/Grid.d.ts +1 -0
- package/lib/table-component/table/Grid.js +9 -0
- package/package.json +1 -1
|
@@ -57,6 +57,7 @@ export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], ro
|
|
|
57
57
|
export declare const parseBooleanToValue: (value: boolean, type: 'boolean' | 'number') => number | boolean;
|
|
58
58
|
export declare const genPresets: (presets?: import("@ant-design/colors").PalettesProps) => import("antd/es/color-picker/interface").PresetsItem[];
|
|
59
59
|
export declare function findAllChildrenKeys<RecordType>(data: readonly RecordType[], getRowKey: GetRowKey<RecordType>, childrenColumnName: string): Key[];
|
|
60
|
+
export declare function findAllChildrenKeys2<RecordType>(data: readonly RecordType[], rowKey: any, childrenColumnName: string): Key[];
|
|
60
61
|
export declare const flattenArray: <RecordType extends AnyObject = AnyObject>(arr: any[]) => RecordType[];
|
|
61
62
|
export declare const flattenData: <RecordType extends AnyObject = AnyObject>(childrenColumnName: string, data?: RecordType[]) => RecordType[];
|
|
62
63
|
export declare const unFlattenData: <RecordType extends AnyObject = AnyObject>(data: RecordType[]) => RecordType[];
|
|
@@ -447,6 +447,17 @@ export function findAllChildrenKeys(data, getRowKey, childrenColumnName) {
|
|
|
447
447
|
dig(data);
|
|
448
448
|
return keys;
|
|
449
449
|
}
|
|
450
|
+
export function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
|
|
451
|
+
const keys = [];
|
|
452
|
+
function dig(list) {
|
|
453
|
+
(list || []).forEach(item => {
|
|
454
|
+
keys.push(item[rowKey]);
|
|
455
|
+
dig(item[childrenColumnName]);
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
dig(data);
|
|
459
|
+
return keys;
|
|
460
|
+
}
|
|
450
461
|
export const flattenArray = arr => {
|
|
451
462
|
if (!arr) {
|
|
452
463
|
return [];
|
|
@@ -29,15 +29,16 @@ import Grid from "./table/Grid";
|
|
|
29
29
|
|
|
30
30
|
// import { Tooltip } from 'react-tooltip'
|
|
31
31
|
// import ContextMenu from './ContextMenu'
|
|
32
|
-
import { addRowIdArray, convertToObj,
|
|
32
|
+
import { addRowIdArray, convertToObj, convertToObjTrue,
|
|
33
33
|
// convertFilters,
|
|
34
|
-
filterDataByColumns, flatColumns2,
|
|
34
|
+
filterDataByColumns, findAllChildrenKeys2, flatColumns2,
|
|
35
35
|
// filterDataByColumns,
|
|
36
|
-
getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayByColumns,
|
|
36
|
+
getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayByColumns, isTreeArray, updateWidthsByOther } from "./hook/utils";
|
|
37
37
|
// import GridEdit from './table/GridEdit'
|
|
38
38
|
import { convertToTanStackColumns } from "./hook/useColumns";
|
|
39
39
|
import { convertColumns } from "./hook/convert";
|
|
40
40
|
import { Modal } from 'antd';
|
|
41
|
+
// import { findAllChildrenKeys2 } from '../grid-component/hooks'
|
|
41
42
|
// import { columns111 } from '../test-2/columns'
|
|
42
43
|
|
|
43
44
|
dayjs.extend(customParseFormat);
|
|
@@ -62,6 +63,7 @@ const InternalTable = props => {
|
|
|
62
63
|
groupSetting,
|
|
63
64
|
groupColumns,
|
|
64
65
|
selectionSettings,
|
|
66
|
+
expandable,
|
|
65
67
|
// contextMenuClick,
|
|
66
68
|
// contextMenuOpen,
|
|
67
69
|
height,
|
|
@@ -70,6 +72,10 @@ const InternalTable = props => {
|
|
|
70
72
|
const id = React.useMemo(() => {
|
|
71
73
|
return faker.string.alpha(20);
|
|
72
74
|
}, []);
|
|
75
|
+
const {
|
|
76
|
+
defaultExpandedRowKeys,
|
|
77
|
+
defaultExpandAllRows
|
|
78
|
+
} = expandable || {};
|
|
73
79
|
const rowKey = 'rowId';
|
|
74
80
|
const prefix = 'ui-rc';
|
|
75
81
|
const getWindowSize = () => {
|
|
@@ -97,7 +103,8 @@ const InternalTable = props => {
|
|
|
97
103
|
const [isFullScreen, setIsFullScreen] = React.useState(false);
|
|
98
104
|
const [columns, setColumns] = React.useState([]);
|
|
99
105
|
React.useEffect(() => {
|
|
100
|
-
setColumns(propsColumns)
|
|
106
|
+
// setColumns(propsColumns as any)
|
|
107
|
+
setColumns(updateWidthsByOther(propsColumns, columns));
|
|
101
108
|
}, [propsColumns]);
|
|
102
109
|
const [expanded, setExpanded] = React.useState({});
|
|
103
110
|
const convertData = React.useMemo(() => {
|
|
@@ -110,17 +117,14 @@ const InternalTable = props => {
|
|
|
110
117
|
return convertToTanStackColumns({
|
|
111
118
|
t,
|
|
112
119
|
columns,
|
|
113
|
-
// expanded,
|
|
114
|
-
// setExpanded,
|
|
115
|
-
// expandable,
|
|
116
120
|
format,
|
|
117
121
|
editAble
|
|
118
122
|
});
|
|
119
123
|
|
|
120
|
-
// return convertToTanStackColumns<RecordType>(columns
|
|
124
|
+
// return convertToTanStackColumns<RecordType>(columns)
|
|
121
125
|
}, [t, columns, format, editAble]);
|
|
122
126
|
const isDataTree = React.useMemo(() => {
|
|
123
|
-
return
|
|
127
|
+
return isTreeArray(dataSource);
|
|
124
128
|
}, [dataSource]);
|
|
125
129
|
const columnPinning = React.useMemo(() => {
|
|
126
130
|
return {
|
|
@@ -133,6 +137,16 @@ const InternalTable = props => {
|
|
|
133
137
|
const [mergedFilterKeys, setMergedFilterKeys] = useMergedState(getAllRowKey(convertData), {
|
|
134
138
|
value: undefined
|
|
135
139
|
});
|
|
140
|
+
React.useEffect(() => {
|
|
141
|
+
if (defaultExpandAllRows) {
|
|
142
|
+
const allKeys = findAllChildrenKeys2(convertData, rowKey, 'children');
|
|
143
|
+
setExpanded(convertToObjTrue(allKeys));
|
|
144
|
+
} else {
|
|
145
|
+
if (defaultExpandedRowKeys) {
|
|
146
|
+
setExpanded(convertToObjTrue(defaultExpandedRowKeys ?? []));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}, [defaultExpandAllRows, convertData, defaultExpandedRowKeys]);
|
|
136
150
|
|
|
137
151
|
// ========================= Keys =========================
|
|
138
152
|
|
|
@@ -196,7 +210,9 @@ const InternalTable = props => {
|
|
|
196
210
|
height: height,
|
|
197
211
|
isDataTree: isDataTree,
|
|
198
212
|
selectionSettings: selectionSettings,
|
|
199
|
-
mergedSelectedKeys: mergedSelectedKeys
|
|
213
|
+
mergedSelectedKeys: mergedSelectedKeys,
|
|
214
|
+
expandable: expandable,
|
|
215
|
+
setColumns: setColumns
|
|
200
216
|
})), /*#__PURE__*/React.createElement(Modal, {
|
|
201
217
|
open: isFullScreen,
|
|
202
218
|
footer: null,
|
|
@@ -265,7 +281,9 @@ const InternalTable = props => {
|
|
|
265
281
|
windowSize: windowSize,
|
|
266
282
|
isDataTree: isDataTree,
|
|
267
283
|
selectionSettings: selectionSettings,
|
|
268
|
-
mergedSelectedKeys: mergedSelectedKeys
|
|
284
|
+
mergedSelectedKeys: mergedSelectedKeys,
|
|
285
|
+
expandable: expandable,
|
|
286
|
+
setColumns: setColumns
|
|
269
287
|
})))));
|
|
270
288
|
};
|
|
271
289
|
export default InternalTable;
|
|
@@ -2,7 +2,7 @@ import type { Table } from "@tanstack/react-table";
|
|
|
2
2
|
import { type Column } from "@tanstack/react-table";
|
|
3
3
|
import type { VirtualItem } from "@tanstack/react-virtual";
|
|
4
4
|
import type { AnyObject, ColumnsTable, ColumnTable, EditType, FilterOperator, IColumnType, IFormat, RangeState, Sorter, TypeFilter } from "./../type";
|
|
5
|
-
import { type CSSProperties } from "react";
|
|
5
|
+
import { Key, type CSSProperties } from "react";
|
|
6
6
|
import dayjs from "dayjs";
|
|
7
7
|
import type { IPositionCell } from "../useContext";
|
|
8
8
|
import type { ColumnDef } from "@tanstack/react-table";
|
|
@@ -136,3 +136,7 @@ export declare const convertToObjTrue: (arr: any) => {
|
|
|
136
136
|
export declare const getDiffent2Array: (a: any[], b: any[]) => any[];
|
|
137
137
|
export declare function isTree(arr: any[]): boolean;
|
|
138
138
|
export declare function findFirst(items: Column<any>[]): Column<any, unknown>;
|
|
139
|
+
export declare function isTreeArray(arr: any[]): boolean;
|
|
140
|
+
export declare function updateColumnWidthsRecursive(columns: any[], sizing: Record<string, number>): any[];
|
|
141
|
+
export declare function updateWidthsByOther(source: any[], target: any[]): any[];
|
|
142
|
+
export declare function findAllChildrenKeys2<RecordType>(data: readonly RecordType[], rowKey: any, childrenColumnName: string): Key[];
|
|
@@ -1877,14 +1877,24 @@ export const getDiffent2Array = (a, b) => {
|
|
|
1877
1877
|
return [...a.filter(x => !b.includes(x)), ...b.filter(x => !a.includes(x))];
|
|
1878
1878
|
};
|
|
1879
1879
|
export function isTree(arr) {
|
|
1880
|
-
if (!Array.isArray(arr))
|
|
1880
|
+
if (!Array.isArray(arr)) {
|
|
1881
|
+
return false;
|
|
1882
|
+
}
|
|
1881
1883
|
function checkNode(node) {
|
|
1882
|
-
if (typeof node !== "object" || node === null)
|
|
1884
|
+
if (typeof node !== "object" || node === null) {
|
|
1885
|
+
return false;
|
|
1886
|
+
}
|
|
1883
1887
|
if ("children" in node) {
|
|
1884
|
-
if (!Array.isArray(node.children))
|
|
1885
|
-
|
|
1888
|
+
if (!Array.isArray(node.children)) {
|
|
1889
|
+
return false;
|
|
1890
|
+
}
|
|
1891
|
+
if (node.children.length === 0) {
|
|
1892
|
+
return false;
|
|
1893
|
+
}
|
|
1886
1894
|
for (const child of node.children) {
|
|
1887
|
-
if (!checkNode(child))
|
|
1895
|
+
if (!checkNode(child)) {
|
|
1896
|
+
return false;
|
|
1897
|
+
}
|
|
1888
1898
|
}
|
|
1889
1899
|
}
|
|
1890
1900
|
return true;
|
|
@@ -1898,4 +1908,73 @@ export function findFirst(items) {
|
|
|
1898
1908
|
const leftItem = items.find(item => item.getIsPinned() === 'left');
|
|
1899
1909
|
if (leftItem) return leftItem;
|
|
1900
1910
|
return null;
|
|
1911
|
+
}
|
|
1912
|
+
export function isTreeArray(arr) {
|
|
1913
|
+
if (!Array.isArray(arr)) return false;
|
|
1914
|
+
return arr.every(item => {
|
|
1915
|
+
if ("children" in item) {
|
|
1916
|
+
return Array.isArray(item.children) && item.children.length > 0;
|
|
1917
|
+
}
|
|
1918
|
+
return true; // node lá thì hợp lệ
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
export function updateColumnWidthsRecursive(columns, sizing) {
|
|
1922
|
+
return columns.map(col => {
|
|
1923
|
+
const updated = {
|
|
1924
|
+
...col
|
|
1925
|
+
};
|
|
1926
|
+
|
|
1927
|
+
// cập nhật width nếu có trong sizing
|
|
1928
|
+
if (sizing[col.field] !== undefined) {
|
|
1929
|
+
updated.width = sizing[col.field];
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
// nếu có children thì gọi đệ quy
|
|
1933
|
+
if (col.children && col.children.length > 0) {
|
|
1934
|
+
updated.children = updateColumnWidthsRecursive(col.children, sizing);
|
|
1935
|
+
}
|
|
1936
|
+
return updated;
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
export function updateWidthsByOther(source, target) {
|
|
1940
|
+
const targetMap = new Map();
|
|
1941
|
+
|
|
1942
|
+
// tạo map {field -> width} từ target
|
|
1943
|
+
const buildMap = cols => {
|
|
1944
|
+
cols.forEach(col => {
|
|
1945
|
+
if (col.width !== undefined) {
|
|
1946
|
+
targetMap.set(col.field, col.width);
|
|
1947
|
+
}
|
|
1948
|
+
if (col.children) {
|
|
1949
|
+
buildMap(col.children);
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1952
|
+
};
|
|
1953
|
+
buildMap(target);
|
|
1954
|
+
|
|
1955
|
+
// cập nhật width từ map
|
|
1956
|
+
const update = cols => cols.map(col => {
|
|
1957
|
+
const updated = {
|
|
1958
|
+
...col
|
|
1959
|
+
};
|
|
1960
|
+
if (targetMap.has(col.field)) {
|
|
1961
|
+
updated.width = targetMap.get(col.field);
|
|
1962
|
+
}
|
|
1963
|
+
if (col.children) {
|
|
1964
|
+
updated.children = update(col.children);
|
|
1965
|
+
}
|
|
1966
|
+
return updated;
|
|
1967
|
+
});
|
|
1968
|
+
return update(source);
|
|
1969
|
+
}
|
|
1970
|
+
export function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
|
|
1971
|
+
const keys = [];
|
|
1972
|
+
function dig(list) {
|
|
1973
|
+
(list || []).forEach(item => {
|
|
1974
|
+
keys.push(item[rowKey]);
|
|
1975
|
+
dig(item[childrenColumnName]);
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
dig(data);
|
|
1979
|
+
return keys;
|
|
1901
1980
|
}
|
|
@@ -8,6 +8,7 @@ type Props<T> = Omit<TableProps<T>, 'columns'> & {
|
|
|
8
8
|
prefix: string;
|
|
9
9
|
columns: ColumnDef<T>[];
|
|
10
10
|
propsColumns: ColumnsTable<T>;
|
|
11
|
+
setColumns: Dispatch<SetStateAction<ColumnsTable<T>>>;
|
|
11
12
|
columnHidden: VisibilityState;
|
|
12
13
|
expanded: ExpandedState;
|
|
13
14
|
setExpanded: any;
|
|
@@ -17,7 +17,7 @@ import { arrayMove } from '@dnd-kit/sortable';
|
|
|
17
17
|
import React from 'react';
|
|
18
18
|
import TableContainer from "../TableContainer";
|
|
19
19
|
import { OperatorFeature } from "../features/operator";
|
|
20
|
-
import { convertFilters, convertToObjTrue, filterDataByColumns, getAllRowKey } from "../hook/utils";
|
|
20
|
+
import { convertFilters, convertToObjTrue, filterDataByColumns, getAllRowKey, updateColumnWidthsRecursive } from "../hook/utils";
|
|
21
21
|
import TableContainerEdit from "../TableContainerEdit";
|
|
22
22
|
const Grid = props => {
|
|
23
23
|
const {
|
|
@@ -28,6 +28,7 @@ const Grid = props => {
|
|
|
28
28
|
originData,
|
|
29
29
|
columns,
|
|
30
30
|
propsColumns,
|
|
31
|
+
setColumns,
|
|
31
32
|
pagination,
|
|
32
33
|
expanded,
|
|
33
34
|
setExpanded,
|
|
@@ -64,6 +65,7 @@ const Grid = props => {
|
|
|
64
65
|
const [rowSelection, setRowSelection] = React.useState(convertToObjTrue(mergedSelectedKeys));
|
|
65
66
|
const [grouping, setGrouping] = React.useState([]);
|
|
66
67
|
const [columnSizing, setColumnSizing] = React.useState({});
|
|
68
|
+
const [columnSizingInfo, setColumnSizingInfo] = React.useState({});
|
|
67
69
|
// const [manualUpdate, setManualUpdate] = React.useState(false)
|
|
68
70
|
// const [manualResize, setManualResize] = React.useState(false)
|
|
69
71
|
|
|
@@ -112,6 +114,7 @@ const Grid = props => {
|
|
|
112
114
|
columnResizeMode,
|
|
113
115
|
columnResizeDirection,
|
|
114
116
|
onColumnSizingChange: setColumnSizing,
|
|
117
|
+
onColumnSizingInfoChange: setColumnSizingInfo,
|
|
115
118
|
// ColumnSizing
|
|
116
119
|
|
|
117
120
|
// ColumnSorting
|
|
@@ -148,6 +151,12 @@ const Grid = props => {
|
|
|
148
151
|
}
|
|
149
152
|
}
|
|
150
153
|
}, [columnHidden, table]);
|
|
154
|
+
React.useEffect(() => {
|
|
155
|
+
if (columnSizingInfo.isResizingColumn === false) {
|
|
156
|
+
const aa = updateColumnWidthsRecursive(propsColumns, columnSizing);
|
|
157
|
+
setColumns(aa);
|
|
158
|
+
}
|
|
159
|
+
}, [columnSizingInfo]);
|
|
151
160
|
React.useEffect(() => {
|
|
152
161
|
// if (!manualUpdate) {
|
|
153
162
|
if (Object.keys(rowSelection) !== Object.keys(mergedSelectedKeys)) {
|
|
@@ -57,6 +57,7 @@ export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], ro
|
|
|
57
57
|
export declare const parseBooleanToValue: (value: boolean, type: 'boolean' | 'number') => number | boolean;
|
|
58
58
|
export declare const genPresets: (presets?: import("@ant-design/colors").PalettesProps) => import("antd/es/color-picker/interface").PresetsItem[];
|
|
59
59
|
export declare function findAllChildrenKeys<RecordType>(data: readonly RecordType[], getRowKey: GetRowKey<RecordType>, childrenColumnName: string): Key[];
|
|
60
|
+
export declare function findAllChildrenKeys2<RecordType>(data: readonly RecordType[], rowKey: any, childrenColumnName: string): Key[];
|
|
60
61
|
export declare const flattenArray: <RecordType extends AnyObject = AnyObject>(arr: any[]) => RecordType[];
|
|
61
62
|
export declare const flattenData: <RecordType extends AnyObject = AnyObject>(childrenColumnName: string, data?: RecordType[]) => RecordType[];
|
|
62
63
|
export declare const unFlattenData: <RecordType extends AnyObject = AnyObject>(data: RecordType[]) => RecordType[];
|
|
@@ -17,6 +17,7 @@ exports.convertFormat = convertFormat;
|
|
|
17
17
|
exports.filterDataByColumns3 = exports.filterDataByColumns2 = exports.filterDataByColumns = exports.editAbleColumns = exports.detectSeparators = exports.customWeekStartEndFormat = exports.customFilterOption = exports.countItemsBeforeIndex = exports.convertLabelToTitle = void 0;
|
|
18
18
|
exports.filterDataByColumns4 = filterDataByColumns4;
|
|
19
19
|
exports.findAllChildrenKeys = findAllChildrenKeys;
|
|
20
|
+
exports.findAllChildrenKeys2 = findAllChildrenKeys2;
|
|
20
21
|
exports.getAllVisibleKeys = exports.getAllRowKey = exports.genPresets = exports.flattenData = exports.flattenArray = exports.findItemPath = exports.findItemByKey = void 0;
|
|
21
22
|
exports.getBottomRowCells = getBottomRowCells;
|
|
22
23
|
exports.getCellsByPosition = getCellsByPosition;
|
|
@@ -38,8 +39,8 @@ exports.isRightMostInRegion = isRightMostInRegion;
|
|
|
38
39
|
exports.isTopMostInRegion = exports.isSelectedCell = void 0;
|
|
39
40
|
exports.mergeWithFilter = mergeWithFilter;
|
|
40
41
|
exports.mergeWithFilter2 = mergeWithFilter2;
|
|
41
|
-
exports.
|
|
42
|
-
exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.unFlattenData = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.sumByField = exports.sortedSetDSC = exports.sortedSetASC = exports.showDraggingPoint = exports.shouldInclude = exports.removeVietnameseTones = void 0;
|
|
42
|
+
exports.removeFieldRecursive = exports.removeColumns = exports.removeClassCellIndexSelected = exports.removeClassBorderPasteCell = exports.removeBorderPasteClass = exports.removeBorderClass2 = exports.removeBorderClass = exports.parseCells = exports.parseBooleanToValue = exports.onRemoveBorderSelectedCell = exports.onRemoveBgSelectedCell = exports.onRemoveBgCellIndex = exports.onAddBorderSelectedCell = exports.onAddBgSelectedCell = exports.onAddBgCellIndex = exports.newGuid = exports.mergedSets = void 0;
|
|
43
|
+
exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.unFlattenData = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.sumByField = exports.sortedSetDSC = exports.sortedSetASC = exports.showDraggingPoint = exports.shouldInclude = exports.removeVietnameseTones = exports.removeInvisibleColumns = void 0;
|
|
43
44
|
exports.updateDataByFilter = updateDataByFilter;
|
|
44
45
|
exports.updateOrInsert = updateOrInsert;
|
|
45
46
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
@@ -525,6 +526,17 @@ function findAllChildrenKeys(data, getRowKey, childrenColumnName) {
|
|
|
525
526
|
dig(data);
|
|
526
527
|
return keys;
|
|
527
528
|
}
|
|
529
|
+
function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
|
|
530
|
+
const keys = [];
|
|
531
|
+
function dig(list) {
|
|
532
|
+
(list || []).forEach(item => {
|
|
533
|
+
keys.push(item[rowKey]);
|
|
534
|
+
dig(item[childrenColumnName]);
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
dig(data);
|
|
538
|
+
return keys;
|
|
539
|
+
}
|
|
528
540
|
const flattenArray = arr => {
|
|
529
541
|
if (!arr) {
|
|
530
542
|
return [];
|
|
@@ -44,6 +44,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
44
44
|
|
|
45
45
|
// import GridEdit from './table/GridEdit'
|
|
46
46
|
|
|
47
|
+
// import { findAllChildrenKeys2 } from '../grid-component/hooks'
|
|
47
48
|
// import { columns111 } from '../test-2/columns'
|
|
48
49
|
|
|
49
50
|
_dayjs.default.extend(_customParseFormat.default);
|
|
@@ -68,6 +69,7 @@ const InternalTable = props => {
|
|
|
68
69
|
groupSetting,
|
|
69
70
|
groupColumns,
|
|
70
71
|
selectionSettings,
|
|
72
|
+
expandable,
|
|
71
73
|
// contextMenuClick,
|
|
72
74
|
// contextMenuOpen,
|
|
73
75
|
height,
|
|
@@ -76,6 +78,10 @@ const InternalTable = props => {
|
|
|
76
78
|
const id = _react.default.useMemo(() => {
|
|
77
79
|
return _faker.faker.string.alpha(20);
|
|
78
80
|
}, []);
|
|
81
|
+
const {
|
|
82
|
+
defaultExpandedRowKeys,
|
|
83
|
+
defaultExpandAllRows
|
|
84
|
+
} = expandable || {};
|
|
79
85
|
const rowKey = 'rowId';
|
|
80
86
|
const prefix = 'ui-rc';
|
|
81
87
|
const getWindowSize = () => {
|
|
@@ -103,7 +109,8 @@ const InternalTable = props => {
|
|
|
103
109
|
const [isFullScreen, setIsFullScreen] = _react.default.useState(false);
|
|
104
110
|
const [columns, setColumns] = _react.default.useState([]);
|
|
105
111
|
_react.default.useEffect(() => {
|
|
106
|
-
setColumns(propsColumns)
|
|
112
|
+
// setColumns(propsColumns as any)
|
|
113
|
+
setColumns((0, _utils.updateWidthsByOther)(propsColumns, columns));
|
|
107
114
|
}, [propsColumns]);
|
|
108
115
|
const [expanded, setExpanded] = _react.default.useState({});
|
|
109
116
|
const convertData = _react.default.useMemo(() => {
|
|
@@ -116,17 +123,14 @@ const InternalTable = props => {
|
|
|
116
123
|
return (0, _useColumns.convertToTanStackColumns)({
|
|
117
124
|
t,
|
|
118
125
|
columns,
|
|
119
|
-
// expanded,
|
|
120
|
-
// setExpanded,
|
|
121
|
-
// expandable,
|
|
122
126
|
format,
|
|
123
127
|
editAble
|
|
124
128
|
});
|
|
125
129
|
|
|
126
|
-
// return convertToTanStackColumns<RecordType>(columns
|
|
130
|
+
// return convertToTanStackColumns<RecordType>(columns)
|
|
127
131
|
}, [t, columns, format, editAble]);
|
|
128
132
|
const isDataTree = _react.default.useMemo(() => {
|
|
129
|
-
return (0, _utils.
|
|
133
|
+
return (0, _utils.isTreeArray)(dataSource);
|
|
130
134
|
}, [dataSource]);
|
|
131
135
|
const columnPinning = _react.default.useMemo(() => {
|
|
132
136
|
return {
|
|
@@ -139,6 +143,16 @@ const InternalTable = props => {
|
|
|
139
143
|
const [mergedFilterKeys, setMergedFilterKeys] = (0, _useMergedState.default)((0, _utils.getAllRowKey)(convertData), {
|
|
140
144
|
value: undefined
|
|
141
145
|
});
|
|
146
|
+
_react.default.useEffect(() => {
|
|
147
|
+
if (defaultExpandAllRows) {
|
|
148
|
+
const allKeys = (0, _utils.findAllChildrenKeys2)(convertData, rowKey, 'children');
|
|
149
|
+
setExpanded((0, _utils.convertToObjTrue)(allKeys));
|
|
150
|
+
} else {
|
|
151
|
+
if (defaultExpandedRowKeys) {
|
|
152
|
+
setExpanded((0, _utils.convertToObjTrue)(defaultExpandedRowKeys ?? []));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}, [defaultExpandAllRows, convertData, defaultExpandedRowKeys]);
|
|
142
156
|
|
|
143
157
|
// ========================= Keys =========================
|
|
144
158
|
|
|
@@ -202,7 +216,9 @@ const InternalTable = props => {
|
|
|
202
216
|
height: height,
|
|
203
217
|
isDataTree: isDataTree,
|
|
204
218
|
selectionSettings: selectionSettings,
|
|
205
|
-
mergedSelectedKeys: mergedSelectedKeys
|
|
219
|
+
mergedSelectedKeys: mergedSelectedKeys,
|
|
220
|
+
expandable: expandable,
|
|
221
|
+
setColumns: setColumns
|
|
206
222
|
})), /*#__PURE__*/_react.default.createElement(_antd.Modal, {
|
|
207
223
|
open: isFullScreen,
|
|
208
224
|
footer: null,
|
|
@@ -271,7 +287,9 @@ const InternalTable = props => {
|
|
|
271
287
|
windowSize: windowSize,
|
|
272
288
|
isDataTree: isDataTree,
|
|
273
289
|
selectionSettings: selectionSettings,
|
|
274
|
-
mergedSelectedKeys: mergedSelectedKeys
|
|
290
|
+
mergedSelectedKeys: mergedSelectedKeys,
|
|
291
|
+
expandable: expandable,
|
|
292
|
+
setColumns: setColumns
|
|
275
293
|
})))));
|
|
276
294
|
};
|
|
277
295
|
var _default = exports.default = InternalTable;
|
|
@@ -2,7 +2,7 @@ import type { Table } from "@tanstack/react-table";
|
|
|
2
2
|
import { type Column } from "@tanstack/react-table";
|
|
3
3
|
import type { VirtualItem } from "@tanstack/react-virtual";
|
|
4
4
|
import type { AnyObject, ColumnsTable, ColumnTable, EditType, FilterOperator, IColumnType, IFormat, RangeState, Sorter, TypeFilter } from "./../type";
|
|
5
|
-
import { type CSSProperties } from "react";
|
|
5
|
+
import { Key, type CSSProperties } from "react";
|
|
6
6
|
import dayjs from "dayjs";
|
|
7
7
|
import type { IPositionCell } from "../useContext";
|
|
8
8
|
import type { ColumnDef } from "@tanstack/react-table";
|
|
@@ -136,3 +136,7 @@ export declare const convertToObjTrue: (arr: any) => {
|
|
|
136
136
|
export declare const getDiffent2Array: (a: any[], b: any[]) => any[];
|
|
137
137
|
export declare function isTree(arr: any[]): boolean;
|
|
138
138
|
export declare function findFirst(items: Column<any>[]): Column<any, unknown>;
|
|
139
|
+
export declare function isTreeArray(arr: any[]): boolean;
|
|
140
|
+
export declare function updateColumnWidthsRecursive(columns: any[], sizing: Record<string, number>): any[];
|
|
141
|
+
export declare function updateWidthsByOther(source: any[], target: any[]): any[];
|
|
142
|
+
export declare function findAllChildrenKeys2<RecordType>(data: readonly RecordType[], rowKey: any, childrenColumnName: string): Key[];
|
|
@@ -20,6 +20,7 @@ exports.convertFilters = exports.convertDayjsToDate = exports.convertDateToDayjs
|
|
|
20
20
|
exports.convertFormat = convertFormat;
|
|
21
21
|
exports.extendsObject = exports.detectSeparators = exports.customWeekStartEndFormat = exports.convertToObjTrue = exports.convertToObj = exports.convertLabelToTitle = void 0;
|
|
22
22
|
exports.filterDataByColumns = filterDataByColumns;
|
|
23
|
+
exports.findAllChildrenKeys2 = findAllChildrenKeys2;
|
|
23
24
|
exports.findFirst = findFirst;
|
|
24
25
|
exports.getAllVisibleKeys1 = exports.getAllVisibleKeys = exports.getAllRowKey = exports.genPresets = exports.flattenData = exports.flattenArray = exports.flatColumns2 = exports.findItemByKey = void 0;
|
|
25
26
|
exports.getCellsByPosition = getCellsByPosition;
|
|
@@ -39,10 +40,14 @@ exports.isEqualSet = isEqualSet;
|
|
|
39
40
|
exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isFormattedNumber = void 0;
|
|
40
41
|
exports.isObjEqual = isObjEqual;
|
|
41
42
|
exports.isTree = isTree;
|
|
43
|
+
exports.isTreeArray = isTreeArray;
|
|
42
44
|
exports.sortByType = exports.shouldInclude = exports.removeVietnameseTones = exports.parseBooleanToValue = exports.onRemoveBgSelectedCell = exports.onAddBgSelectedCell = exports.newGuid = void 0;
|
|
43
45
|
exports.sortData = sortData;
|
|
44
|
-
exports.
|
|
46
|
+
exports.updateArrayByKey = exports.unFlattenData = exports.sumSize = void 0;
|
|
47
|
+
exports.updateColumnWidthsRecursive = updateColumnWidthsRecursive;
|
|
48
|
+
exports.updateColumns1 = void 0;
|
|
45
49
|
exports.updateOrInsert = updateOrInsert;
|
|
50
|
+
exports.updateWidthsByOther = updateWidthsByOther;
|
|
46
51
|
var _useSelection = require("rc-master-ui/es/table/hooks/useSelection");
|
|
47
52
|
var _uuid = require("uuid");
|
|
48
53
|
var _colors = require("@ant-design/colors");
|
|
@@ -1978,14 +1983,24 @@ const getDiffent2Array = (a, b) => {
|
|
|
1978
1983
|
};
|
|
1979
1984
|
exports.getDiffent2Array = getDiffent2Array;
|
|
1980
1985
|
function isTree(arr) {
|
|
1981
|
-
if (!Array.isArray(arr))
|
|
1986
|
+
if (!Array.isArray(arr)) {
|
|
1987
|
+
return false;
|
|
1988
|
+
}
|
|
1982
1989
|
function checkNode(node) {
|
|
1983
|
-
if (typeof node !== "object" || node === null)
|
|
1990
|
+
if (typeof node !== "object" || node === null) {
|
|
1991
|
+
return false;
|
|
1992
|
+
}
|
|
1984
1993
|
if ("children" in node) {
|
|
1985
|
-
if (!Array.isArray(node.children))
|
|
1986
|
-
|
|
1994
|
+
if (!Array.isArray(node.children)) {
|
|
1995
|
+
return false;
|
|
1996
|
+
}
|
|
1997
|
+
if (node.children.length === 0) {
|
|
1998
|
+
return false;
|
|
1999
|
+
}
|
|
1987
2000
|
for (const child of node.children) {
|
|
1988
|
-
if (!checkNode(child))
|
|
2001
|
+
if (!checkNode(child)) {
|
|
2002
|
+
return false;
|
|
2003
|
+
}
|
|
1989
2004
|
}
|
|
1990
2005
|
}
|
|
1991
2006
|
return true;
|
|
@@ -1999,4 +2014,73 @@ function findFirst(items) {
|
|
|
1999
2014
|
const leftItem = items.find(item => item.getIsPinned() === 'left');
|
|
2000
2015
|
if (leftItem) return leftItem;
|
|
2001
2016
|
return null;
|
|
2017
|
+
}
|
|
2018
|
+
function isTreeArray(arr) {
|
|
2019
|
+
if (!Array.isArray(arr)) return false;
|
|
2020
|
+
return arr.every(item => {
|
|
2021
|
+
if ("children" in item) {
|
|
2022
|
+
return Array.isArray(item.children) && item.children.length > 0;
|
|
2023
|
+
}
|
|
2024
|
+
return true; // node lá thì hợp lệ
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
function updateColumnWidthsRecursive(columns, sizing) {
|
|
2028
|
+
return columns.map(col => {
|
|
2029
|
+
const updated = {
|
|
2030
|
+
...col
|
|
2031
|
+
};
|
|
2032
|
+
|
|
2033
|
+
// cập nhật width nếu có trong sizing
|
|
2034
|
+
if (sizing[col.field] !== undefined) {
|
|
2035
|
+
updated.width = sizing[col.field];
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
// nếu có children thì gọi đệ quy
|
|
2039
|
+
if (col.children && col.children.length > 0) {
|
|
2040
|
+
updated.children = updateColumnWidthsRecursive(col.children, sizing);
|
|
2041
|
+
}
|
|
2042
|
+
return updated;
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
function updateWidthsByOther(source, target) {
|
|
2046
|
+
const targetMap = new Map();
|
|
2047
|
+
|
|
2048
|
+
// tạo map {field -> width} từ target
|
|
2049
|
+
const buildMap = cols => {
|
|
2050
|
+
cols.forEach(col => {
|
|
2051
|
+
if (col.width !== undefined) {
|
|
2052
|
+
targetMap.set(col.field, col.width);
|
|
2053
|
+
}
|
|
2054
|
+
if (col.children) {
|
|
2055
|
+
buildMap(col.children);
|
|
2056
|
+
}
|
|
2057
|
+
});
|
|
2058
|
+
};
|
|
2059
|
+
buildMap(target);
|
|
2060
|
+
|
|
2061
|
+
// cập nhật width từ map
|
|
2062
|
+
const update = cols => cols.map(col => {
|
|
2063
|
+
const updated = {
|
|
2064
|
+
...col
|
|
2065
|
+
};
|
|
2066
|
+
if (targetMap.has(col.field)) {
|
|
2067
|
+
updated.width = targetMap.get(col.field);
|
|
2068
|
+
}
|
|
2069
|
+
if (col.children) {
|
|
2070
|
+
updated.children = update(col.children);
|
|
2071
|
+
}
|
|
2072
|
+
return updated;
|
|
2073
|
+
});
|
|
2074
|
+
return update(source);
|
|
2075
|
+
}
|
|
2076
|
+
function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
|
|
2077
|
+
const keys = [];
|
|
2078
|
+
function dig(list) {
|
|
2079
|
+
(list || []).forEach(item => {
|
|
2080
|
+
keys.push(item[rowKey]);
|
|
2081
|
+
dig(item[childrenColumnName]);
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
dig(data);
|
|
2085
|
+
return keys;
|
|
2002
2086
|
}
|
|
@@ -8,6 +8,7 @@ type Props<T> = Omit<TableProps<T>, 'columns'> & {
|
|
|
8
8
|
prefix: string;
|
|
9
9
|
columns: ColumnDef<T>[];
|
|
10
10
|
propsColumns: ColumnsTable<T>;
|
|
11
|
+
setColumns: Dispatch<SetStateAction<ColumnsTable<T>>>;
|
|
11
12
|
columnHidden: VisibilityState;
|
|
12
13
|
expanded: ExpandedState;
|
|
13
14
|
setExpanded: any;
|
|
@@ -30,6 +30,7 @@ const Grid = props => {
|
|
|
30
30
|
originData,
|
|
31
31
|
columns,
|
|
32
32
|
propsColumns,
|
|
33
|
+
setColumns,
|
|
33
34
|
pagination,
|
|
34
35
|
expanded,
|
|
35
36
|
setExpanded,
|
|
@@ -66,6 +67,7 @@ const Grid = props => {
|
|
|
66
67
|
const [rowSelection, setRowSelection] = _react.default.useState((0, _utils.convertToObjTrue)(mergedSelectedKeys));
|
|
67
68
|
const [grouping, setGrouping] = _react.default.useState([]);
|
|
68
69
|
const [columnSizing, setColumnSizing] = _react.default.useState({});
|
|
70
|
+
const [columnSizingInfo, setColumnSizingInfo] = _react.default.useState({});
|
|
69
71
|
// const [manualUpdate, setManualUpdate] = React.useState(false)
|
|
70
72
|
// const [manualResize, setManualResize] = React.useState(false)
|
|
71
73
|
|
|
@@ -114,6 +116,7 @@ const Grid = props => {
|
|
|
114
116
|
columnResizeMode,
|
|
115
117
|
columnResizeDirection,
|
|
116
118
|
onColumnSizingChange: setColumnSizing,
|
|
119
|
+
onColumnSizingInfoChange: setColumnSizingInfo,
|
|
117
120
|
// ColumnSizing
|
|
118
121
|
|
|
119
122
|
// ColumnSorting
|
|
@@ -150,6 +153,12 @@ const Grid = props => {
|
|
|
150
153
|
}
|
|
151
154
|
}
|
|
152
155
|
}, [columnHidden, table]);
|
|
156
|
+
_react.default.useEffect(() => {
|
|
157
|
+
if (columnSizingInfo.isResizingColumn === false) {
|
|
158
|
+
const aa = (0, _utils.updateColumnWidthsRecursive)(propsColumns, columnSizing);
|
|
159
|
+
setColumns(aa);
|
|
160
|
+
}
|
|
161
|
+
}, [columnSizingInfo]);
|
|
153
162
|
_react.default.useEffect(() => {
|
|
154
163
|
// if (!manualUpdate) {
|
|
155
164
|
if (Object.keys(rowSelection) !== Object.keys(mergedSelectedKeys)) {
|