es-grid-template 1.9.95 → 1.9.97

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 (91) hide show
  1. package/es/grid-component/GridRefreshButton.css +9 -9
  2. package/es/grid-component/hooks/rowFocus.d.ts +2 -1
  3. package/es/grid-component/hooks/rowFocus.js +26 -0
  4. package/es/grid-component/type.d.ts +1 -1
  5. package/es/group-component/TableContainer.js +1 -0
  6. package/es/group-component/TableContainerEdit.js +1 -0
  7. package/es/group-component/body/TableBodyCell.d.ts +2 -0
  8. package/es/group-component/body/TableBodyCell.js +15 -30
  9. package/es/group-component/body/TableBodyCellEdit.js +21 -84
  10. package/es/group-component/body/TableBodyCellEmpty.d.ts +2 -0
  11. package/es/group-component/body/TableBodyCellEmpty.js +15 -30
  12. package/es/group-component/body/TableBodyRowGroupCell.d.ts +2 -0
  13. package/es/group-component/body/TableBodyRowGroupCell.js +15 -30
  14. package/es/group-component/footer/TableFooter.d.ts +2 -1
  15. package/es/group-component/footer/TableFooter.js +8 -11
  16. package/es/group-component/footer/TableFooterCell.d.ts +2 -1
  17. package/es/group-component/footer/TableFooterCell.js +9 -4
  18. package/es/group-component/footer/TableFooterRow.d.ts +2 -1
  19. package/es/group-component/footer/TableFooterRow.js +4 -2
  20. package/es/group-component/hook/utils.d.ts +3 -3
  21. package/es/group-component/table/TableWrapper.d.ts +1 -0
  22. package/es/group-component/table/TableWrapper.js +5 -3
  23. package/es/table-component/TableContainer.js +3 -1
  24. package/es/table-component/TableContainerEdit.js +3 -1
  25. package/es/table-component/body/TableBodyCell.js +15 -39
  26. package/es/table-component/body/TableBodyCellEdit.js +18 -69
  27. package/es/table-component/footer/TableFooter.d.ts +2 -1
  28. package/es/table-component/footer/TableFooter.js +8 -11
  29. package/es/table-component/footer/TableFooterCell.d.ts +2 -1
  30. package/es/table-component/footer/TableFooterCell.js +9 -4
  31. package/es/table-component/footer/TableFooterRow.d.ts +2 -1
  32. package/es/table-component/footer/TableFooterRow.js +4 -2
  33. package/es/table-component/table/TableWrapper.d.ts +1 -0
  34. package/es/table-component/table/TableWrapper.js +5 -3
  35. package/es/table-virtuoso/body/TableBodyCell.d.ts +1 -0
  36. package/es/table-virtuoso/body/TableBodyCell.js +13 -30
  37. package/es/table-virtuoso/body/TableBodyCellRowGroup.d.ts +1 -0
  38. package/es/table-virtuoso/body/TableBodyCellRowGroup.js +13 -30
  39. package/es/table-virtuoso/body/TableBodyRow.d.ts +2 -1
  40. package/es/table-virtuoso/body/TableBodyRow.js +10 -3
  41. package/es/table-virtuoso/footer/TableFooterCell.d.ts +2 -1
  42. package/es/table-virtuoso/footer/TableFooterCell.js +9 -4
  43. package/es/table-virtuoso/table/TableContainer.js +3 -1
  44. package/es/table-virtuoso/table/TableWrapper.d.ts +1 -0
  45. package/es/table-virtuoso/table/TableWrapper.js +14 -7
  46. package/lib/grid-component/GridRefreshButton.css +9 -9
  47. package/lib/grid-component/hooks/rowFocus.d.ts +2 -1
  48. package/lib/grid-component/hooks/rowFocus.js +27 -0
  49. package/lib/grid-component/type.d.ts +1 -1
  50. package/lib/group-component/TableContainer.js +1 -0
  51. package/lib/group-component/TableContainerEdit.js +1 -0
  52. package/lib/group-component/body/TableBodyCell.d.ts +2 -0
  53. package/lib/group-component/body/TableBodyCell.js +14 -29
  54. package/lib/group-component/body/TableBodyCellEdit.js +20 -83
  55. package/lib/group-component/body/TableBodyCellEmpty.d.ts +2 -0
  56. package/lib/group-component/body/TableBodyCellEmpty.js +14 -29
  57. package/lib/group-component/body/TableBodyRowGroupCell.d.ts +2 -0
  58. package/lib/group-component/body/TableBodyRowGroupCell.js +14 -29
  59. package/lib/group-component/footer/TableFooter.d.ts +2 -1
  60. package/lib/group-component/footer/TableFooter.js +8 -11
  61. package/lib/group-component/footer/TableFooterCell.d.ts +2 -1
  62. package/lib/group-component/footer/TableFooterCell.js +9 -4
  63. package/lib/group-component/footer/TableFooterRow.d.ts +2 -1
  64. package/lib/group-component/footer/TableFooterRow.js +4 -2
  65. package/lib/group-component/table/TableWrapper.d.ts +1 -0
  66. package/lib/group-component/table/TableWrapper.js +5 -3
  67. package/lib/table-component/TableContainer.js +3 -1
  68. package/lib/table-component/TableContainerEdit.js +3 -1
  69. package/lib/table-component/body/TableBodyCell.js +14 -38
  70. package/lib/table-component/body/TableBodyCellEdit.js +17 -68
  71. package/lib/table-component/footer/TableFooter.d.ts +2 -1
  72. package/lib/table-component/footer/TableFooter.js +8 -11
  73. package/lib/table-component/footer/TableFooterCell.d.ts +2 -1
  74. package/lib/table-component/footer/TableFooterCell.js +9 -4
  75. package/lib/table-component/footer/TableFooterRow.d.ts +2 -1
  76. package/lib/table-component/footer/TableFooterRow.js +4 -2
  77. package/lib/table-component/table/TableWrapper.d.ts +1 -0
  78. package/lib/table-component/table/TableWrapper.js +5 -3
  79. package/lib/table-virtuoso/body/TableBodyCell.d.ts +1 -0
  80. package/lib/table-virtuoso/body/TableBodyCell.js +12 -29
  81. package/lib/table-virtuoso/body/TableBodyCellRowGroup.d.ts +1 -0
  82. package/lib/table-virtuoso/body/TableBodyCellRowGroup.js +12 -29
  83. package/lib/table-virtuoso/body/TableBodyRow.d.ts +2 -1
  84. package/lib/table-virtuoso/body/TableBodyRow.js +10 -3
  85. package/lib/table-virtuoso/footer/TableFooterCell.d.ts +2 -1
  86. package/lib/table-virtuoso/footer/TableFooterCell.js +9 -4
  87. package/lib/table-virtuoso/table/TableContainer.js +3 -1
  88. package/lib/table-virtuoso/table/TableWrapper.d.ts +1 -0
  89. package/lib/table-virtuoso/table/TableWrapper.js +14 -7
  90. package/package.json +1 -1
  91. package/CHANGELOG.md +0 -16
