es-grid-template 1.7.48 → 1.8.1

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.
Files changed (61) hide show
  1. package/es/grid-component/TempTable.js +1 -3
  2. package/es/table-component/ColumnsChoose.js +9 -2
  3. package/es/table-component/InternalTable.js +1 -0
  4. package/es/table-component/TableContainer.d.ts +5 -1
  5. package/es/table-component/TableContainer.js +33 -3
  6. package/es/table-component/TableContainerEdit.js +87 -62
  7. package/es/table-component/body/TableBody.js +1 -1
  8. package/es/table-component/body/TableBodyCell.d.ts +7 -3
  9. package/es/table-component/body/TableBodyCell.js +270 -135
  10. package/es/table-component/body/TableBodyCellEdit.d.ts +2 -2
  11. package/es/table-component/body/TableBodyCellEdit.js +18 -13
  12. package/es/table-component/body/TableBodyRow.d.ts +2 -2
  13. package/es/table-component/body/TableBodyRow.js +45 -16
  14. package/es/table-component/components/command/Command.js +2 -0
  15. package/es/table-component/footer/TableFooter.js +1 -1
  16. package/es/table-component/footer/TableFooterCell.js +3 -2
  17. package/es/table-component/footer/TableFooterRow.js +4 -3
  18. package/es/table-component/header/TableHead.d.ts +1 -1
  19. package/es/table-component/header/TableHead.js +83 -20
  20. package/es/table-component/header/TableHeadCell.js +13 -8
  21. package/es/table-component/header/TableHeadCell2.d.ts +17 -0
  22. package/es/table-component/header/TableHeadCell2.js +331 -0
  23. package/es/table-component/header/TableHeadGroupCell.d.ts +17 -0
  24. package/es/table-component/header/TableHeadGroupCell.js +328 -0
  25. package/es/table-component/header/TableHeadRow.js +1 -1
  26. package/es/table-component/hook/utils.d.ts +1 -0
  27. package/es/table-component/hook/utils.js +28 -2
  28. package/es/table-component/style.scss +26 -4
  29. package/es/table-component/table/Grid.js +19 -19
  30. package/es/table-component/table/TableWrapper.js +1 -1
  31. package/lib/grid-component/TempTable.js +1 -3
  32. package/lib/table-component/ColumnsChoose.js +9 -2
  33. package/lib/table-component/InternalTable.js +1 -0
  34. package/lib/table-component/TableContainer.d.ts +5 -1
  35. package/lib/table-component/TableContainer.js +32 -2
  36. package/lib/table-component/TableContainerEdit.js +87 -62
  37. package/lib/table-component/body/TableBody.js +1 -1
  38. package/lib/table-component/body/TableBodyCell.d.ts +7 -3
  39. package/lib/table-component/body/TableBodyCell.js +269 -136
  40. package/lib/table-component/body/TableBodyCellEdit.d.ts +2 -2
  41. package/lib/table-component/body/TableBodyCellEdit.js +18 -13
  42. package/lib/table-component/body/TableBodyRow.d.ts +2 -2
  43. package/lib/table-component/body/TableBodyRow.js +45 -16
  44. package/lib/table-component/components/command/Command.js +2 -0
  45. package/lib/table-component/footer/TableFooter.js +1 -1
  46. package/lib/table-component/footer/TableFooterCell.js +3 -2
  47. package/lib/table-component/footer/TableFooterRow.js +4 -3
  48. package/lib/table-component/header/TableHead.d.ts +1 -1
  49. package/lib/table-component/header/TableHead.js +84 -20
  50. package/lib/table-component/header/TableHeadCell.js +13 -8
  51. package/lib/table-component/header/TableHeadCell2.d.ts +17 -0
  52. package/lib/table-component/header/TableHeadCell2.js +340 -0
  53. package/lib/table-component/header/TableHeadGroupCell.d.ts +17 -0
  54. package/lib/table-component/header/TableHeadGroupCell.js +337 -0
  55. package/lib/table-component/header/TableHeadRow.js +1 -1
  56. package/lib/table-component/hook/utils.d.ts +1 -0
  57. package/lib/table-component/hook/utils.js +30 -3
  58. package/lib/table-component/style.scss +26 -4
  59. package/lib/table-component/table/Grid.js +19 -19
  60. package/lib/table-component/table/TableWrapper.js +1 -1
  61. package/package.json +1 -1
