es-grid-template 1.8.41 → 1.8.43

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.
@@ -37,7 +37,7 @@ getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayB
37
37
  // import GridEdit from './table/GridEdit'
38
38
  import { convertToTanStackColumns } from "./hook/useColumns";
39
39
  import { convertColumns } from "./hook/convert";
40
- import { Modal } from 'antd';
40
+ // import { Modal } from 'antd'
41
41
  // import { findAllChildrenKeys2 } from '../grid-component/hooks'
42
42
  // import { columns111 } from '../test-2/columns'
43
43
 
@@ -214,77 +214,6 @@ const InternalTable = props => {
214
214
  mergedSelectedKeys: mergedSelectedKeys,
215
215
  expandable: expandable,
216
216
  setColumns: setColumns
217
- })), /*#__PURE__*/React.createElement(Modal, {
218
- open: isFullScreen,
219
- footer: null,
220
- centered: true,
221
- closable: true,
222
- width: '100%',
223
- style: {
224
- maxWidth: '100%',
225
- height: '100%'
226
- }
227
- // onClose={() => setIsFullScreen(false)}
228
- ,
229
- onCancel: () => setIsFullScreen(false)
230
-
231
- // destroyOnClose
232
- ,
233
- styles: {
234
- content: {
235
- height: '100vh',
236
- borderRadius: 0,
237
- padding: '15px 10px'
238
- },
239
- wrapper: {
240
- zIndex: 1050
241
- }
242
- },
243
- destroyOnClose: true
244
- }, /*#__PURE__*/React.createElement("div", {
245
- style: {
246
- paddingTop: 40
247
- }
248
- }, /*#__PURE__*/React.createElement(Grid, _extends({}, rest, {
249
- t: t
250
- // id={isFullScreen ? faker.string.alpha(20) : id}
251
- ,
252
- id: faker.string.alpha(20),
253
- prefix: prefix,
254
- originData: convertData,
255
- dataSource: mergedData,
256
- locale: locale,
257
- format: format
258
- // columns={columns111 as any}
259
- ,
260
- columns: convertColumns(mergedColumns),
261
- propsColumns: columns,
262
- rowKey: rowKey,
263
- groupSetting: groupSetting,
264
- groupAble: groupAble,
265
- groupColumns: groupColumns,
266
- columnPinning: columnPinning,
267
- columnHidden: columnsHiddenKeys ? convertToObj(columnsHiddenKeys) : columnVisibility,
268
- triggerFilter: setFilterState,
269
- triggerSorter: setSorterStates,
270
- setMergedFilterKeys: setMergedFilterKeys,
271
- mergedFilterKeys: mergedFilterKeys,
272
- expanded: expanded
273
- // onContextMenu={onContextMenu}
274
- // contextMenuItems={contextMenuItems}
275
- ,
276
- editAble: editAble,
277
- triggerChangeColumns: triggerChangeColumns,
278
- setExpanded: setExpanded,
279
- isFullScreen: isFullScreen,
280
- setIsFullScreen: setIsFullScreen,
281
- height: windowSize.innerHeight - 70,
282
- windowSize: windowSize,
283
- isDataTree: isDataTree,
284
- selectionSettings: selectionSettings,
285
- mergedSelectedKeys: mergedSelectedKeys,
286
- expandable: expandable,
287
- setColumns: setColumns
288
- })))));
217
+ })));
289
218
  };
290
219
  export default InternalTable;
@@ -19,7 +19,7 @@ import { ColumnsChoose } from "./ColumnsChoose";
19
19
  import { numericFormatter } from 'react-numeric-component';
20
20
  // import ComponentSpinner from '../grid-component/LoadingSpinner'
21
21
  import TableWrapper from "./table/TableWrapper";
22
- import { sumSize, updateColumnWidthsRecursive } from "./hook/utils";
22
+ import { getTableHeight, sumSize, updateColumnWidthsRecursive } from "./hook/utils";
23
23
  import { useVirtualizer } from '@tanstack/react-virtual';