@@ -442,44 +442,20 @@ const TableBodyCell = props => {
442
442
  }
443
443
  },
444
444
  onKeyDown: e => {
445
- const flatRows = table.getRowModel().flatRows;
446
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
447
- const nextIndex = cell.row.index + 1;
448
- // const nextIndex = rowNumber + 1
449
-
450
- const nextId = flatRows[nextIndex].id;
451
- setFocusedCell?.({
452
- colId: cell.column.id,
453
- rowId: nextId
454
- });
455
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
456
-
457
- // if (rowNumber < flatRows.length - 5) {
458
- // e.stopPropagation()
459
- // e.preventDefault()
460
- // rowVirtualizer.scrollToIndex(cell.row.index, {
461
- // align: 'center', // 'start' | 'center' | 'end'
462
- // })
463
- // }
464
-
465
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
466
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
467
- if (cellFocus) {
468
- cellFocus.focus();
469
- }
470
- }
471
- if (e.key === 'ArrowUp' && rowNumber > 0) {
472
- const prevIndex = cell.row.index - 1;
473
- const nextId = flatRows[prevIndex].id;
474
- setFocusedCell?.({
475
- colId: cell.column.id,
476
- rowId: nextId
477
- });
478
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
479
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
480
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
481
- if (cellFocus) {
482
- cellFocus.focus();
445
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
446
+ const rows = table.getRowModel().rows;
447
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
448
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
449
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
450
+ if (nextRow) {
451
+ setFocusedCell?.({
452
+ colId: cell.column.id,
453
+ rowId: nextRow.id
454
+ });
455
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.rowVirtualizer?.scrollToIndex(nextIndex, {
456
+ align: 'center'
457
+ }));
458
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
483
459
  }
484
460
  }