@@ -11,6 +11,7 @@ export declare const newGuid: () => any;
11
11
  export declare const convertDayjsToDate: (dateString: string, format?: string) => Date;
12
12
  export declare const convertDateToDayjs: (date: Date | undefined, format?: string) => dayjs.Dayjs;
13
13
  export declare const getCommonPinningStyles: (column: Column<any>) => CSSProperties;
14
+ export declare const getCommonPinningStyles2: (header: any) => CSSProperties;
14
15
  export declare const sumSize: (items: any) => number;
15
16
  export declare const appendIfNotExists: (a: VirtualItem[], b: VirtualItem[]) => VirtualItem[];
16
17
  export declare const getNewItemsOnly: (a: VirtualItem[], b: VirtualItem[]) => VirtualItem[];
@@ -42,7 +42,31 @@ export const getCommonPinningStyles = column => {
42
42
  // opacity: isPinned ? 0.5 : 1,
43
43
  opacity: 1,
44
44
  position: isPinned ? "sticky" : "relative",
45
- width: column.getSize(),
45
+ // width: column.getSize(),
46
+ width: 'auto',
47
+ zIndex: isPinned ? 2 : 0
48
+ // border: '1px solid #e5e7eb',
49
+ // borderTop: 0,
50
+ // borderBottom: 0
51
+ };
52
+ };
53
+ export const getCommonPinningStyles2 = header => {
54
+ const isPinned = header.column.getIsPinned();
55
+ // const isLastLeftPinnedColumn = isPinned === "left" && column.getIsLastColumn("left");
56
+ // const isFirstRightPinnedColumn =isPinned === "right" && column.getIsFirstColumn("right");
57
+
58
+ return {
59
+ // boxShadow: isFirstRightPinnedColumn
60
+ // ? "#e0e0e0 2px 0px 1px -1px inset"
61
+ // : undefined,
62
+
63
+ left: isPinned === "left" ? `${header.getStart("left")}px` : undefined,
64
+ right: isPinned === "right" ? `${header.getAfter("right")}px` : undefined,
65
+ // opacity: isPinned ? 0.5 : 1,
66
+ opacity: 1,
67
+ position: isPinned ? "sticky" : "relative",
68
+ // width: column.getSize(),
69
+ width: 'auto',
46
70
  zIndex: isPinned ? 2 : 0
47
71
  // border: '1px solid #e5e7eb',
48
72
  // borderTop: 0,
@@ -203,9 +227,11 @@ export const addRowIdArray = inputArray => {
203
227
  if (typeof item.children !== "string" && item.children && item.children.length > 0) {
204
228
  item.children = addRowIdArray(item.children);
205
229
  }
230
+
231
+ // return { ...item, rowId: item.rowId ?? item.id ?? newGuid() }
206
232
  return {
207
233
  ...item,
208
- rowId: item.rowId ?? item.id ?? newGuid()
234
+ rowId: item.id ?? item.rowId ?? newGuid()
209
235
  };
210
236
  });
211
237
  } else {
@@ -121,7 +121,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
121
121
  white-space: normal;
122
122
  // overflow: hidden;
123
123
  text-overflow: ellipsis;
124
- word-break: keep-all;
124
+ word-break: break-word;
125
125
  }
126
126
 
127
127
 
@@ -129,7 +129,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
129
129
  white-space: normal;
130
130
  overflow: hidden;
131
131
  text-overflow: ellipsis;
132
- word-break: keep-all;
132
+ word-break: break-word;
133
133
  }
