es-grid-template 1.7.41 → 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.
@@ -31,14 +31,14 @@ import Grid from "./table/Grid";
31
31
  // import ContextMenu from './ContextMenu'
32
32
  import { addRowIdArray, convertToObj, convertToObjTrue,
33
33
  // convertFilters,
34
- filterDataByColumns, flatColumns2,
34
+ filterDataByColumns, findAllChildrenKeys2, flatColumns2,
35
35
  // filterDataByColumns,
36
- getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayByColumns, isTreeArray } from "./hook/utils";
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
+ // import { findAllChildrenKeys2 } from '../grid-component/hooks'
42
42
  // import { columns111 } from '../test-2/columns'
43
43
 
44
44
  dayjs.extend(customParseFormat);
@@ -103,7 +103,8 @@ const InternalTable = props => {
103
103
  const [isFullScreen, setIsFullScreen] = React.useState(false);
104
104
  const [columns, setColumns] = React.useState([]);
105
105
  React.useEffect(() => {
106
- setColumns(propsColumns);
106
+ // setColumns(propsColumns as any)
107
+ setColumns(updateWidthsByOther(propsColumns, columns));
107
108
  }, [propsColumns]);
108
109
  const [expanded, setExpanded] = React.useState({});
109
110
  const convertData = React.useMemo(() => {
@@ -210,7 +211,8 @@ const InternalTable = props => {
210
211
  isDataTree: isDataTree,
211
212
  selectionSettings: selectionSettings,
212
213
  mergedSelectedKeys: mergedSelectedKeys,
213
- expandable: expandable
214
+ expandable: expandable,
215
+ setColumns: setColumns
214
216
  })), /*#__PURE__*/React.createElement(Modal, {
215
217
  open: isFullScreen,
216
218
  footer: null,
@@ -280,7 +282,8 @@ const InternalTable = props => {
280
282
  isDataTree: isDataTree,
281
283
  selectionSettings: selectionSettings,
282
284
  mergedSelectedKeys: mergedSelectedKeys,
283
- expandable: expandable
285
+ expandable: expandable,
286
+ setColumns: setColumns
284
287
  })))));
285
288
  };
286
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";
@@ -137,3 +137,6 @@ 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
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[];
@@ -1917,4 +1917,64 @@ export function isTreeArray(arr) {
1917
1917
  }
1918
1918
  return true; // node lá thì hợp lệ
1919
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;
1920
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)) {
@@ -20,7 +20,6 @@ var _utils = require("./hook/utils");
20
20
  var _useColumns = require("./hook/useColumns");
21
21
  var _convert = require("./hook/convert");
22
22
  var _antd = require("antd");
23
- var _hooks = require("../grid-component/hooks");
24
23
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
25
24
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
26
25
  // import en from "rc-master-ui/es/date-picker/locale/en_US"
@@ -45,6 +44,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
45
44
 
46
45
  // import GridEdit from './table/GridEdit'
47
46
 
47
+ // import { findAllChildrenKeys2 } from '../grid-component/hooks'
48
48
  // import { columns111 } from '../test-2/columns'
49
49
 
50
50
  _dayjs.default.extend(_customParseFormat.default);
@@ -109,7 +109,8 @@ const InternalTable = props => {
109
109
  const [isFullScreen, setIsFullScreen] = _react.default.useState(false);
110
110
  const [columns, setColumns] = _react.default.useState([]);
111
111
  _react.default.useEffect(() => {
112
- setColumns(propsColumns);
112
+ // setColumns(propsColumns as any)
113
+ setColumns((0, _utils.updateWidthsByOther)(propsColumns, columns));
113
114
  }, [propsColumns]);
114
115
  const [expanded, setExpanded] = _react.default.useState({});
115
116
  const convertData = _react.default.useMemo(() => {
@@ -144,7 +145,7 @@ const InternalTable = props => {
144
145
  });
145
146
  _react.default.useEffect(() => {
146
147
  if (defaultExpandAllRows) {
147
- const allKeys = (0, _hooks.findAllChildrenKeys2)(convertData, rowKey, 'children');
148
+ const allKeys = (0, _utils.findAllChildrenKeys2)(convertData, rowKey, 'children');
148
149
  setExpanded((0, _utils.convertToObjTrue)(allKeys));
149
150
  } else {
150
151
  if (defaultExpandedRowKeys) {
@@ -216,7 +217,8 @@ const InternalTable = props => {
216
217
  isDataTree: isDataTree,
217
218
  selectionSettings: selectionSettings,
218
219
  mergedSelectedKeys: mergedSelectedKeys,
219
- expandable: expandable
220
+ expandable: expandable,
221
+ setColumns: setColumns
220
222
  })), /*#__PURE__*/_react.default.createElement(_antd.Modal, {
221
223
  open: isFullScreen,
222
224
  footer: null,
@@ -286,7 +288,8 @@ const InternalTable = props => {
286
288
  isDataTree: isDataTree,
287
289
  selectionSettings: selectionSettings,
288
290
  mergedSelectedKeys: mergedSelectedKeys,
289
- expandable: expandable
291
+ expandable: expandable,
292
+ setColumns: setColumns
290
293
  })))));
291
294
  };
292
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";
@@ -137,3 +137,6 @@ 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
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;
@@ -42,8 +43,11 @@ exports.isTree = isTree;
42
43
  exports.isTreeArray = isTreeArray;
43
44
  exports.sortByType = exports.shouldInclude = exports.removeVietnameseTones = exports.parseBooleanToValue = exports.onRemoveBgSelectedCell = exports.onAddBgSelectedCell = exports.newGuid = void 0;
44
45
  exports.sortData = sortData;
45
- exports.updateColumns1 = exports.updateArrayByKey = exports.unFlattenData = exports.sumSize = void 0;
46
+ exports.updateArrayByKey = exports.unFlattenData = exports.sumSize = void 0;
47
+ exports.updateColumnWidthsRecursive = updateColumnWidthsRecursive;
48
+ exports.updateColumns1 = void 0;
46
49
  exports.updateOrInsert = updateOrInsert;
50
+ exports.updateWidthsByOther = updateWidthsByOther;
47
51
  var _useSelection = require("rc-master-ui/es/table/hooks/useSelection");
48
52
  var _uuid = require("uuid");
49
53
  var _colors = require("@ant-design/colors");
@@ -2019,4 +2023,64 @@ function isTreeArray(arr) {
2019
2023
  }
2020
2024
  return true; // node lá thì hợp lệ
2021
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;
2022
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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.7.41",
3
+ "version": "1.7.42",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",