es-grid-template 1.4.0 → 1.4.2

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 (33) hide show
  1. package/es/grid-component/EditableCell.js +46 -15
  2. package/es/grid-component/InternalTable.d.ts +1 -0
  3. package/es/grid-component/InternalTable.js +469 -113
  4. package/es/grid-component/TableGrid.js +46 -48
  5. package/es/grid-component/hooks/columns/index.d.ts +1 -1
  6. package/es/grid-component/hooks/columns/index.js +3 -13
  7. package/es/grid-component/hooks/useColumns.js +5 -2
  8. package/es/grid-component/hooks/utils.d.ts +17 -2
  9. package/es/grid-component/hooks/utils.js +24 -5
  10. package/es/grid-component/styles.scss +1186 -1170
  11. package/es/grid-component/table/Grid.d.ts +1 -0
  12. package/es/grid-component/table/GridEdit.d.ts +1 -0
  13. package/es/grid-component/table/GridEdit.js +190 -140
  14. package/es/grid-component/table/Group.d.ts +1 -0
  15. package/es/grid-component/type.d.ts +7 -2
  16. package/es/grid-component/useContext.d.ts +1 -0
  17. package/lib/grid-component/EditableCell.js +46 -15
  18. package/lib/grid-component/InternalTable.d.ts +1 -0
  19. package/lib/grid-component/InternalTable.js +469 -102
  20. package/lib/grid-component/TableGrid.js +45 -47
  21. package/lib/grid-component/hooks/columns/index.d.ts +1 -1
  22. package/lib/grid-component/hooks/columns/index.js +5 -15
  23. package/lib/grid-component/hooks/useColumns.js +4 -1
  24. package/lib/grid-component/hooks/utils.d.ts +17 -2
  25. package/lib/grid-component/hooks/utils.js +26 -6
  26. package/lib/grid-component/styles.scss +1186 -1170
  27. package/lib/grid-component/table/Grid.d.ts +1 -0
  28. package/lib/grid-component/table/GridEdit.d.ts +1 -0
  29. package/lib/grid-component/table/GridEdit.js +189 -139
  30. package/lib/grid-component/table/Group.d.ts +1 -0
  31. package/lib/grid-component/type.d.ts +7 -2
  32. package/lib/grid-component/useContext.d.ts +1 -0
  33. package/package.json +5 -5