134
134
 
135
135
  }
@@ -176,7 +176,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
176
176
  .#{$prefix}-grid-cell-text-wrap {
177
177
  white-space: normal;
178
178
  // text-overflow: ellipsis;
179
- word-break: keep-all;
179
+ word-break: break-word;
180
180
  overflow: hidden;
181
181
  }
182
182
 
@@ -257,7 +257,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
257
257
 
258
258
  .#{$prefix}-grid-tbody {
259
259
 
260
- tr.#{$prefix}-grid-row {
260
+ .#{$prefix}-grid-row {
261
261
  border-bottom: 1px solid lightgray;
262
262
  }
263
263
 
@@ -266,6 +266,20 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
266
266
  position: absolute;
267
267
  width: 100%;
268
268
 
269
+ &:hover {
270
+ .#{$prefix}-grid-cell:not(.editable) {
271
+ background-color: $rowHoverBg;
272
+
273
+ &.cell-editable, &.#{$prefix}-grid-cell-index, &.#{$prefix}-grid-cell-selection {
274
+ // background-color: transparent;
275
+ }
276
+
277
+ // &.ui-rc-grid-cell-index {
278
+ // background-color: #ffffff;
279
+ // }
280
+ }
281
+ }
282
+
269
283
  &.#{$prefix}-grid-row-selected {
270
284
 
271
285
  .#{$prefix}-grid-cell {
@@ -274,6 +288,14 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
274
288
 
275
289
  }
276
290
 
291
+ &.#{$prefix}-grid-row-focus {
292
+
293
+ .#{$prefix}-grid-cell {
294
+ background-color: $rowHoverBg;
295
+ }
296
+
297
+ }
298
+
277
299
  }
278
300
 
279
301
  .#{$prefix}-grid-cell {
@@ -141,18 +141,16 @@ const Grid = props => {
141
141
 
142
142
  // debugTable: true
143
143
  });
144
-
145
- // React.useEffect(() => {
146
- // if (columnHidden) {
147
- // const abb = table.getVisibleLeafColumns()?.[0]
148
-
149
- // if (abb && Object.keys(columnSizingInfo).length === 0
150
- // ) {
151
- // setColumnSizing({ "#": abb.getSize() })
152
- // }
153
- // }
154
-
155
- // }, [columnHidden, columnSizingInfo])
144
+ React.useEffect(() => {
145
+ if (columnHidden) {
146
+ const abb = table.getVisibleLeafColumns()?.[0];
147
+ if (abb && Object.keys(columnSizingInfo).length === 0) {
148
+ setColumnSizing({
149
+ "#": abb.getSize()
150
+ });
151
+ }
152
+ }
153
+ }, [columnHidden, columnSizingInfo]);
156
154
 
157
155
  // React.useEffect(() => {
158
156
  // if (columnSizingInfo.isResizingColumn === false) {