485
461
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
@@ -824,77 +824,26 @@ const TableBodyCellEdit = props => {
824
824
  }
825
825
  return;
826
826
  }
827
- if (e.key === 'ArrowDown') {
828
- // e.preventDefault()
829
- // e.stopPropagation()
830
-
831
- const nextRow = table.getRowModel().rows[rowNumber + 1];
832
- if (nextRow) {
833
- const nextRowId = nextRow.id;
834
- setFocusedCell?.({
835
- rowId: nextRowId,
836
- colId
837
- });
838
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
839
- setStartCell?.({
840
- rowId: nextRowId,
841
- colId
842
- });
843
- setEndCell?.({
844
- rowId: nextRowId,
845
- colId
846
- });
847
- setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
848
- rowId: nextRowId,
849
- colId
850
- }, {
851
- rowId: nextRowId,
852
- colId
853
- }));
854
-
855
- // columnVirtualizer.scrollToIndex(nextCol.getIndex(), { align: 'center' })
856
- // rowVirtualizer.scrollToIndex(nextRow.index, { align: 'center' })
857
-
858
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextRowId}"]`);
859
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
860
- if (cellFocus) {
861
- cellFocus.focus();
862
- }
863
- }
864
- return;
865
- }
866
- if (e.key === 'ArrowUp') {
867
- // e.preventDefault()
868
- // e.stopPropagation()
869
-
870
- const nextRow = table.getRowModel().rows[rowNumber - 1];
827
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
828
+ const rows = table.getRowModel().rows;
829
+ const currentIndex = rows.findIndex(row => row.id === rowId);
830
+ if (currentIndex < 0) return;
831
+ const step = e.key === 'ArrowDown' ? 1 : -1;
832
+ const nextIndex = currentIndex + step;
833
+ const nextRow = rows[nextIndex];
871
834
  if (nextRow) {
872
- const nextRowId = nextRow.id;
873
- setFocusedCell?.({
874
- rowId: nextRowId,
875
- colId
876
- });
877
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
878
- setStartCell?.({
879
- rowId: nextRowId,
880
- colId
881
- });
882
- setEndCell?.({
883
- rowId: nextRowId,
884
- colId
885
- });
886
- setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
887
- rowId: nextRowId,
888
- colId
889
- }, {
890
- rowId: nextRowId,
835
+ const nextCell = {
836
+ rowId: nextRow.id,
891
837
  colId
838
+ };
839
+ setFocusedCell?.(nextCell);
840
+ setStartCell?.(nextCell);
841
+ setEndCell?.(nextCell);
842
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, nextCell, nextCell));
843
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, colId, () => rowVirtualizer.scrollToIndex(nextIndex, {
844
+ align: 'center'
892
845
  }));
893
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextRowId}"]`);
894
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
895
- if (cellFocus) {
896
- cellFocus.focus();
897
- }
846
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
898
847
  }
899
848
  return;
900
849
  }
@@ -2,6 +2,7 @@
2
2
  import type { Table } from "@tanstack/react-table";
3
3
  interface TableFooterProps<T> {
4
4
  table: Table<T>;
5
+ footerDataSource?: any[];
5
6
  }
6
- declare const TableFooter: <RecordType extends object>({ table, }: TableFooterProps<RecordType>) => JSX.Element;
7
+ declare const TableFooter: <RecordType extends object>({ table, footerDataSource, }: TableFooterProps<RecordType>) => JSX.Element;
7
8
  export default TableFooter;
@@ -14,7 +14,8 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
14
14
 