@@ -355,9 +355,7 @@ const TableGrid = props => {
355
355
  }), /*#__PURE__*/_react.default.createElement(_rcMasterUi.Table, (0, _extends2.default)({
356
356
  ref: tableRef
357
357
  }, rest, {
358
- tableLayout: 'fixed'
359
- // id={newGuid()}
360
- ,
358
+ tableLayout: 'fixed',
361
359
  locale: {
362
360
  ...locale,
363
361
  emptyText: showEmptyText !== false ? /*#__PURE__*/_react.default.createElement(_rcMasterUi.Empty, {
@@ -371,10 +369,7 @@ const TableGrid = props => {
371
369
  }
372
370
  // dataSource={columns && columns.length > 0 ? filterDataByColumns3(dataSource, filterStates) : []}
373
371
  ,
374
- dataSource: columns && columns.length > 0 ? (0, _hooks.filterDataByColumns4)(dataSource, filterStates) : []
375
- // dataSource={columns && columns.length > 0 && loading !== true ? dataSource : []}
376
- // className={styles.customTable}
377
- ,
372
+ dataSource: columns && columns.length > 0 ? (0, _hooks.filterDataByColumns4)(dataSource, filterStates) : [],
378
373
  className: (0, _classnames.default)(className, {
379
374
  'table-none-column-select': selectionSettings?.mode === undefined && selectionSettings?.type !== 'multiple'
380
375
  }, styles.customTable),
@@ -413,46 +408,6 @@ const TableGrid = props => {
413
408
  // }}
414
409
  ,
415
410
 
416
- summary: () => {
417
- if (typeof summary === 'function') {
418
- return summary(dataSource);
419
- }
420
- if (!summary) {
421
- return undefined;
422
- }
423
- return /*#__PURE__*/_react.default.createElement(_rcMasterUi.Table.Summary, {
424
- fixed: true
425
- }, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Table.Summary.Row, null, (0, _columns.flatColumns)(!!mode ? [_rcMasterUi.Table.SELECTION_COLUMN, ...columns] : [...columns]).filter(col => col.hidden !== true).map((col, index) => {
426
- const cellFormat = col.format ? typeof col.format === 'function' ? col.format({}) : col.format : format;
427
- const thousandSeparator = cellFormat?.thousandSeparator;
428
- const decimalSeparator = cellFormat?.decimalSeparator;
429
-
430
- // const dec = (col.format?.decimalScale || col.format?.decimalScale === 0) ? col.format?.decimalScale : format?.decimalScale
431
- const dec = cellFormat?.decimalScale;
432
- const sumValue = col.type === 'number' ? (0, _hooks.sumDataByField)(dataSource, col?.key) : 0;
433
- const value = !(0, _hooks.isEmpty)(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
434
- const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
435
- const numericFormatProps = {
436
- thousandSeparator: (0, _hooks.checkThousandSeparator)(thousandSeparator, decimalSeparator),
437
- decimalSeparator: (0, _hooks.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
438
- allowNegative: cellFormat?.allowNegative ?? false,
439
- prefix: cellFormat?.prefix,
440
- suffix: cellFormat?.suffix,
441
- decimalScale: dec,
442
- fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
443
- };
444
- return /*#__PURE__*/_react.default.createElement(_rcMasterUi.Table.Summary.Cell, {
445
- key: col.key,
446
- index: index,
447
- align: col.align ?? 'right',
448
- className: 'ui-rc-table-cell-ellipsis'
449
- }, col.summaryTemplate ? col.summaryTemplate(cellValue, col.key) : (0, _reactNumericComponent.numericFormatter)(cellValue, numericFormatProps));
450
- })));
451
- },
452
- pagination: !pagination || pagination && pagination?.onChange ? false : {
453
- showTotal: (total, range) => `${range[0]}-${range[1]} / ${total} items`,
454
- ...pagination
455
- },
456
411
  onFilter: val => {
457
412
  handleOnFilter(val);
458
413
  // triggerFilter?.(convertFilters(val))
@@ -507,6 +462,49 @@ const TableGrid = props => {
507
462
  },
508
463
  expandable: {
509
464
  ...expandable
465
+ },
466
+ summary: () => {
467
+ if (typeof summary === 'function') {
468
+ return summary(dataSource);
469
+ }
470
+ if (!summary) {
471
+ return undefined;
472
+ }
473
+ return /*#__PURE__*/_react.default.createElement(_rcMasterUi.Table.Summary, {
474
+ fixed: true
475
+ }, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Table.Summary.Row, null, (0, _columns.flatColumns)(!!mode ? [_rcMasterUi.Table.SELECTION_COLUMN, ...columns] : [...columns]).filter(col => col.hidden !== true).map((col, index) => {
476
+ // const cellFormat: IFormat | undefined = col.format ? typeof col.format === 'function' ? col.format({}) : col.format : format
477
+
478
+ const colFormat = typeof col.format === 'function' ? col.format({}) : col.format;
479
+ const cellFormat = (0, _hooks.getFormat)(colFormat, format);
480
+ const thousandSeparator = cellFormat?.thousandSeparator;
481
+ const decimalSeparator = cellFormat?.decimalSeparator;
482
+
483
+ // const dec = (col.format?.decimalScale || col.format?.decimalScale === 0) ? col.format?.decimalScale : format?.decimalScale
484
+ const dec = cellFormat?.decimalScale;
485
+ const sumValue = col.type === 'number' ? (0, _hooks.sumDataByField)(dataSource, col?.key) : 0;
486
+ const value = !(0, _hooks.isEmpty)(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
487
+ const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
488
+ const numericFormatProps = {
489
+ thousandSeparator: (0, _hooks.checkThousandSeparator)(thousandSeparator, decimalSeparator),
490
+ decimalSeparator: (0, _hooks.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
491
+ allowNegative: cellFormat?.allowNegative ?? false,
492
+ prefix: cellFormat?.prefix,
493
+ suffix: cellFormat?.suffix,
494
+ decimalScale: dec,
495
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
496
+ };
497
+ return /*#__PURE__*/_react.default.createElement(_rcMasterUi.Table.Summary.Cell, {
498
+ key: col.key,
499
+ index: index,
500
+ align: col.align ?? 'right',
501
+ className: 'ui-rc-table-cell-ellipsis'
502
+ }, col.summaryTemplate ? col.summaryTemplate(cellValue, col.key) : (0, _reactNumericComponent.numericFormatter)(cellValue, numericFormatProps));
503
+ })));
504
+ },
505
+ pagination: !pagination || pagination && pagination?.onChange ? false : {
506
+ showTotal: (total, range) => `${range[0]}-${range[1]} / ${total} items`,
507
+ ...pagination
510
508
  }
511
509
  })), /*#__PURE__*/_react.default.createElement("div", null), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/_react.default.createElement(_pagination.default
512
510
  // style={{padding: '0.75rem 1rem'}}
@@ -3,7 +3,7 @@ import React from "react";
3
3
  import type { TableLocale } from "rc-master-ui/lib/table/interface";
4
4
  import type { ColumnsTable } from "../../type";
5
5
  export declare function flatColumns<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
6
- export declare function flatColumns2<RecordType>(columns: ColumnsTable<RecordType>): ColumnsTable<RecordType>;
6
+ export declare const flatColumns2: <RecordType>(columns: ColumnsTable<RecordType>) => ColumnsTable<RecordType>;
7
7
  export declare const getValueCell: <T>(column: ColumnTable<T>, value: any, format?: IFormat) => any;
8
8
  export declare const renderContent: <T>(column: ColumnTable<T>, value: any, record: any, index: number, format?: IFormat) => React.JSX.Element;
9
9
  export declare const renderFilter: <RecordType>(column: ColumnTable<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any, format?: IFormat) => React.JSX.Element;
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.flatColumns = flatColumns;
8
- exports.flatColumns2 = flatColumns2;
9
- exports.renderFilter = exports.renderContent = exports.getValueCell = void 0;
8
+ exports.renderFilter = exports.renderContent = exports.getValueCell = exports.flatColumns2 = void 0;
10
9
  var _utils = require("../utils");
11
10
  var _reactNumericComponent = require("react-numeric-component");
12
11
  var _dayjs = _interopRequireDefault(require("dayjs"));
@@ -49,16 +48,8 @@ function flatColumns(columns, parentKey = 'key') {
49
48
  }];
50
49
  }, []);
51
50
  }
52
- function flatColumns2(columns
53
- // parentKey = 'key'
54
- ) {
55
- // @ts-ignore
51
+ const flatColumns2 = columns => {
56
52
  return columns.reduce((list, column) => {
57
- // const { fixed } = column
58
- // Convert `fixed='true'` to `fixed='left'` instead
59
- // const parsedFixed = fixed === true ? 'left' : fixed
60
- // const mergedKey = `${parentKey}-${index}`
61
-
62
53
  const subColumns = column.children;
63
54
  if (column === _useSelection.SELECTION_COLUMN) {
64
55
  return [...list, {
@@ -66,18 +57,17 @@ function flatColumns2(columns
66
57
  }];
67
58
  }
68
59
  if (subColumns && subColumns.length > 0) {
69
- return [...list, ...flatColumns(subColumns).map(subColum => ({
60
+ return [...list, ...flatColumns2(subColumns).map(subColum => ({
70
61
  // fixed: parsedFixed,
71
62
  ...subColum
72
63
  }))];
73
64
  }
74
65
  return [...list, {
75
- // key: mergedKey,
76
66
  ...column
77
- // fixed: parsedFixed
78
67
  }];
79
68
  }, []);
80
- }
69
+ };
70
+ exports.flatColumns2 = flatColumns2;
81
71
  const getValueCell = (column, value, format) => {
82
72
  switch (column?.type) {
83
73
  case 'number':
@@ -273,12 +273,14 @@ const useColumns = config => {
273
273
  })));
274
274
  },
275
275
  onHeaderCell: () => ({
276
+ id: `${col.field}`,
276
277
  width: col.width,
277
278
  onResize: handleResize?.(col),
278
279
  className: col.headerTextAlign === 'center' ? 'head-align-center' : col.headerTextAlign === 'right' ? 'head-align-right' : ''
279
280
  }),
280
281
  onCell: (data, index) => {
281
282
  return {
283
+ id: `${col.field}`,
282
284
  colSpan: groupColumns && data.children && col.field === firstNonGroupColumn?.field ? 2 : groupColumns && data.children && nonGroupColumns[1].field === col.field ? 0 : 1,
283
285
  zIndex: data.children && col.field === firstNonGroupColumn?.field ? 11 : undefined,
284
286
  ...transformedColumn?.onCell?.(data, index),
@@ -293,7 +295,8 @@ const useColumns = config => {
293
295
  };
294
296
  },
295
297
  render: (value, record, rowIndex) => {
296
- const cellFormat = col.format ? typeof col.format === 'function' ? col.format(record) : col.format : format;
298
+ const colFormat = typeof col.format === 'function' ? col.format(record) : col.format;
299
+ const cellFormat = (0, _utils.getFormat)(colFormat, format);
297
300
  if (groupSetting && groupSetting.hiddenColumnGroup === false) {
298
301
  if (record.children) {
299
302
  return (0, _columns.renderContent)(col, value, record, rowIndex, cellFormat);
@@ -21,6 +21,21 @@ export declare const getVisibleColumnKeys: (columns: any[]) => string[];
21
21
  export declare function getHiddenParentKeys(columns: any[], parentKeys?: string[]): string[];
22
22
  export declare const updateColumns: (columns: any[], includes: string[]) => any[];
23
23
  export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string[]) => any[];
24
+ export declare const getFormat: (colFormat?: IFormat, format?: IFormat) => {
25
+ thousandSeparator: string;
26
+ decimalSeparator: string;
27
+ decimalScale: number;
28
+ allowNegative: boolean;
29
+ prefix: string;
30
+ suffix: string;
31
+ fixedDecimalScale: boolean;
32
+ dateFormat: string;
33
+ datetimeFormat: string;
34
+ timeFormat: string;
35
+ weekFormat: string;
36
+ monthFormat: string;
37
+ yearFormat: string;
38
+ };
24
39
  export declare const getDatepickerFormat: (type: EditType | TypeFilter | IColumnType, format?: IFormat) => string;
25
40
  export declare const customWeekStartEndFormat: (value: any, weekFormat: string) => string;
26
41
  export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
@@ -78,7 +93,7 @@ export declare const checkChild: (inputArray: any[]) => boolean;
78
93
  export declare const isEditable: <RecordType>(column: ColumnTable, rowData: RecordType) => boolean | ((rowData: any) => boolean);
79
94
  export declare const isArraysEqual: (arr1: any[], arr2: any[]) => boolean;
80
95
  export declare const editAbleColumns: <T>(columns: ColumnsTable<T>) => ColumnTable<T>[];
81
- export declare const findItemPath: (tree: any[], targetItem: any, rowKey: any) => any;
96
+ export declare const findItemPath: (tree: any[], targetItem: any, rowKey: any, currentPage?: number, pageSize?: number) => any;
82
97
  export declare const filterDataByColumns: (data: any[], queries: any) => any[];
83
98
  export declare const filterDataByColumns2: (data: any[], queries: any) => any[];
84
99
  export declare const removeFieldRecursive: (data: any[], field: string) => any[];
@@ -109,7 +124,7 @@ export declare function getCellsByPosition(cellSet: any, position?: string): any
109
124
  export declare const addBorderClass: (selectedCells: any, type: string, className: string, id?: string) => void;
110
125
  export declare const removeBorderClass: (selectedCells: any, type: string, className: string, id?: string) => void;
111
126
  export declare const removeBorderClass2: (className: string, id?: string) => void;
112
- export declare const onAddBgSelectedCell: (selectedCells: any, id?: string) => void;
127
+ export declare const onAddBgSelectedCell: (selectedCells: any, id?: string, isFocusCellIndex?: boolean) => void;
113
128
  export declare const onAddBorderSelectedCell: (selectedCells: any, id?: string) => void;
114
129
  export declare const onRemoveBgSelectedCell: (selectedCells: any, id?: string, rowsSelected?: any) => void;
115
130
  export declare const onRemoveBorderSelectedCell: (selectedCells: any, id?: string) => void;
@@ -16,7 +16,7 @@ exports.findAllChildrenKeys = findAllChildrenKeys;
16
16
  exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = exports.findItemPath = exports.findItemByKey = void 0;
17
17
  exports.getBottomRowCells = getBottomRowCells;
18
18
  exports.getCellsByPosition = getCellsByPosition;
19
- exports.getFirstSelectCell = exports.getEditType = exports.getDefaultValue = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = void 0;
19
+ exports.getFormat = exports.getFirstSelectCell = exports.getEditType = exports.getDefaultValue = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = void 0;
20
20
  exports.getHiddenParentKeys = getHiddenParentKeys;
21
21
  exports.hideDraggingPoint = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = exports.getRowsPasteIndex = exports.getRowNumber = exports.getLastSelectCell = void 0;
22
22
  exports.invalidDate = invalidDate;
@@ -216,6 +216,26 @@ const updateColumnsByGroup = (columns, columnsGroup) => {
216
216
  });
217
217
  };
218
218
  exports.updateColumnsByGroup = updateColumnsByGroup;
219
+ const getFormat = (colFormat, format) => {
220
+ return {
221
+ thousandSeparator: colFormat?.thousandSeparator ?? format?.thousandSeparator,
222
+ decimalSeparator: colFormat?.decimalSeparator ?? format?.decimalSeparator,
223
+ decimalScale: colFormat?.decimalScale ?? format?.decimalScale,
224
+ allowNegative: colFormat?.allowNegative ?? format?.allowNegative,
225
+ // check nhập số âm
226
+ prefix: colFormat?.prefix ?? format?.prefix,
227
+ suffix: colFormat?.suffix ?? format?.suffix,
228
+ fixedDecimalScale: colFormat?.fixedDecimalScale ?? format?.fixedDecimalScale,
229
+ // mặc định thêm số 0 sau số thập phân
230
+ dateFormat: colFormat?.dateFormat ?? format?.dateFormat,
231
+ datetimeFormat: colFormat?.datetimeFormat ?? format?.datetimeFormat,
232
+ timeFormat: colFormat?.timeFormat ?? format?.timeFormat,
233
+ weekFormat: colFormat?.weekFormat ?? format?.weekFormat,
234
+ monthFormat: colFormat?.monthFormat ?? format?.monthFormat,
235
+ yearFormat: colFormat?.yearFormat ?? format?.yearFormat
236
+ };
237
+ };
238
+ exports.getFormat = getFormat;
219
239
  const getDatepickerFormat = (type, format) => {
220
240
  const typeFormat = type ? type.toLowerCase() : '';
221
241
  switch (typeFormat) {
@@ -1011,11 +1031,11 @@ const editAbleColumns = columns => {
1011
1031
  return columns.filter(col => col.field !== '#' && col.field !== 'index' && col.field !== 'command' && col.visible !== false);
1012
1032
  };
1013
1033
  exports.editAbleColumns = editAbleColumns;
1014
- const findItemPath = (tree, targetItem, rowKey) => {
1034
+ const findItemPath = (tree, targetItem, rowKey, currentPage, pageSize) => {
1015
1035
  let result = null;
1016
1036
  function dfs(nodes, path = []) {
1017
1037
  for (let i = 0; i < nodes.length; i++) {
1018
- const currentPath = [...path, i + 1];
1038
+ const currentPath = currentPage && pageSize ? [...path, i + 1 + (currentPage - 1) * pageSize] : [...path, i + 1];
1019
1039
  const node = nodes[i];
1020
1040
  if (node?.[rowKey] === targetItem?.[rowKey]) {
1021
1041
  result = currentPath.join('.');
@@ -1642,7 +1662,7 @@ const removeBorderClass2 = (className, id) => {
1642
1662
  }
1643
1663
  };
1644
1664
  exports.removeBorderClass2 = removeBorderClass2;
1645
- const onAddBgSelectedCell = (selectedCells, id) => {
1665
+ const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
1646
1666
  const selectors = Array.from(selectedCells).map(pos => {
1647
1667
  const [row1, col1] = pos.split('-');
1648
1668
  return `[data-row-index="${row1}"][data-col-index="${col1}"]`;
@@ -1657,7 +1677,7 @@ const onAddBgSelectedCell = (selectedCells, id) => {
1657
1677
  const rowsArray = [...new Set([...selectedCells].map(item => item.split("-")[0]))];
1658
1678
  const rowsSelectors = rowsArray.map(r => `.rc-ui-cell-index[data-row-index="${r}"]`).join(", ");
1659
1679
  const cellsIndex = table && rowsSelectors.length > 0 ? table?.querySelectorAll(rowsSelectors) : null;
1660
- if (cellsIndex) {
1680
+ if (cellsIndex && isFocusCellIndex !== false) {
1661
1681
  cellsIndex.forEach(cell => {
1662
1682
  cell.classList.add('focus');
1663
1683
  });
@@ -1694,7 +1714,7 @@ const onAddBorderSelectedCell = (selectedCells, id) => {
1694
1714
  if (cell) {
1695
1715
  cell.style.zIndex = 1;
1696
1716
  }
1697
- if (cell && cell.classList.contains('ui-rc-table-cell-fix-left')) {
1717
+ if (cell && (cell.classList.contains('ui-rc-table-cell-fix-left') || cell.classList.contains('ui-rc-table-cell-fix-right'))) {
1698
1718
  cell.style.zIndex = 3;
1699
1719
  }
1700
1720