@@ -167,12 +165,12 @@ const Grid = props => {
167
165
 
168
166
  React.useEffect(() => {
169
167
  // if (!manualUpdate) {
170
- if (Object.keys(rowSelection) !== Object.keys(mergedSelectedKeys)) {
168
+ if (Object.keys(rowSelection) !== Object.keys(mergedSelectedKeys) && !isSelectionChange.isChange) {
171
169
  setRowSelection(convertToObjTrue(mergedSelectedKeys));
172
170
  }
173
171
 
174
172
  // }
175
- }, [mergedSelectedKeys]);
173
+ }, [mergedSelectedKeys, isSelectionChange]);
176
174
  React.useEffect(() => {
177
175
  if (isSelectionChange.isChange) {
178
176
  // setManualUpdate(true)
@@ -186,12 +184,14 @@ const Grid = props => {
186
184
  rowData: isSelectionChange.rowData,
187
185
  selected: rs
188
186
  });
189
- setIsSelectionChange(prev => ({
190
- ...prev,
191
- isChange: false
192
- }));
187
+
188
+ // setIsSelectionChange((prev) => ({
189
+ // ...prev,
190
+ // isChange: false
191
+
192
+ // }))
193
193
  }
194
- }, [isSelectionChange, rowSelected, rowSelection, table]);
194
+ }, [isSelectionChange, rowSelection, table.getState().rowSelection]);
195
195
  React.useEffect(() => {
196
196
  if (sorterChange) {
197
197
  const aa = table.getState().sorting;
@@ -189,7 +189,7 @@ const TableWrapper = props => {
189
189
  // onScroll={infiniteScroll ? handleScroll : undefined}
190
190
  ,
191
191
  onScroll: handleScroll
192
- }, /*#__PURE__*/React.createElement("table", {
192
+ }, /*#__PURE__*/React.createElement("div", {
193
193
  style: {
194
194
  display: 'grid',
195
195
  minWidth: table.getTotalSize()
@@ -13,18 +13,16 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
13
13
  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; }
14
14
  const TempTable = props => {
15
15
  const {
16
- infiniteScroll,
17
16
  groupAble,
18
17
  editAble,
19
18
  ...rest
20
19
  } = props;
21
20
 
22
21
  // const TabComponent = groupAble ? InternalTable : Table
23
- const TabComponent = editAble ? _tableComponent.default : _InternalTable.default;
22
+ const TabComponent = groupAble ? _InternalTable.default : _tableComponent.default;
24
23
  // const TabComponent = InternalTable
25
24
 
26
25
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(TabComponent, (0, _extends2.default)({}, rest, {
27
- infiniteScroll: infiniteScroll,
28
26
  groupAble: groupAble,
29
27
  editAble: editAble
30
28
  })));
@@ -9,12 +9,14 @@ var _useMergedState = _interopRequireDefault(require("rc-util/lib/hooks/useMerge
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _styledComponents = _interopRequireDefault(require("styled-components"));
11
11
  var _antd = require("antd");
12
- var _icons = require("@ant-design/icons");
13
12
  var _tree = _interopRequireDefault(require("rc-master-ui/es/tree"));
14
13
  var _SearchOutlined = _interopRequireDefault(require("@ant-design/icons/SearchOutlined"));
15
14
  var _utils = require("./hook/utils");
15
+ var _becoxyIcons = require("becoxy-icons");
16
16
  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); }
17
17
  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; }
18
+ // import { SettingOutlined } from "@ant-design/icons"
19
+
18
20
  const BoxAction = _styledComponents.default.div.withConfig({
19
21
  displayName: "BoxAction",
20
22
  componentId: "es-grid-template__sc-jfujqh-0"
@@ -211,6 +213,11 @@ const ColumnsChoose = props => {
211
213
  }, /*#__PURE__*/_react.default.createElement(_antd.Tooltip, {
212
214
  arrow: false,
213
215
  title: 'Cài đặt'
214
- }, /*#__PURE__*/_react.default.createElement(_icons.SettingOutlined, null))));
216
+ }, /*#__PURE__*/_react.default.createElement(_becoxyIcons.Settings, {
217
+ fontSize: 16,
218
+ style: {
219
+ cursor: 'pointer'
220
+ }
221
+ }))));
215
222
  };
216
223
  exports.ColumnsChoose = ColumnsChoose;