15
15
  const TableFooter = ({
16
16
  // columnVirtualizer,
17
- table
17
+ table,
18
+ footerDataSource
18
19
  // virtualPaddingLeft,
19
20
  // virtualPaddingRight,
20
21
  // ...rest
@@ -30,15 +31,11 @@ const TableFooter = ({
30
31
  bottom: 0,
31
32
  zIndex: 1
32
33
  }
33
- }, /*#__PURE__*/_react.default.createElement(_TableFooterRow.default, {
34
- table: table
35
- // columnVirtualizer={columnVirtualizer}
36
- ,
37
- headerGroup: table.getHeaderGroups()[table.getHeaderGroups().length - 1]
38
- // key={headerGroup.id}
39
- // virtualPaddingLeft={virtualPaddingLeft}
40
- // virtualPaddingRight={virtualPaddingRight}
41
- // {...rest}
42
- }));
34
+ }, (footerDataSource ?? [undefined]).map((footerRow, index) => /*#__PURE__*/_react.default.createElement(_TableFooterRow.default, {
35
+ key: index,
36
+ table: table,
37
+ headerGroup: table.getHeaderGroups()[table.getHeaderGroups().length - 1],
38
+ footerRow: footerRow
39
+ })));
43
40
  };
44
41
  var _default = exports.default = TableFooter;
@@ -2,6 +2,7 @@
2
2
  import type { Column } from "@tanstack/react-table";
3
3
  interface TableFooterCellProps<T> {
4
4
  column: Column<T, any>;
5
+ footerRow?: Record<string, any>;
5
6
  }
6
- declare const TableFooterCell: <RecordType extends object>({ column }: TableFooterCellProps<RecordType>) => JSX.Element;
7
+ declare const TableFooterCell: <RecordType extends object>({ column, footerRow }: TableFooterCellProps<RecordType>) => JSX.Element;
7
8
  export default TableFooterCell;
@@ -14,7 +14,8 @@ var _reactNumericComponent = require("react-numeric-component");
14
14
  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); }
15
15
  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; }
