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
@@ -12,7 +12,7 @@ import classNames from "classnames";
12
12
  import { checkDecimalSeparator, checkThousandSeparator,
13
13
  // filterDataByColumns2,
14
14
  // filterDataByColumns3,
15
- filterDataByColumns4,
15
+ filterDataByColumns4, getFormat,
16
16
  // convertFlatColumn,
17
17
  isEmpty,
18
18
  // newGuid,
@@ -355,9 +355,7 @@ const TableGrid = props => {
355
355
  }), /*#__PURE__*/React.createElement(Table, _extends({
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.createElement(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 ? filterDataByColumns4(dataSource, filterStates) : []
375
- // dataSource={columns && columns.length > 0 && loading !== true ? dataSource : []}
376
- // className={styles.customTable}
377
- ,
372
+ dataSource: columns && columns.length > 0 ? filterDataByColumns4(dataSource, filterStates) : [],
378
373
  className: classNames(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.createElement(Table.Summary, {
424
- fixed: true
425
- }, /*#__PURE__*/React.createElement(Table.Summary.Row, null, flatColumns(!!mode ? [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' ? sumDataByField(dataSource, col?.key) : 0;
433
- const value = !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: checkThousandSeparator(thousandSeparator, decimalSeparator),
437
- decimalSeparator: 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.createElement(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) : 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.createElement(Table.Summary, {
474
+ fixed: true
475
+ }, /*#__PURE__*/React.createElement(Table.Summary.Row, null, flatColumns(!!mode ? [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 = 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' ? sumDataByField(dataSource, col?.key) : 0;
486
+ const value = !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: checkThousandSeparator(thousandSeparator, decimalSeparator),
490
+ decimalSeparator: 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.createElement(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) : 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.createElement("div", null), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/React.createElement(Pagination
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;
@@ -38,16 +38,8 @@ export function flatColumns(columns, parentKey = 'key') {
38
38
  }];
39
39
  }, []);
40
40
  }
41
- export function flatColumns2(columns
42
- // parentKey = 'key'
43
- ) {
44
- // @ts-ignore
41
+ export const flatColumns2 = columns => {
45
42
  return columns.reduce((list, column) => {
46
- // const { fixed } = column
47
- // Convert `fixed='true'` to `fixed='left'` instead
48
- // const parsedFixed = fixed === true ? 'left' : fixed
49
- // const mergedKey = `${parentKey}-${index}`
50
-
51
43
  const subColumns = column.children;
52
44
  if (column === SELECTION_COLUMN) {
53
45
  return [...list, {
@@ -55,18 +47,16 @@ export function flatColumns2(columns
55
47
  }];
56
48
  }
57
49
  if (subColumns && subColumns.length > 0) {
58
- return [...list, ...flatColumns(subColumns).map(subColum => ({
50
+ return [...list, ...flatColumns2(subColumns).map(subColum => ({
59
51
  // fixed: parsedFixed,
60
52
  ...subColum
61
53
  }))];
62
54
  }
63
55
  return [...list, {
64
- // key: mergedKey,
65
56
  ...column
66
- // fixed: parsedFixed
67
57
  }];
68
58
  }, []);
69
- }
59
+ };
70
60
  export const getValueCell = (column, value, format) => {
71
61
  switch (column?.type) {
72
62
  case 'number':
@@ -4,7 +4,7 @@ import { Fragment, useCallback } from 'react';
4
4
  // import Command from "../Command";
5
5
  import { Button, Space } from "antd";
6
6
  import { Select } from "rc-master-ui";
7
- import { findItemPath, getTypeFilter } from "./utils";
7
+ import { findItemPath, getFormat, getTypeFilter } from "./utils";
8
8
  import { booleanOperator, numberOperator, stringOperator, translateOption } from "./constant";
9
9
  import { flatColumns2, renderContent, renderFilter } from "./columns";
10
10
  import { SearchOutlined } from "@ant-design/icons";
@@ -262,12 +262,14 @@ const useColumns = config => {
262
262
  })));
263
263
  },
264
264
  onHeaderCell: () => ({
265
+ id: `${col.field}`,
265
266
  width: col.width,
266
267
  onResize: handleResize?.(col),
267
268
  className: col.headerTextAlign === 'center' ? 'head-align-center' : col.headerTextAlign === 'right' ? 'head-align-right' : ''
268
269
  }),
269
270
  onCell: (data, index) => {
270
271
  return {
272
+ id: `${col.field}`,
271
273
  colSpan: groupColumns && data.children && col.field === firstNonGroupColumn?.field ? 2 : groupColumns && data.children && nonGroupColumns[1].field === col.field ? 0 : 1,
272
274
  zIndex: data.children && col.field === firstNonGroupColumn?.field ? 11 : undefined,
273
275
  ...transformedColumn?.onCell?.(data, index),
@@ -282,7 +284,8 @@ const useColumns = config => {
282
284
  };
283
285
  },
284
286
  render: (value, record, rowIndex) => {
285
- const cellFormat = col.format ? typeof col.format === 'function' ? col.format(record) : col.format : format;
287
+ const colFormat = typeof col.format === 'function' ? col.format(record) : col.format;
288
+ const cellFormat = getFormat(colFormat, format);
286
289
  if (groupSetting && groupSetting.hiddenColumnGroup === false) {
287
290
  if (record.children) {
288
291
  return 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;
@@ -171,6 +171,25 @@ export const updateColumnsByGroup = (columns, columnsGroup) => {
171
171
  return newColumn;
172
172
  });
173
173
  };
174
+ export const getFormat = (colFormat, format) => {
175
+ return {
176
+ thousandSeparator: colFormat?.thousandSeparator ?? format?.thousandSeparator,
177
+ decimalSeparator: colFormat?.decimalSeparator ?? format?.decimalSeparator,
178
+ decimalScale: colFormat?.decimalScale ?? format?.decimalScale,
179
+ allowNegative: colFormat?.allowNegative ?? format?.allowNegative,
180
+ // check nhập số âm
181
+ prefix: colFormat?.prefix ?? format?.prefix,
182
+ suffix: colFormat?.suffix ?? format?.suffix,
183
+ fixedDecimalScale: colFormat?.fixedDecimalScale ?? format?.fixedDecimalScale,
184
+ // mặc định thêm số 0 sau số thập phân
185
+ dateFormat: colFormat?.dateFormat ?? format?.dateFormat,
186
+ datetimeFormat: colFormat?.datetimeFormat ?? format?.datetimeFormat,
187
+ timeFormat: colFormat?.timeFormat ?? format?.timeFormat,
188
+ weekFormat: colFormat?.weekFormat ?? format?.weekFormat,
189
+ monthFormat: colFormat?.monthFormat ?? format?.monthFormat,
190
+ yearFormat: colFormat?.yearFormat ?? format?.yearFormat
191
+ };
192
+ };
174
193
  export const getDatepickerFormat = (type, format) => {
175
194
  const typeFormat = type ? type.toLowerCase() : '';
176
195
  switch (typeFormat) {
@@ -930,11 +949,11 @@ export const isArraysEqual = (arr1, arr2) => {
930
949
  export const editAbleColumns = columns => {
931
950
  return columns.filter(col => col.field !== '#' && col.field !== 'index' && col.field !== 'command' && col.visible !== false);
932
951
  };
933
- export const findItemPath = (tree, targetItem, rowKey) => {
952
+ export const findItemPath = (tree, targetItem, rowKey, currentPage, pageSize) => {
934
953
  let result = null;
935
954
  function dfs(nodes, path = []) {
936
955
  for (let i = 0; i < nodes.length; i++) {
937
- const currentPath = [...path, i + 1];
956
+ const currentPath = currentPage && pageSize ? [...path, i + 1 + (currentPage - 1) * pageSize] : [...path, i + 1];
938
957
  const node = nodes[i];
939
958
  if (node?.[rowKey] === targetItem?.[rowKey]) {
940
959
  result = currentPath.join('.');
@@ -1544,7 +1563,7 @@ export const removeBorderClass2 = (className, id) => {
1544
1563
  });
1545
1564
  }
1546
1565
  };
1547
- export const onAddBgSelectedCell = (selectedCells, id) => {
1566
+ export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
1548
1567
  const selectors = Array.from(selectedCells).map(pos => {
1549
1568
  const [row1, col1] = pos.split('-');
1550
1569
  return `[data-row-index="${row1}"][data-col-index="${col1}"]`;
@@ -1559,7 +1578,7 @@ export const onAddBgSelectedCell = (selectedCells, id) => {
1559
1578
  const rowsArray = [...new Set([...selectedCells].map(item => item.split("-")[0]))];
1560
1579
  const rowsSelectors = rowsArray.map(r => `.rc-ui-cell-index[data-row-index="${r}"]`).join(", ");
1561
1580
  const cellsIndex = table && rowsSelectors.length > 0 ? table?.querySelectorAll(rowsSelectors) : null;
1562
- if (cellsIndex) {
1581
+ if (cellsIndex && isFocusCellIndex !== false) {
1563
1582
  cellsIndex.forEach(cell => {
1564
1583
  cell.classList.add('focus');
1565
1584
  });
@@ -1595,7 +1614,7 @@ export const onAddBorderSelectedCell = (selectedCells, id) => {
1595
1614
  if (cell) {
1596
1615
  cell.style.zIndex = 1;
1597
1616
  }
1598
- if (cell && cell.classList.contains('ui-rc-table-cell-fix-left')) {
1617
+ if (cell && (cell.classList.contains('ui-rc-table-cell-fix-left') || cell.classList.contains('ui-rc-table-cell-fix-right'))) {
1599
1618
  cell.style.zIndex = 3;
1600
1619
  }
1601
1620