@@ -110,6 +110,7 @@ const InternalTable = props => {
110
110
  const [columns, setColumns] = _react.default.useState([]);
111
111
  _react.default.useEffect(() => {
112
112
  // setColumns(propsColumns as any)
113
+
113
114
  setColumns((0, _utils.updateWidthsByOther)(propsColumns, columns));
114
115
  }, [propsColumns]);
115
116
  const [expanded, setExpanded] = _react.default.useState({});
@@ -1,6 +1,6 @@
1
1
  import type { Dispatch, SetStateAction } from 'react';
2
2
  import React from 'react';
3
- import type { ColumnDef, Table } from '@tanstack/react-table';
3
+ import type { ColumnDef, ColumnSizingInfoState, ColumnSizingState, Table } from '@tanstack/react-table';
4
4
  import type { ColumnsTable, TableProps } from './type';
5
5
  type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
6
6
  table: Table<T>;
@@ -32,6 +32,10 @@ type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
32
32
  isFullScreen: boolean;
33
33
  setIsFullScreen: Dispatch<SetStateAction<boolean>>;
34
34
  isDataTree: boolean;
35
+ setColumnSizing: Dispatch<SetStateAction<any>>;
36
+ setColumns: Dispatch<SetStateAction<any>>;
37
+ columnSizingInfo: ColumnSizingInfoState;
38
+ columnSizing: ColumnSizingState;
35
39
  };
36
40
  declare const TableContainer: <RecordType extends object>(props: TableContainerProps<RecordType>) => React.JSX.Element;
37
41
  export default TableContainer;
@@ -80,13 +80,17 @@ const TableContainer = props => {
80
80
  contextMenuHidden,
81
81
  isFullScreen,
82
82
  setIsFullScreen,
83
- isDataTree
83
+ isDataTree,
84
+ setColumns,
85
+ columnSizing,
86
+ columnSizingInfo
84
87
  } = props;
85
88
  const tableContainerRef = _react.default.useRef(null);
86
89
  const containerRef = _react.default.useRef(null);
87
90
  const bottomToolbarRef = _react.default.useRef(null);
88
91
  const topToolbarRef = _react.default.useRef(null);
89
92
  const [tableHeight, settableHeight] = _react.default.useState(0);
93
+ const [focusedCell, setFocusedCell] = _react.default.useState(undefined);
90
94
  _react.default.useEffect(() => {
91
95
  const totalHeight = minHeight ?? height;
92
96
  if (totalHeight) {
@@ -139,6 +143,30 @@ const TableContainer = props => {
139
143
  columnVirtualizer.measure();
140
144
  });
141
145
  }, [columnSizingState, columnVirtualizer]);
146
+ _react.default.useEffect(() => {
147
+ if (!tableContainerRef.current) {
148
+ return;
149
+ }
150
+
151
+ // const containerWidth = tableContainerRef.current.offsetWidth
152
+ // const totalWidth = table.getTotalSize()
153
+
154
+ // if (totalWidth && totalWidth <= containerWidth) {
155
+
156
+ // return
157
+
158
+ // }
159
+
160
+ if (columnSizingInfo.isResizingColumn === false) {
161
+ const aa = (0, _utils.updateColumnWidthsRecursive)(propsColumns, columnSizing);
162
+ setColumns(aa);
163
+
164
+ // requestAnimationFrame(() => {
165
+
166
+ // columnVirtualizer.measure()
167
+ // })
168
+ }
169
+ }, [columnSizingInfo]);
142
170
  const triggerCommandClick = () => {};