16
16
  const TableFooterCell = ({
17
- column
17
+ column,
18
+ footerRow
18
19
  }) => {
19
20
  const isPinned = column.getIsPinned();
20
21
  const isLastLeftPinnedColumn = isPinned === 'left' && column.getIsLastColumn('left');
@@ -25,7 +26,10 @@ const TableFooterCell = ({
25
26
  dataSource
26
27
  } = (0, _react.useContext)(_useContext.TableContext);
27
28
  const col = column.columnDef.meta ?? {};
28
- const colFormat = typeof col.format === 'function' ? col.format({}) : col.format;
29
+ const isCustomFooter = footerRow !== undefined;
30
+ const field = col.field;
31
+ const hasFooterValue = isCustomFooter && Object.prototype.hasOwnProperty.call(footerRow, field) && footerRow[field] != null;
32
+ const colFormat = typeof col.format === 'function' ? col.format(footerRow ?? {}) : col.format;
29
33
  const cellFormat = (0, _utils.getFormat)(colFormat, format);
30
34
  const thousandSeparator = cellFormat?.thousandSeparator;
31
35
  const decimalSeparator = cellFormat?.decimalSeparator;
@@ -34,7 +38,7 @@ const TableFooterCell = ({
34
38
  const dec = cellFormat?.decimalScale;
35
39
 
36
40
  // const sumValue = col.type === 'number' ? sumDataByField(filterDataByColumns4(dataSource, filterStates) as any[], col?.key as string) : 0
37
- const sumValue = col.type === 'number' ? (0, _hooks.sumByField)(dataSource, col?.field) : 0;
41
+ const sumValue = col.type === 'number' ? isCustomFooter ? hasFooterValue ? Number(footerRow[field]) : 0 : (0, _hooks.sumByField)(dataSource, field) : 0;
38
42
  const value = !(0, _utils.isEmpty)(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
39
43
  const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
40
44
  const numberValue = Number(value);
@@ -47,6 +51,7 @@ const TableFooterCell = ({
47
51
  decimalScale: dec,
48
52
  fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
49
53
  };
54
+ const content = isCustomFooter && (!hasFooterValue || col.isSummary === false) ? '' : col.summaryTemplate ? col.summaryTemplate(numberValue, field) : isCustomFooter && col.type !== 'number' ? footerRow[field] : (0, _reactNumericComponent.numericFormatter)(cellValue, numericFormatProps);
50
55
  return /*#__PURE__*/_react.default.createElement("div", {
51
56
  // ref={el => {
52
57
  // if (el) columnVirtualizer.measureElement(el)
@@ -70,6 +75,6 @@ const TableFooterCell = ({
70
75
  minWidth: column?.getSize()
71
76
  // backgroundColor: "#fafafa",
72
77
  }
73
- }, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, col.summaryTemplate ? col.summaryTemplate(numberValue, col.field) : (0, _reactNumericComponent.numericFormatter)(cellValue, numericFormatProps)) : '');
78
+ }, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, content) : '');
74
79
  };
75
80
  var _default = exports.default = TableFooterCell;
@@ -2,7 +2,8 @@
2
2
  import type { HeaderGroup, Table } from "@tanstack/react-table";
3
3
  interface TableFooterRowProps<T> {
4
4
  table: Table<T>;
5
+ footerRow?: Record<string, any>;
5
6
  headerGroup: HeaderGroup<T>;
6
7
  }
7
- declare const TableFooterRow: <RecordType extends object>({ table, headerGroup, }: TableFooterRowProps<RecordType>) => JSX.Element;
8
+ declare const TableFooterRow: <RecordType extends object>({ table, headerGroup, footerRow, }: TableFooterRowProps<RecordType>) => JSX.Element;
8
9
  export default TableFooterRow;
@@ -10,7 +10,8 @@ var _react = _interopRequireDefault(require("react"));
10
10
  var _useContext = require("../useContext");
11
11
  const TableFooterRow = ({
12
12
  table,
13
- headerGroup
13
+ headerGroup,
14
+ footerRow
14
15
  }) => {
15
16
  const visibleColumns = table.getVisibleLeafColumns();
16
17
  const {
@@ -30,7 +31,8 @@ const TableFooterRow = ({
30
31
  }, visibleColumns.map(header => {
31
32
  return /*#__PURE__*/_react.default.createElement(_TableFooterCell.default, {
32
33
  key: header.id,
33
- column: header
34
+ column: header,
35
+ footerRow: footerRow
34
36
  });
35
37
  }));
36
38
  };
@@ -11,6 +11,7 @@ type Props<T> = {
11
11
  minHeight?: number;
12
12
  table: Table<T>;
13
13
  showHeader?: boolean;
14
+ footerDataSource?: any[];
14
15
  summary?: boolean;
15
16
  loading?: boolean;
16
17
  commandClick?: (args: Omit<CommandClick<T>, 'rows'>) => void;
@@ -255,6 +255,7 @@ const TableWrapper = props => {
255
255
  }, /*#__PURE__*/_react.default.createElement("div", {
256
256
  // id={id}
257
257
  ref: tableContainerRef,
258
+ "data-grid-scroll": true,
258
259
  style: {
259
260
  overflow: 'auto',
260
261
  //our scrollable table container
@@ -294,9 +295,10 @@ const TableWrapper = props => {
294
295
  virtualPaddingRight: virtualPaddingRight,
295
296
  fixedLeftColumns: fixedLeftColumns,
296
297
  fixedRightColumns: fixedRightColumns
297
- }), summary && /*#__PURE__*/_react.default.createElement(_TableFooter.default
298
- // columnVirtualizer={columnVirtualizer}
299
- , {
298
+ }), summary && /*#__PURE__*/_react.default.createElement(_TableFooter.default, {
299
+ footerDataSource: props.footerDataSource
300
+ // columnVirtualizer={columnVirtualizer}
301
+ ,
300
302
  table: table
301
303
  // virtualPaddingLeft={virtualPaddingLeft}
302
304
  // virtualPaddingRight={virtualPaddingRight}
@@ -4,6 +4,7 @@ import type { CommandClick } from "../../grid-component/type";
4
4
  import type { VirtualItem } from "@tanstack/react-virtual";
5
5
  interface TableBodyCellProps<T> {
6
6
  table: Table<T>;
7
+ scrollToRow?: (index: number) => void;
7
8
  tableId: string;
8
9
  cell: Cell<T, unknown>;
9
10
  commandClick?: (args: CommandClick<T>) => void;
@@ -381,35 +381,18 @@ const TableBodyCell = props => {
381
381
  }
382
382
  },
383
383
  onKeyDown: e => {
384
- const flatRows = table.getRowModel().flatRows;
385
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
386
- const nextIndex = cell.row.index + 1;
387
- // const nextIndex = rowNumber + 1
388
-
389
- const nextId = flatRows[nextIndex].id;
390
- setFocusedCell?.({
391
- colId: cell.column.id,
392
- rowId: nextId
393
- });
394
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
395
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
396
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
397
- if (cellFocus) {
398
- cellFocus.focus();
399
- }
400
- }
401
- if (e.key === 'ArrowUp' && rowNumber > 0) {
402
- const prevIndex = cell.row.index - 1;
403
- const nextId = flatRows[prevIndex].id;
404
- setFocusedCell?.({
405
- colId: cell.column.id,
406
- rowId: nextId
407
- });
408
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
409
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
410
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
411
- if (cellFocus) {
412
- cellFocus.focus();
384
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
385
+ const rows = table.getRowModel().rows;
386
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
387
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
388
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
389
+ if (nextRow) {
390
+ setFocusedCell?.({
391
+ colId: cell.column.id,
392
+ rowId: nextRow.id
393
+ });
394
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.scrollToRow?.(nextIndex));
395
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
413
396
  }
414
397
  }
415
398
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
@@ -4,6 +4,7 @@ import type { CommandClick } from "../../grid-component/type";
4
4
  import type { VirtualItem } from "@tanstack/react-virtual";
5
5
  interface TableBodyCellProps<T> {
6
6
  table: Table<T>;
7
+ scrollToRow?: (index: number) => void;
7
8
  tableId: string;
8
9
  cell: Cell<T, unknown>;
9
10
  commandClick?: (args: CommandClick<T>) => void;
@@ -96,35 +96,18 @@ const TableBodyCellRowGroup = props => {
96
96
  }
97
97
  },
98
98
  onKeyDown: e => {
99
- const flatRows = table.getRowModel().flatRows;
100
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
101
- const nextIndex = cell.row.index + 1;
102
- // const nextIndex = rowNumber + 1
103
-
104
- const nextId = flatRows[nextIndex].id;
105
- setFocusedCell?.({
106
- colId: cell.column.id,
107
- rowId: nextId
108
- });
109
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
110
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
111
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
112
- if (cellFocus) {
113
- cellFocus.focus();
114
- }
115
- }
116
- if (e.key === 'ArrowUp' && rowNumber > 0) {
117
- const prevIndex = cell.row.index - 1;
118
- const nextId = flatRows[prevIndex].id;
119
- setFocusedCell?.({
120
- colId: cell.column.id,
121
- rowId: nextId
122
- });
123
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
124
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
125
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
126
- if (cellFocus) {
127
- cellFocus.focus();
99
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
100
+ const rows = table.getRowModel().rows;
101
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
102
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
103
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
104
+ if (nextRow) {
105
+ setFocusedCell?.({
106
+ colId: cell.column.id,
107
+ rowId: nextRow.id
108
+ });
109
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.scrollToRow?.(nextIndex));
110
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
128
111
  }
129
112
  }
130
113
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
@@ -4,10 +4,11 @@ import type { CommandClick } from "../../grid-component/type";
4
4
  interface TableBodyRowProps<T> {
5
5
  tableId: string;
6
6
  table: Table<T>;
7
+ scrollToRow?: (index: number) => void;
7
8
  row: Row<T>;
8
9
  commandClick?: (args: CommandClick<T>) => void;
9
10
  editAble?: boolean;
10
11
  [key: string]: any;
11
12
  }
12
- declare const TableBodyRow: <RecordType extends object>({ tableId, table, row, virtualRow, commandClick, contextMenuItems, onContextMenu, rowheight, editAble, isEditing, isRowEditable, ...rest }: TableBodyRowProps<RecordType>) => JSX.Element;
13
+ declare const TableBodyRow: <RecordType extends object>({ tableId, table, row, scrollToRow, virtualRow, commandClick, contextMenuItems, onContextMenu, rowheight, editAble, isEditing, isRowEditable, ...rest }: TableBodyRowProps<RecordType>) => JSX.Element;
13
14
  export default TableBodyRow;
@@ -21,6 +21,7 @@ const TableBodyRow = ({
21
21
  tableId,
22
22
  table,
23
23
  row,
24
+ scrollToRow,
24
25
  virtualRow,
25
26
  commandClick,
26
27
  contextMenuItems,
@@ -140,7 +141,9 @@ const TableBodyRow = ({
140
141
  rowData: row.original,
141
142
  value: cellValue
142
143
  }) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, headertext, headertext ? ': ' : '', " ", cellContent);
143
- return /*#__PURE__*/_react.default.createElement(_TableBodyCell.default, (0, _extends2.default)({}, otherCellAttributes, {
144
+ return /*#__PURE__*/_react.default.createElement(_TableBodyCell.default, (0, _extends2.default)({
145
+ scrollToRow: scrollToRow
146
+ }, otherCellAttributes, {
144
147
  table: table,
145
148
  tableId: tableId,
146
149
  key: cell.id,
@@ -173,7 +176,9 @@ const TableBodyRow = ({
173
176
  const childrenData = row.subRows.map(it => it.original);
174
177
  const sumValue = (0, _hooks.sumByField)(childrenData, cell.column.id);
175
178
  const sumValueFormat = (0, _reactNumericComponent.numericFormatter)(sumValue.toString(), numericFormatProps);
176
- return /*#__PURE__*/_react.default.createElement(_TableBodyCellRowGroup.default, (0, _extends2.default)({}, otherCellAttributes, {
179
+ return /*#__PURE__*/_react.default.createElement(_TableBodyCellRowGroup.default, (0, _extends2.default)({
180
+ scrollToRow: scrollToRow
181
+ }, otherCellAttributes, {
177
182
  table: table,
178
183
  tableId: tableId,
179
184
  key: cell.id,
@@ -186,7 +191,9 @@ const TableBodyRow = ({
186
191
  sumValue: sumValueFormat
187
192
  }));
188
193
  }
189
- return /*#__PURE__*/_react.default.createElement(_TableBodyCell.default, (0, _extends2.default)({}, otherCellAttributes, {
194
+ return /*#__PURE__*/_react.default.createElement(_TableBodyCell.default, (0, _extends2.default)({
195
+ scrollToRow: scrollToRow
196
+ }, otherCellAttributes, {
190
197
  table: table,
191
198
  tableId: tableId,
192
199
  key: cell.id,
@@ -2,6 +2,7 @@
2
2
  import type { Column } from "@tanstack/react-table";
3
3
  interface TableFooterCellProps<T> {
4
4
  column: Column<T, any>;
5
+ footerRow?: Record<string, any>;
5
6
  }
6
- declare const TableFooterCell: <RecordType extends object>({ column }: TableFooterCellProps<RecordType>) => JSX.Element;
7
+ declare const TableFooterCell: <RecordType extends object>({ column, footerRow }: TableFooterCellProps<RecordType>) => JSX.Element;
7
8
  export default TableFooterCell;
@@ -14,7 +14,8 @@ var _reactNumericComponent = require("react-numeric-component");
14
14
  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); }
15
15
  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; }
16
16
  const TableFooterCell = ({
17
- column
17
+ column,
18
+ footerRow
18
19
  }) => {
19
20
  const {
20
21
  prefix,
@@ -22,7 +23,10 @@ const TableFooterCell = ({
22
23
  dataSource
23
24
  } = (0, _react.useContext)(_useContext.TableContext);
24
25
  const col = column.columnDef.meta ?? {};
25
- const colFormat = typeof col.format === 'function' ? col.format({}) : col.format;
26
+ const isCustomFooter = footerRow !== undefined;
27
+ const field = col.field;
28
+ const hasFooterValue = isCustomFooter && Object.prototype.hasOwnProperty.call(footerRow, field) && footerRow[field] != null;
29
+ const colFormat = typeof col.format === 'function' ? col.format(footerRow ?? {}) : col.format;
26
30
  const cellFormat = (0, _utils.getFormat)(colFormat, format);
27
31
  const thousandSeparator = cellFormat?.thousandSeparator;
28
32
  const decimalSeparator = cellFormat?.decimalSeparator;
@@ -31,7 +35,7 @@ const TableFooterCell = ({
31
35
  const dec = cellFormat?.decimalScale;
32
36
 
33
37
  // const sumValue = col.type === 'number' ? sumDataByField(filterDataByColumns4(dataSource, filterStates) as any[], col?.key as string) : 0
34
- const sumValue = col.type === 'number' ? (0, _hooks.sumByField)(dataSource, col?.field) : 0;
38
+ const sumValue = col.type === 'number' ? isCustomFooter ? hasFooterValue ? Number(footerRow[field]) : 0 : (0, _hooks.sumByField)(dataSource, field) : 0;
35
39
  const value = !(0, _utils.isEmpty)(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
36
40
  const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
37
41
  const numberValue = Number(value);
@@ -44,6 +48,7 @@ const TableFooterCell = ({
44
48
  decimalScale: dec,
45
49
  fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
46
50
  };
51
+ const content = isCustomFooter && (!hasFooterValue || col.isSummary === false) ? '' : col.summaryTemplate ? col.summaryTemplate(numberValue, field) : isCustomFooter && col.type !== 'number' ? footerRow[field] : (0, _reactNumericComponent.numericFormatter)(cellValue, numericFormatProps);
47
52
  return /*#__PURE__*/_react.default.createElement("th", {
48
53
  className: (0, _classnames.default)(`${prefix}-grid-cell`, {
49
54
  // [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
@@ -58,6 +63,6 @@ const TableFooterCell = ({
58
63
  minWidth: column?.getSize(),
59
64
  height: 40
60
65
  }
61
- }, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, col.summaryTemplate ? col.summaryTemplate(numberValue, col.field) : (0, _reactNumericComponent.numericFormatter)(cellValue, numericFormatProps)) : '');
66
+ }, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, content) : '');
62
67
  };
63
68
  var _default = exports.default = TableFooterCell;
@@ -299,7 +299,9 @@ const TableContainer = props => {
299
299
  pagination,
300
300
  groupSetting
301
301
  }
302
- }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, (0, _extends2.default)({}, rest, {
302
+ }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, (0, _extends2.default)({
303
+ footerDataSource: props.footerDataSource
304
+ }, rest, {
303
305
  tableContainerRef: tableContainerRef,
304
306
  prefix: prefix,
305
307
  id: id,
@@ -10,6 +10,7 @@ type Props<T> = {
10
10
  height: number;
11
11
  minHeight?: number;
12
12
  dataSource: T[];
13
+ footerDataSource?: any[];
13
14
  summary?: boolean;
14
15
  loading?: boolean;
15
16
  commandClick?: (args: Omit<CommandClick<T>, 'rows'>) => void;
@@ -45,6 +45,11 @@ const TableWrapper = props => {
45
45
 
46
46
  // ref cho scroll container
47
47
  const scrollRef = (0, _react.useRef)(null);
48
+ const virtuosoRef = (0, _react.useRef)(null);
49
+ const scrollToRow = index => virtuosoRef.current?.scrollToIndex({
50
+ index,
51
+ align: 'center'
52
+ });
48
53
  const {
49
54
  rows
50
55
  } = table.getRowModel();
@@ -137,6 +142,7 @@ const TableWrapper = props => {
137
142
  position: "relative"
138
143
  }
139
144
  }, /*#__PURE__*/_react.default.createElement(_reactVirtuoso.TableVirtuoso, (0, _extends2.default)({
145
+ ref: virtuosoRef,
140
146
  data: table.getRowModel().rows,
141
147
  totalCount: rows.length
142
148
  }, onVisibleRowsChange ? {
@@ -201,6 +207,7 @@ const TableWrapper = props => {
201
207
  return /*#__PURE__*/_react.default.createElement(_TableBodyRow.default, (0, _extends2.default)({
202
208
  tableId: id,
203
209
  row: row,
210
+ scrollToRow: scrollToRow,
204
211
  table: table,
205
212
  commandClick: commandClick,
206
213
  rowheight: editAble ? 37 : rowheight,
@@ -258,14 +265,14 @@ const TableWrapper = props => {
258
265
  },
259
266
  fixedFooterContent: summary ? () => {
260
267
  const visibleColumns = table.getVisibleLeafColumns();
261
- return /*#__PURE__*/_react.default.createElement("tr", {
268
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (props.footerDataSource ?? [undefined]).map((footerRow, index) => /*#__PURE__*/_react.default.createElement("tr", {
269
+ key: index,
262
270
  className: "ui-rc-grid-footer-row"
263
- }, visibleColumns.map(header => {
264
- return /*#__PURE__*/_react.default.createElement(_TableFooterCell.default, {
265
- key: header.id,
266
- column: header
267
- });
268
- }));
271
+ }, visibleColumns.map(column => /*#__PURE__*/_react.default.createElement(_TableFooterCell.default, {
272
+ key: column.id,
273
+ column: column,
274
+ footerRow: footerRow
275
+ })))));
269
276
  } : undefined
270
277
  }))), /*#__PURE__*/_react.default.createElement(_reactTooltip.Tooltip, {
271
278
  id: `${id}-tooltip-content`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.9.95",
3
+ "version": "1.9.97",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",