24
24
  const TableContainer = props => {
25
25
  const {
@@ -84,7 +84,8 @@ const TableContainer = props => {
84
84
  const [tableHeight, settableHeight] = React.useState(0);
85
85
  const [focusedCell, setFocusedCell] = React.useState(undefined);
86
86
  React.useEffect(() => {
87
- const totalHeight = minHeight ?? height;
87
+ // const totalHeight = minHeight ?? height
88
+ const totalHeight = getTableHeight(height, minHeight);
88
89
  if (totalHeight) {
89
90
  const topHeight = topToolbarRef.current ? topToolbarRef.current.offsetHeight : 0;
90
91
  const bottomHeight = bottomToolbarRef.current ? bottomToolbarRef.current.offsetHeight : 0;
@@ -24,7 +24,6 @@ type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
24
24
  setSorterChange: Dispatch<SetStateAction<boolean>>;
25
25
  setFilterChange: Dispatch<SetStateAction<boolean>>;
26
26
  onContextMenu?: (data: T) => (event: any) => void;
27
- tableHeight?: number;
28
27
  isDataTree: boolean;
29
28
  windowSize: {
30
29
  innerHeight: number;
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import React, { Fragment } from "react";
3
3
  import { useCopyToClipboard } from 'usehooks-ts';
4
- import { checkDecimalSeparator, checkThousandSeparator, detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween, getDefaultValue, getFormat, getRowIdsBetween, getSelectedCellMatrix, isEditable, isFormattedNumber, newGuid, parseExcelClipboardText, sumSize,
4
+ import { checkDecimalSeparator, checkThousandSeparator, detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween, getDefaultValue, getFormat, getRowIdsBetween, getSelectedCellMatrix, getTableHeight, isEditable, isFormattedNumber, newGuid, parseExcelClipboardText, sumSize,
5
5
  // sumSize,
6
6
  unFlattenData, updateArrayByKey, updateColumnWidthsRecursive, updateOrInsert } from "./hook/utils";
7
7
  import { useVirtualizer } from "@tanstack/react-virtual";
@@ -79,7 +79,6 @@ const TableContainerEdit = props => {
79
79
  contextMenuItems: propsContext,
80
80
  setSorterChange,
81
81
  setFilterChange,
82
- // tableHeight,
83
82
  onCellPaste,
84
83
  // triggerPaste,
85
84
  validate,
@@ -879,7 +878,8 @@ const TableContainerEdit = props => {
879
878
  // // }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
880
879
 
881
880
  React.useEffect(() => {
882
- const totalHeight = minHeight ?? height;
881
+ // const totalHeight = minHeight ?? height
882
+ const totalHeight = getTableHeight(height, minHeight);
883
883
  if (totalHeight) {
884
884
  const topHeight = topToolbarRef.current ? topToolbarRef.current.offsetHeight : 0;
885
885
  const bottomHeight = bottomToolbarRef.current ? bottomToolbarRef.current.offsetHeight : 0;
@@ -387,7 +387,7 @@ const TableBodyCellEdit = props => {
387
387
  colSelectIds.forEach(colId => {
388
388
  const cellll = row.getVisibleCells().find(c => c.column.id === colId);
389
389
  const value = cellll?.getValue();
390
- rowData.push(value !== undefined ? String(value) : '');
390
+ rowData.push(value !== undefined ? value : '');
391
391
  });
392
392
  dataSelected.push(rowData);
393
393
  });
@@ -404,12 +404,11 @@ const TableBodyCellEdit = props => {
404
404
  const targetRow = pasteState.startRowIndex + rowIndex1;
405
405
 
406
406
  // Nếu vượt quá số dòng hiện có, thêm dòng mới
407
- if (targetRow >= newData.length) {
408
- newData.push({
409
- id: undefined,
410
- rowId: newGuid()
411
- });
412
- }
407
+ // if (targetRow >= newData.length) {
408
+
409
+ // newData.push({ id: undefined, rowId: newGuid() })
410
+ // }
411
+
413
412
  rowValues.forEach((cellValue, colIndex1) => {
414
413
  const targetCol = startColIndex + colIndex1;
415
414
  if (targetCol >= tmpCols.length) {
@@ -5,6 +5,16 @@ import TableHeadCell2 from "./TableHeadCell2";
5
5
  import TableHeadGroupCell from "./TableHeadGroupCell";
6
6
  // import { getCommonPinningStyles } from '../hook/utils'
7
7
 
8
+ // const getVisibleChildCount = <T,>(column: Column<T>): number => {
9
+ // if (!column.columns?.length) return 0;
10
+
11
+ // return column.columns.reduce((count: number, col: Column<T>) => {
12
+ // const selfCount = col.getIsVisible() ? 1 : 0;
13
+ // const childrenCount = getVisibleChildCount(col);
14
+ // return count + selfCount + (childrenCount ? childrenCount - 1 : childrenCount);
15
+ // }, 0);
16
+ // }
17
+
8
18
  const TableHead = ({
9
19
  columnVirtualizer,
10
20
  table
@@ -18,6 +28,7 @@ const TableHead = ({
18
28
  } = useContext(TableContext);
19
29
  const headerGroups = table.getFlatHeaders();
20
30
  const leafColumns = table.getVisibleFlatColumns();
31
+ // const leafColumns11 = table.getIsAllColumnsVisible();
21
32
  const headerDepth = table.getHeaderGroups().length;
22
33
  return /*#__PURE__*/React.createElement("div", {
23
34
  className: `${prefix}-grid-thead`,
@@ -32,8 +43,11 @@ const TableHead = ({
32
43
  }
33
44
  }, leafColumns.map(column => {
34
45
  const depth = column.depth ?? 0;
35
- // const colSpan = col.getLeafColumns().length || 1;
36
- const colSpan = column.columns.length || 1;
46
+
47
+ // const colSpan = column.columns.length || 1;
48
+ const colSpan = column.getFlatColumns().filter(col => col.getIsVisible() && col.columns.length < 1).length;
49
+ // const colSpan = getVisibleChildCount(column);
50
+
37
51
  const rowSpan = column.columns?.length > 0 ? 1 : headerDepth - depth;
38
52
  const header = headerGroups.find(it => it.id === column.id || it.column.id === column.id && it.subHeaders.length > 0);
39
53
  // const groupHeader = headerGroups.find((it) => it.column.id === column.id && it.subHeaders.length >= 2)
@@ -141,7 +141,7 @@ export function convertToTanStackColumns({
141
141
  }
142
142
  },
143
143
  enableResizing: allowResizing !== false,
144
- enableHiding: false,
144
+ // enableHiding: false,
145
145
  // enableResizing: true,
146
146
  id: field,
147
147
  size: width,
@@ -263,8 +263,6 @@ export const toggleRowSelection = props => {
263
263
  let checkedRows = [];
264
264
  const rowParent = row.getParentRow();
265
265
 
266
- // console.log(countUnselectedChildren(row))
267
-
268
266
  // nếu có cha và cha chưa được chọn và tất cả con đã chọn => thêm row cha vào
269
267
  if (rowParent && !rowParent.getIsSelected() && countUnselectedChildren(row) === 1) {
270
268
  rowParent.toggleSelected(!rowParent.getIsSelected());
@@ -152,3 +152,4 @@ export declare function getAllChildren(row: any): any;
152
152
  export declare function toggleRowAndChildren(row: Row<any>, isSelected?: boolean): void;
153
153
  export declare function countUnselectedChildren(row: Row<any>): number;
154
154
  export declare function removeDuplicatesByKey(arr: any[], key?: string): any[];
155
+ export declare const getTableHeight: (height?: number, minHeight?: number) => number;
@@ -1680,13 +1680,30 @@ export const convertFilters = filters => {
1680
1680
  });
1681
1681
  return result;
1682
1682
  };
1683
+
1684
+ // export function getInvisibleColumns(columns: ColumnTable[]): Record<string, boolean> {
1685
+ // const result: Record<string, boolean> = {};
1686
+ // for (const col of columns) {
1687
+ // if (col.visible === false || col.hidden) {
1688
+ // result[col.field ?? ''] = false;
1689
+ // }
1690
+ // }
1691
+ // return result;
1692
+ // }
1693
+
1683
1694
  export function getInvisibleColumns(columns) {
1684
1695
  const result = {};
1685
- for (const col of columns) {
1686
- if (col.visible === false || col.hidden) {
1687
- result[col.field ?? ''] = false;
1696
+ function traverse(cols) {
1697
+ for (const col of cols) {
1698
+ if (col.visible === false) {
1699
+ result[col.field ?? ''] = false;
1700
+ }
1701
+ if (col.children && col.children.length > 0) {
1702
+ traverse(col.children);
1703
+ }
1688
1704
  }
1689
1705
  }
1706
+ traverse(columns);
1690
1707
  return result;
1691
1708
  }
1692
1709
  export const getAllVisibleKeys = columns => {
@@ -1746,7 +1763,7 @@ export function getHiddenParentKeys1(columns, parentKeys = []) {
1746
1763
  for (const column of columns) {
1747
1764
  if (column.children) {
1748
1765
  const currentPath = column.field ? [...parentKeys, column.field] : [...parentKeys];
1749
- const childHiddenParents = getHiddenParentKeys(column.children, currentPath);
1766
+ const childHiddenParents = getHiddenParentKeys1(column.children, currentPath);
1750
1767
  if (childHiddenParents.length > 0) {
1751
1768
  childHiddenParents.forEach(key => hiddenParents.add(key));
1752
1769
  currentPath.forEach(key => hiddenParents.add(key));
@@ -1971,7 +1988,6 @@ export function findFirst(items) {
1971
1988
 
1972
1989
  // // if (requireNonEmpty) {
1973
1990
 
1974
- // // console.log('requireNonEmpty', requireNonEmpty)
1975
1991
  // // if (children.length > 0) {
1976
1992
  // // hasParent = true
1977
1993
  // // }
@@ -2232,4 +2248,22 @@ export function removeDuplicatesByKey(arr, key = 'id') {
2232
2248
  }
2233
2249
  }
2234
2250
  return Array.from(map.values());
2235
- }
2251
+ }
2252
+ export const getTableHeight = (height, minHeight) => {
2253
+ if (height && !minHeight) {
2254
+ return height;
2255
+ }
2256
+ if (minHeight && !height) {
2257
+ return minHeight;
2258
+ }
2259
+ if (minHeight && height) {
2260
+ return Math.max(minHeight, height);
2261
+ // if (height > minHeight) {
2262
+ // return height
2263
+ // }
2264
+
2265
+ // if (minHeight > height) {
2266
+ // return minHeight
2267
+ // }
2268
+ }
2269
+ };
@@ -1,4 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { Modal } from 'antd';
3
+ import { faker } from '@faker-js/faker';
2
4
  import { getCoreRowModel, getExpandedRowModel,
3
5
  // getFilteredRowModel,
4
6
  getGroupedRowModel, getPaginationRowModel,
@@ -14,7 +16,7 @@ import { arrayMove } from '@dnd-kit/sortable';
14
16
 
15
17
  // import { faker } from '@faker-js/faker'
16
18
 
17
- import React from 'react';
19
+ import React, { Fragment } from 'react';
18
20
  import TableContainer from "../TableContainer";
19
21
  import { OperatorFeature } from "../features/operator";
20
22
  import { convertFilters, convertToObjTrue, filterByIds, filterDataByColumns, getAllRowKey, isObjEqual } from "../hook/utils";
@@ -53,6 +55,7 @@ const Grid = props => {
53
55
  infiniteScroll,
54
56
  mergedSelectedKeys,
55
57
  allowResizing,
58
+ windowSize,
56
59
  ...rest
57
60
  } = props;
58
61
  const [columnResizeMode] = React.useState('onChange');
@@ -86,6 +89,7 @@ const Grid = props => {
86
89
  });
87
90
  const [sorterChange, setSorterChange] = React.useState(false);
88
91
  const [filterChange, setFilterChange] = React.useState(false);
92
+ const [isFullScreen, setIsFullScreen] = React.useState(false);
89
93
  const table = useReactTable({
90
94
  _features: [OperatorFeature],
91
95
  data: dataSource,
@@ -274,7 +278,7 @@ const Grid = props => {
274
278
  }
275
279
  const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}));
276
280
  const ContainerComponent = editAble ? TableContainerEdit : TableContainer;
277
- return /*#__PURE__*/React.createElement("div", {
281
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
278
282
  className: `${prefix}-grid`,
279
283
  style: {
280
284
  minHeight: minHeight ?? undefined,
@@ -288,6 +292,7 @@ const Grid = props => {
288
292
  }, /*#__PURE__*/React.createElement(ContainerComponent, _extends({}, rest, {
289
293
  id: id,
290
294
  t: t,
295
+ windowSize: windowSize,
291
296
  table: table,
292
297
  editAble: editAble,
293
298
  dataSource: dataSource,
@@ -298,7 +303,7 @@ const Grid = props => {
298
303
  setIsSelectionChange: setIsSelectionChange,
299
304
  setSorterChange: setSorterChange,
300
305
  setFilterChange: setFilterChange,
301
- height: minHeight ?? height ?? 700,
306
+ height: height ?? minHeight ?? 700,
302
307
  minHeight: minHeight,
303
308
  pagination: pagination,
304
309
  columns: columns,
@@ -312,7 +317,82 @@ const Grid = props => {
312
317
  setColumnSizing: setColumnSizing,
313
318
  setColumns: setColumns,
314
319
  columnSizing: columnSizing,
315
- columnSizingInfo: columnSizingInfo
316
- }))));
320
+ columnSizingInfo: columnSizingInfo,
321
+ isFullScreen: isFullScreen,
322
+ setIsFullScreen: setIsFullScreen
323
+ })))), /*#__PURE__*/React.createElement(Modal, {
324
+ open: isFullScreen,
325
+ footer: null,
326
+ centered: true,
327
+ closable: true,
328
+ width: '100%',
329
+ style: {
330
+ maxWidth: '100%',
331
+ height: '100%'
332
+ }
333
+ // onClose={() => setIsFullScreen(false)}
334
+ ,
335
+ onCancel: () => setIsFullScreen(false)
336
+
337
+ // destroyOnClose
338
+ ,
339
+ styles: {
340
+ content: {
341
+ height: '100vh',
342
+ borderRadius: 0,
343
+ padding: '15px 10px'
344
+ },
345
+ wrapper: {
346
+ zIndex: 1050
347
+ }
348
+ },
349
+ destroyOnClose: true
350
+ }, /*#__PURE__*/React.createElement("div", {
351
+ style: {
352
+ paddingTop: 40
353
+ }
354
+ }, /*#__PURE__*/React.createElement("div", {
355
+ className: `${prefix}-grid`,
356
+ style: {
357
+ // minHeight: minHeight ?? undefined,
358
+ maxHeight: windowSize.innerHeight - 70
359
+ }
360
+ }, /*#__PURE__*/React.createElement(DndContext, {
361
+ collisionDetection: closestCenter,
362
+ modifiers: [restrictToHorizontalAxis],
363
+ onDragEnd: handleDragEnd,
364
+ sensors: sensors
365
+ }, /*#__PURE__*/React.createElement(ContainerComponent, _extends({}, rest, {
366
+ id: faker.string.alpha(20),
367
+ t: t,
368
+ table: table,
369
+ editAble: editAble,
370
+ dataSource: dataSource,
371
+ originData: originData,
372
+ prefix: prefix,
373
+ selectionSettings: selectionSettings,
374
+ isSelectionChange: isSelectionChange,
375
+ setIsSelectionChange: setIsSelectionChange,
376
+ setSorterChange: setSorterChange,
377
+ setFilterChange: setFilterChange,
378
+ height: windowSize.innerHeight - 70,
379
+ minHeight: minHeight,
380
+ pagination: pagination,
381
+ columns: columns,
382
+ windowSize: windowSize,
383
+ propsColumns: propsColumns,
384
+ triggerChangeColumns: triggerChangeColumns,
385
+ columnHidden: columnHidden,
386
+ setExpanded: setExpanded,
387
+ expanded: expanded,
388
+ infiniteScroll: infiniteScroll,
389
+ setMergedFilterKeys: setMergedFilterKeys,
390
+ setColumnSizing: setColumnSizing,
391
+ setColumns: setColumns,
392
+ columnSizing: columnSizing,
393
+ columnSizingInfo: columnSizingInfo,
394
+ isFullScreen: isFullScreen,
395
+ setIsFullScreen: setIsFullScreen
396
+ })))))));
317
397
  };
318
398
  export default Grid;
@@ -180,10 +180,10 @@ const TableWrapper = props => {
180
180
  //our scrollable table container
181
181
  position: 'relative',
182
182
  //needed for sticky header
183
- // height: tableHeight ?? '500px' //should be a fixed height
183
+ // height: height, //should be a fixed height
184
184
  maxHeight: height,
185
185
  //should be a fixed height
186
- height: minHeight ? height : undefined //should be a fixed height
186
+ minHeight: minHeight ? height : undefined //should be a fixed height
187
187
  // minWidth: table.getTotalSize()
188
188
  }
189
189
  // onScroll={infiniteScroll ? handleScroll : undefined}
@@ -19,7 +19,6 @@ var _Grid = _interopRequireDefault(require("./table/Grid"));
19
19
  var _utils = require("./hook/utils");
20
20
  var _useColumns = require("./hook/useColumns");
21
21
  var _convert = require("./hook/convert");
22
- var _antd = require("antd");
23
22
  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); }
24
23
  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; }
25
24
  // import en from "rc-master-ui/es/date-picker/locale/en_US"
@@ -44,6 +43,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
44
43
 
45
44
  // import GridEdit from './table/GridEdit'
46
45
 
46
+ // import { Modal } from 'antd'
47
47
  // import { findAllChildrenKeys2 } from '../grid-component/hooks'
48
48
  // import { columns111 } from '../test-2/columns'
49
49
 
@@ -220,77 +220,6 @@ const InternalTable = props => {
220
220
  mergedSelectedKeys: mergedSelectedKeys,
221
221
  expandable: expandable,
222
222
  setColumns: setColumns
223
- })), /*#__PURE__*/_react.default.createElement(_antd.Modal, {
224
- open: isFullScreen,
225
- footer: null,
226
- centered: true,
227
- closable: true,
228
- width: '100%',
229
- style: {
230
- maxWidth: '100%',
231
- height: '100%'
232
- }
233
- // onClose={() => setIsFullScreen(false)}
234
- ,
235
- onCancel: () => setIsFullScreen(false)
236
-
237
- // destroyOnClose
238
- ,
239
- styles: {
240
- content: {
241
- height: '100vh',
242
- borderRadius: 0,
243
- padding: '15px 10px'
244
- },
245
- wrapper: {
246
- zIndex: 1050
247
- }
248
- },
249
- destroyOnClose: true
250
- }, /*#__PURE__*/_react.default.createElement("div", {
251
- style: {
252
- paddingTop: 40
253
- }
254
- }, /*#__PURE__*/_react.default.createElement(_Grid.default, (0, _extends2.default)({}, rest, {
255
- t: t
256
- // id={isFullScreen ? faker.string.alpha(20) : id}
257
- ,
258
- id: _faker.faker.string.alpha(20),
259
- prefix: prefix,
260
- originData: convertData,
261
- dataSource: mergedData,
262
- locale: locale,
263
- format: format
264
- // columns={columns111 as any}
265
- ,
266
- columns: (0, _convert.convertColumns)(mergedColumns),
267
- propsColumns: columns,
268
- rowKey: rowKey,
269
- groupSetting: groupSetting,
270
- groupAble: groupAble,
271
- groupColumns: groupColumns,
272
- columnPinning: columnPinning,
273
- columnHidden: columnsHiddenKeys ? (0, _utils.convertToObj)(columnsHiddenKeys) : columnVisibility,
274
- triggerFilter: setFilterState,
275
- triggerSorter: setSorterStates,
276
- setMergedFilterKeys: setMergedFilterKeys,
277
- mergedFilterKeys: mergedFilterKeys,
278
- expanded: expanded
279
- // onContextMenu={onContextMenu}
280
- // contextMenuItems={contextMenuItems}
281
- ,
282
- editAble: editAble,
283
- triggerChangeColumns: triggerChangeColumns,
284
- setExpanded: setExpanded,
285
- isFullScreen: isFullScreen,
286
- setIsFullScreen: setIsFullScreen,
287
- height: windowSize.innerHeight - 70,
288
- windowSize: windowSize,
289
- isDataTree: isDataTree,
290
- selectionSettings: selectionSettings,
291
- mergedSelectedKeys: mergedSelectedKeys,
292
- expandable: expandable,
293
- setColumns: setColumns
294
- })))));
223
+ })));
295
224
  };
296
225
  var _default = exports.default = InternalTable;
@@ -94,7 +94,8 @@ const TableContainer = props => {
94
94
  const [tableHeight, settableHeight] = _react.default.useState(0);
95
95
  const [focusedCell, setFocusedCell] = _react.default.useState(undefined);
96
96
  _react.default.useEffect(() => {
97
- const totalHeight = minHeight ?? height;
97
+ // const totalHeight = minHeight ?? height
98
+ const totalHeight = (0, _utils.getTableHeight)(height, minHeight);
98
99
  if (totalHeight) {
99
100
  const topHeight = topToolbarRef.current ? topToolbarRef.current.offsetHeight : 0;
100
101
  const bottomHeight = bottomToolbarRef.current ? bottomToolbarRef.current.offsetHeight : 0;
@@ -24,7 +24,6 @@ type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
24
24
  setSorterChange: Dispatch<SetStateAction<boolean>>;
25
25
  setFilterChange: Dispatch<SetStateAction<boolean>>;
26
26
  onContextMenu?: (data: T) => (event: any) => void;
27
- tableHeight?: number;
28
27
  isDataTree: boolean;
29
28
  windowSize: {
30
29
  innerHeight: number;
@@ -86,7 +86,6 @@ const TableContainerEdit = props => {
86
86
  contextMenuItems: propsContext,
87
87
  setSorterChange,
88
88
  setFilterChange,
89
- // tableHeight,
90
89
  onCellPaste,
91
90
  // triggerPaste,
92
91
  validate,
@@ -886,7 +885,8 @@ const TableContainerEdit = props => {
886
885
  // // }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
887
886
 
888
887
  _react.default.useEffect(() => {
889
- const totalHeight = minHeight ?? height;
888
+ // const totalHeight = minHeight ?? height
889
+ const totalHeight = (0, _utils.getTableHeight)(height, minHeight);
890
890
  if (totalHeight) {
891
891
  const topHeight = topToolbarRef.current ? topToolbarRef.current.offsetHeight : 0;
892
892
  const bottomHeight = bottomToolbarRef.current ? bottomToolbarRef.current.offsetHeight : 0;
@@ -393,7 +393,7 @@ const TableBodyCellEdit = props => {
393
393
  colSelectIds.forEach(colId => {
394
394
  const cellll = row.getVisibleCells().find(c => c.column.id === colId);
395
395
  const value = cellll?.getValue();
396
- rowData.push(value !== undefined ? String(value) : '');
396
+ rowData.push(value !== undefined ? value : '');
397
397
  });
398
398
  dataSelected.push(rowData);
399
399
  });
@@ -410,12 +410,11 @@ const TableBodyCellEdit = props => {
410
410
  const targetRow = pasteState.startRowIndex + rowIndex1;
411
411
 
412
412
  // Nếu vượt quá số dòng hiện có, thêm dòng mới
413
- if (targetRow >= newData.length) {
414
- newData.push({
415
- id: undefined,
416
- rowId: (0, _utils.newGuid)()
417
- });
418
- }
413
+ // if (targetRow >= newData.length) {
414
+
415
+ // newData.push({ id: undefined, rowId: newGuid() })
416
+ // }
417
+
419
418
  rowValues.forEach((cellValue, colIndex1) => {
420
419
  const targetCol = startColIndex + colIndex1;
421
420
  if (targetCol >= tmpCols.length) {
@@ -15,6 +15,16 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
15
15
 
16
16
  // import { getCommonPinningStyles } from '../hook/utils'
17
17
 
18
+ // const getVisibleChildCount = <T,>(column: Column<T>): number => {
19
+ // if (!column.columns?.length) return 0;
20
+
21
+ // return column.columns.reduce((count: number, col: Column<T>) => {
22
+ // const selfCount = col.getIsVisible() ? 1 : 0;
23
+ // const childrenCount = getVisibleChildCount(col);
24
+ // return count + selfCount + (childrenCount ? childrenCount - 1 : childrenCount);
25
+ // }, 0);
26
+ // }
27
+
18
28
  const TableHead = ({
19
29
  columnVirtualizer,
20
30
  table
@@ -28,6 +38,7 @@ const TableHead = ({
28
38
  } = (0, _react.useContext)(_useContext.TableContext);
29
39
  const headerGroups = table.getFlatHeaders();
30
40
  const leafColumns = table.getVisibleFlatColumns();
41
+ // const leafColumns11 = table.getIsAllColumnsVisible();
31
42
  const headerDepth = table.getHeaderGroups().length;
32
43
  return /*#__PURE__*/_react.default.createElement("div", {
33
44
  className: `${prefix}-grid-thead`,
@@ -42,8 +53,11 @@ const TableHead = ({
42
53
  }
43
54
  }, leafColumns.map(column => {
44
55
  const depth = column.depth ?? 0;
45
- // const colSpan = col.getLeafColumns().length || 1;
46
- const colSpan = column.columns.length || 1;
56
+
57
+ // const colSpan = column.columns.length || 1;
58
+ const colSpan = column.getFlatColumns().filter(col => col.getIsVisible() && col.columns.length < 1).length;
59
+ // const colSpan = getVisibleChildCount(column);
60
+
47
61
  const rowSpan = column.columns?.length > 0 ? 1 : headerDepth - depth;
48
62
  const header = headerGroups.find(it => it.id === column.id || it.column.id === column.id && it.subHeaders.length > 0);
49
63
  // const groupHeader = headerGroups.find((it) => it.column.id === column.id && it.subHeaders.length >= 2)
@@ -152,7 +152,7 @@ function convertToTanStackColumns({
152
152
  }
153
153
  },
154
154
  enableResizing: allowResizing !== false,
155
- enableHiding: false,
155
+ // enableHiding: false,
156
156
  // enableResizing: true,
157
157
  id: field,
158
158
  size: width,
@@ -274,8 +274,6 @@ const toggleRowSelection = props => {
274
274
  let checkedRows = [];
275
275
  const rowParent = row.getParentRow();
276
276
 
277
- // console.log(countUnselectedChildren(row))
278
-
279
277
  // nếu có cha và cha chưa được chọn và tất cả con đã chọn => thêm row cha vào
280
278
  if (rowParent && !rowParent.getIsSelected() && (0, _utils.countUnselectedChildren)(row) === 1) {
281
279
  rowParent.toggleSelected(!rowParent.getIsSelected());
@@ -152,3 +152,4 @@ export declare function getAllChildren(row: any): any;
152
152
  export declare function toggleRowAndChildren(row: Row<any>, isSelected?: boolean): void;
153
153
  export declare function countUnselectedChildren(row: Row<any>): number;
154
154
  export declare function removeDuplicatesByKey(arr: any[], key?: string): any[];
155
+ export declare const getTableHeight: (height?: number, minHeight?: number) => number;
@@ -39,7 +39,7 @@ exports.getHiddenParentKeys1 = getHiddenParentKeys1;
39
39
  exports.getInvisibleColumns = getInvisibleColumns;
40
40
  exports.getNewItemsOnly = exports.getLastSelectCell = void 0;
41
41
  exports.getRowIdsBetween = getRowIdsBetween;
42
- exports.getVisibleColumnKeys1 = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getSelectedCellMatrix = void 0;
42
+ exports.getVisibleColumnKeys1 = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTableHeight = exports.getSelectedCellMatrix = void 0;
43
43
  exports.groupArrayByColumns = groupArrayByColumns;
44
44
  exports.isColor = void 0;
45
45
  exports.isDateString = isDateString;
@@ -1793,14 +1793,30 @@ const convertFilters = filters => {
1793
1793
  });
1794
1794
  return result;
1795
1795
  };
1796
+
1797
+ // export function getInvisibleColumns(columns: ColumnTable[]): Record<string, boolean> {
1798
+ // const result: Record<string, boolean> = {};
1799
+ // for (const col of columns) {
1800
+ // if (col.visible === false || col.hidden) {
1801
+ // result[col.field ?? ''] = false;
1802
+ // }
1803
+ // }
1804
+ // return result;
1805
+ // }
1796
1806
  exports.convertFilters = convertFilters;
1797
1807
  function getInvisibleColumns(columns) {
1798
1808
  const result = {};
1799
- for (const col of columns) {
1800
- if (col.visible === false || col.hidden) {
1801
- result[col.field ?? ''] = false;
1809
+ function traverse(cols) {
1810
+ for (const col of cols) {
1811
+ if (col.visible === false) {
1812
+ result[col.field ?? ''] = false;
1813
+ }
1814
+ if (col.children && col.children.length > 0) {
1815
+ traverse(col.children);
1816
+ }
1802
1817
  }
1803
1818
  }
1819
+ traverse(columns);
1804
1820
  return result;
1805
1821
  }
1806
1822
  const getAllVisibleKeys = columns => {
@@ -1862,7 +1878,7 @@ function getHiddenParentKeys1(columns, parentKeys = []) {
1862
1878
  for (const column of columns) {
1863
1879
  if (column.children) {
1864
1880
  const currentPath = column.field ? [...parentKeys, column.field] : [...parentKeys];
1865
- const childHiddenParents = getHiddenParentKeys(column.children, currentPath);
1881
+ const childHiddenParents = getHiddenParentKeys1(column.children, currentPath);
1866
1882
  if (childHiddenParents.length > 0) {
1867
1883
  childHiddenParents.forEach(key => hiddenParents.add(key));
1868
1884
  currentPath.forEach(key => hiddenParents.add(key));
@@ -2093,7 +2109,6 @@ function findFirst(items) {
2093
2109
 
2094
2110
  // // if (requireNonEmpty) {
2095
2111
 
2096
- // // console.log('requireNonEmpty', requireNonEmpty)
2097
2112
  // // if (children.length > 0) {
2098
2113
  // // hasParent = true
2099
2114
  // // }
@@ -2354,4 +2369,23 @@ function removeDuplicatesByKey(arr, key = 'id') {
2354
2369
  }
2355
2370
  }
2356
2371
  return Array.from(map.values());
2357
- }
2372
+ }
2373
+ const getTableHeight = (height, minHeight) => {
2374
+ if (height && !minHeight) {
2375
+ return height;
2376
+ }
2377
+ if (minHeight && !height) {
2378
+ return minHeight;
2379
+ }
2380
+ if (minHeight && height) {
2381
+ return Math.max(minHeight, height);
2382
+ // if (height > minHeight) {
2383
+ // return height
2384
+ // }
2385
+
2386
+ // if (minHeight > height) {
2387
+ // return minHeight
2388
+ // }
2389
+ }
2390
+ };
2391
+ exports.getTableHeight = getTableHeight;
@@ -6,15 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _antd = require("antd");
10
+ var _faker = require("@faker-js/faker");
9
11
  var _reactTable = require("@tanstack/react-table");
10
12
  var _core = require("@dnd-kit/core");
11
13
  var _modifiers = require("@dnd-kit/modifiers");
12
14
  var _sortable = require("@dnd-kit/sortable");
13
- var _react = _interopRequireDefault(require("react"));
15
+ var _react = _interopRequireWildcard(require("react"));
14
16
  var _TableContainer = _interopRequireDefault(require("../TableContainer"));
15
17
  var _operator = require("../features/operator");
16
18
  var _utils = require("../hook/utils");
17
19
  var _TableContainerEdit = _interopRequireDefault(require("../TableContainerEdit"));
20
+ 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); }
21
+ 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
22
  // import { makeData } from "../default/makeData";
19
23
 
20
24
  // import { flattenArray, getFixedFields, getInvisibleColumns, unFlattenData, updateOrInsert } from './hook/utils'
@@ -55,6 +59,7 @@ const Grid = props => {
55
59
  infiniteScroll,
56
60
  mergedSelectedKeys,
57
61
  allowResizing,
62
+ windowSize,
58
63
  ...rest
59
64
  } = props;
60
65
  const [columnResizeMode] = _react.default.useState('onChange');
@@ -88,6 +93,7 @@ const Grid = props => {
88
93
  });
89
94
  const [sorterChange, setSorterChange] = _react.default.useState(false);
90
95
  const [filterChange, setFilterChange] = _react.default.useState(false);
96
+ const [isFullScreen, setIsFullScreen] = _react.default.useState(false);
91
97
  const table = (0, _reactTable.useReactTable)({
92
98
  _features: [_operator.OperatorFeature],
93
99
  data: dataSource,
@@ -276,7 +282,7 @@ const Grid = props => {
276
282
  }
277
283
  const sensors = (0, _core.useSensors)((0, _core.useSensor)(_core.MouseSensor, {}), (0, _core.useSensor)(_core.TouchSensor, {}), (0, _core.useSensor)(_core.KeyboardSensor, {}));
278
284
  const ContainerComponent = editAble ? _TableContainerEdit.default : _TableContainer.default;
279
- return /*#__PURE__*/_react.default.createElement("div", {
285
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
280
286
  className: `${prefix}-grid`,
281
287
  style: {
282
288
  minHeight: minHeight ?? undefined,
@@ -290,6 +296,7 @@ const Grid = props => {
290
296
  }, /*#__PURE__*/_react.default.createElement(ContainerComponent, (0, _extends2.default)({}, rest, {
291
297
  id: id,
292
298
  t: t,
299
+ windowSize: windowSize,
293
300
  table: table,
294
301
  editAble: editAble,
295
302
  dataSource: dataSource,
@@ -300,7 +307,7 @@ const Grid = props => {
300
307
  setIsSelectionChange: setIsSelectionChange,
301
308
  setSorterChange: setSorterChange,
302
309
  setFilterChange: setFilterChange,
303
- height: minHeight ?? height ?? 700,
310
+ height: height ?? minHeight ?? 700,
304
311
  minHeight: minHeight,
305
312
  pagination: pagination,
306
313
  columns: columns,
@@ -314,7 +321,82 @@ const Grid = props => {
314
321
  setColumnSizing: setColumnSizing,
315
322
  setColumns: setColumns,
316
323
  columnSizing: columnSizing,
317
- columnSizingInfo: columnSizingInfo
318
- }))));
324
+ columnSizingInfo: columnSizingInfo,
325
+ isFullScreen: isFullScreen,
326
+ setIsFullScreen: setIsFullScreen
327
+ })))), /*#__PURE__*/_react.default.createElement(_antd.Modal, {
328
+ open: isFullScreen,
329
+ footer: null,
330
+ centered: true,
331
+ closable: true,
332
+ width: '100%',
333
+ style: {
334
+ maxWidth: '100%',
335
+ height: '100%'
336
+ }
337
+ // onClose={() => setIsFullScreen(false)}
338
+ ,
339
+ onCancel: () => setIsFullScreen(false)
340
+
341
+ // destroyOnClose
342
+ ,
343
+ styles: {
344
+ content: {
345
+ height: '100vh',
346
+ borderRadius: 0,
347
+ padding: '15px 10px'
348
+ },
349
+ wrapper: {
350
+ zIndex: 1050
351
+ }
352
+ },
353
+ destroyOnClose: true
354
+ }, /*#__PURE__*/_react.default.createElement("div", {
355
+ style: {
356
+ paddingTop: 40
357
+ }
358
+ }, /*#__PURE__*/_react.default.createElement("div", {
359
+ className: `${prefix}-grid`,
360
+ style: {
361
+ // minHeight: minHeight ?? undefined,
362
+ maxHeight: windowSize.innerHeight - 70
363
+ }
364
+ }, /*#__PURE__*/_react.default.createElement(_core.DndContext, {
365
+ collisionDetection: _core.closestCenter,
366
+ modifiers: [_modifiers.restrictToHorizontalAxis],
367
+ onDragEnd: handleDragEnd,
368
+ sensors: sensors
369
+ }, /*#__PURE__*/_react.default.createElement(ContainerComponent, (0, _extends2.default)({}, rest, {
370
+ id: _faker.faker.string.alpha(20),
371
+ t: t,
372
+ table: table,
373
+ editAble: editAble,
374
+ dataSource: dataSource,
375
+ originData: originData,
376
+ prefix: prefix,
377
+ selectionSettings: selectionSettings,
378
+ isSelectionChange: isSelectionChange,
379
+ setIsSelectionChange: setIsSelectionChange,
380
+ setSorterChange: setSorterChange,
381
+ setFilterChange: setFilterChange,
382
+ height: windowSize.innerHeight - 70,
383
+ minHeight: minHeight,
384
+ pagination: pagination,
385
+ columns: columns,
386
+ windowSize: windowSize,
387
+ propsColumns: propsColumns,
388
+ triggerChangeColumns: triggerChangeColumns,
389
+ columnHidden: columnHidden,
390
+ setExpanded: setExpanded,
391
+ expanded: expanded,
392
+ infiniteScroll: infiniteScroll,
393
+ setMergedFilterKeys: setMergedFilterKeys,
394
+ setColumnSizing: setColumnSizing,
395
+ setColumns: setColumns,
396
+ columnSizing: columnSizing,
397
+ columnSizingInfo: columnSizingInfo,
398
+ isFullScreen: isFullScreen,
399
+ setIsFullScreen: setIsFullScreen
400
+ })))))));
319
401
  };
320
402
  var _default = exports.default = Grid;
@@ -189,10 +189,10 @@ const TableWrapper = props => {
189
189
  //our scrollable table container
190
190
  position: 'relative',
191
191
  //needed for sticky header
192
- // height: tableHeight ?? '500px' //should be a fixed height
192
+ // height: height, //should be a fixed height
193
193
  maxHeight: height,
194
194
  //should be a fixed height
195
- height: minHeight ? height : undefined //should be a fixed height
195
+ minHeight: minHeight ? height : undefined //should be a fixed height
196
196
  // minWidth: table.getTotalSize()
197
197
  }
198
198
  // onScroll={infiniteScroll ? handleScroll : undefined}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.8.41",
3
+ "version": "1.8.43",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",