143
171
  return /*#__PURE__*/_react.default.createElement("div", {
144
172
  ref: containerRef,
@@ -219,7 +247,9 @@ const TableContainer = props => {
219
247
  setSorterChange,
220
248
  setFilterChange,
221
249
  windowSize,
222
- isDataTree
250
+ isDataTree,
251
+ focusedCell,
252
+ setFocusedCell
223
253
  }
224
254
  }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, {
225
255
  contextMenuItems: contextMenuItems,
@@ -674,80 +674,105 @@ const TableContainerEdit = props => {
674
674
  }, [dataSource, editingKey, id, onBlur]);
675
675
  const columnSizingState = table.getState().columnSizing;
676
676
  _react.default.useEffect(() => {
677
-
678
- // requestAnimationFrame(() => {
679
-
680
- // columnVirtualizer.measure()
681
- // })
677
+ requestAnimationFrame(() => {
678
+ columnVirtualizer.measure();
679
+ });
682
680
  }, [columnSizingState, columnVirtualizer]);
683
681
  _react.default.useEffect(() => {
684
682
  if (!tableContainerRef.current) {
685
683
  return;
686
684
  }
687
- const containerWidth = tableContainerRef.current.offsetWidth;
688
- const totalWidth = table.getTotalSize();
689
- if (totalWidth && totalWidth <= containerWidth) {
690
- return;
691
- }
685
+
686
+ // const containerWidth = tableContainerRef.current.offsetWidth
687
+ // const totalWidth = table.getTotalSize()
688
+
689
+ // if (totalWidth && totalWidth <= containerWidth) {
690
+
691
+ // return
692
+
693
+ // }
694
+
692
695
  if (columnSizingInfo.isResizingColumn === false) {
693
696
  const aa = (0, _utils.updateColumnWidthsRecursive)(propsColumns, columnSizing);
694
697
  setColumns(aa);
695
- requestAnimationFrame(() => {
696
- columnVirtualizer.measure();
697
- });
698
+
699
+ // requestAnimationFrame(() => {
700
+
701
+ // columnVirtualizer.measure()
702
+ // })
698
703
  }
699
704
  }, [columnSizingInfo]);
700
- _react.default.useEffect(() => {
701
- // if (!containerRef.current || !tableContainerRef.current) {
702
- if (!tableContainerRef.current) {
703
- return;
704
- }
705
705
 
706
- // const containerWidth = containerRef.current.offsetWidth - 1
707
- // const containerWidth = tableContainerRef.current.offsetWidth
708
- const containerWidth = tableContainerRef.current.offsetWidth - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0);
709
- const totalWidth = table.getTotalSize() - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0);
710
- if (totalWidth && totalWidth > 0 && totalWidth < containerWidth) {
711
- const factor = containerWidth / totalWidth;
712
- const visibleCols = table.getVisibleLeafColumns();
713
- const baseSizes = visibleCols.map(col => col.getSize() || col.columnDef.size || 150);
714
- const scaledSizes = baseSizes.map(size => size * factor);
715
- const roundedSizes = scaledSizes.map(size => Math.floor(size));
716
- let diff = containerWidth - roundedSizes.reduce((a, b) => a + b, 0);
717
-
718
- // phân bổ diff cho các cột từ trái qua phải
719
- for (let i = 0; diff > 0; i = (i + 1) % roundedSizes.length) {
720
- roundedSizes[i]++;
721
- diff--;
722
- }
723
- const aaa = visibleCols.reduce((acc, col, idx) => {
724
- acc[col.id] = roundedSizes[idx];
725
- return acc;
726
- }, {});
727
- const aa = (0, _utils.updateColumnWidthsRecursive)(propsColumns, aaa);
728
- setColumns(aa);
729
- table.setColumnSizing(aaa);
730
- requestAnimationFrame(() => {
731
- columnVirtualizer.measure();
732
- });
706
+ // React.useEffect(() => {
733
707
 
734
- // setColumnSizing?.(aaa)
735
- } else {
736
- if (columnHidden) {
737
- const abb = table.getVisibleLeafColumns()?.[0];
738
- if (abb && Object.keys(columnSizingInfo).length === 0) {
739
- // setColumnSizing({ "#": abb.getSize() })
740
- table.setColumnSizing({
741
- "#": abb.getSize()
742
- });
743
- requestAnimationFrame(() => {
744
- columnVirtualizer.measure();
745
- });
746
- }
747
- }
748
- }
749
- }, [table.getTotalSize(), dataSource.length, windowSize.innerWidth, columnVirtualizer]);
750
- // }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
708
+ // // if (!containerRef.current || !tableContainerRef.current) {
709
+ // if (!tableContainerRef.current) {
710
+ // return
711
+ // }
712
+
713
+ // // const containerWidth = containerRef.current.offsetWidth - 1
714
+ // // const containerWidth = tableContainerRef.current.offsetWidth
715
+ // const containerWidth = tableContainerRef.current.offsetWidth - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0)
716
+
717
+ // const totalWidth = table.getTotalSize() - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0)
718
+
719
+ // if (totalWidth && totalWidth > 0 && totalWidth < containerWidth) {
720
+
721
+ // const factor = containerWidth / totalWidth
722
+
723
+ // const visibleCols = table.getVisibleLeafColumns()
724
+
725
+ // const baseSizes = visibleCols.map(
726
+ // (col) => col.getSize() || col.columnDef.size || 150
727
+ // )
728
+
729
+ // const scaledSizes = baseSizes.map((size) => size * factor)
730
+ // const roundedSizes = scaledSizes.map((size) => Math.floor(size))
731
+
732
+ // let diff = containerWidth - roundedSizes.reduce((a, b) => a + b, 0)
733
+
734
+ // // phân bổ diff cho các cột từ trái qua phải
735
+ // for (let i = 0; diff > 0; i = (i + 1) % roundedSizes.length) {
736
+ // roundedSizes[i]++
737
+ // diff--
738
+ // }
739
+
740
+ // const aaa = visibleCols.reduce((acc, col, idx) => {
741
+ // acc[col.id] = roundedSizes[idx]
742
+ // return acc
743
+ // }, {} as Record<string, number>)
744
+
745
+ // const aa = updateColumnWidthsRecursive(propsColumns, aaa)
746
+
747
+ // // setColumns(aa)
748
+
749
+ // // table.setColumnSizing(aaa)
750
+
751
+ // requestAnimationFrame(() => {
752
+
753
+ // columnVirtualizer.measure()
754
+ // })
755
+
756
+ // // setColumnSizing?.(aaa)
757
+ // } else {
758
+ // if (columnHidden) {
759
+ // const abb = table.getVisibleLeafColumns()?.[0]
760
+
761
+ // if (abb && Object.keys(columnSizingInfo).length === 0
762
+ // ) {
763
+ // // setColumnSizing({ "#": abb.getSize() })
764
+ // table.setColumnSizing({ "#": abb.getSize() })
765
+
766
+ // requestAnimationFrame(() => {
767
+
768
+ // columnVirtualizer.measure()
769
+ // })
770
+ // }
771
+ // }
772
+
773
+ // }
774
+
775
+ // }, [table.getTotalSize(), dataSource.length, windowSize.innerWidth, columnVirtualizer])
751
776
 
752
777
  // React.useEffect(() => {
753
778
 
@@ -49,7 +49,7 @@ const TableBody = ({
49
49
  overscan: 1
50
50
  });
51
51
  const virtualRows = rowVirtualizer.getVirtualItems();
52
- return /*#__PURE__*/_react.default.createElement("tbody", {
52
+ return /*#__PURE__*/_react.default.createElement("div", {
53
53
  className: `${prefix}-grid-tbody`,
54
54
  style: {
55
55
  display: 'grid',
@@ -1,12 +1,16 @@
1
1
  import type { Cell, Table } from "@tanstack/react-table";
2
2
  import type { CommandClick } from "../type";
3
3
  import React from "react";
4
- import type { VirtualItem } from "@tanstack/react-virtual";
4
+ import type { VirtualItem, Virtualizer } from "@tanstack/react-virtual";
5
5
  interface TableBodyCellProps<T> {
6
+ table: Table<T>;
7
+ rowVirtualizer: Virtualizer<HTMLDivElement, HTMLDivElement>;
8
+ columnVirtualizer: Virtualizer<HTMLDivElement, HTMLDivElement>;
9
+ tableId: string;
6
10
  cell: Cell<T, unknown>;
7
11
  commandClick?: (args: CommandClick<T>) => void;
8
- table: Table<T>;
9
- virtualRow?: VirtualItem;
12
+ virtualRow: VirtualItem;
13
+ [key: string]: any;
10
14
  }
11
15
  declare const TableBodyCell: <RecordType extends object>(props: TableBodyCellProps<RecordType>) => React.JSX.Element;
12
16
  export default TableBodyCell;