es-grid-template 1.7.24 → 1.7.25

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 (73) hide show
  1. package/es/table-component/ColumnsChoose.d.ts +6 -3
  2. package/es/table-component/ColumnsChoose.js +31 -382
  3. package/es/table-component/InternalTable.js +32 -19
  4. package/es/table-component/TableContainer.d.ts +11 -2
  5. package/es/table-component/TableContainer.js +131 -12
  6. package/es/table-component/TableContainerEdit.d.ts +10 -7
  7. package/es/table-component/TableContainerEdit.js +151 -61
  8. package/es/table-component/body/EditableCell.js +14 -11
  9. package/es/table-component/body/TableBody.js +1 -1
  10. package/es/table-component/body/TableBodyCell.d.ts +2 -0
  11. package/es/table-component/body/TableBodyCell.js +13 -3
  12. package/es/table-component/body/TableBodyCellEdit.d.ts +2 -1
  13. package/es/table-component/body/TableBodyCellEdit.js +150 -33
  14. package/es/table-component/body/TableBodyRow.js +9 -4
  15. package/es/table-component/components/ControlCheckbox.js +0 -3
  16. package/es/table-component/components/async-table-select/index.d.ts +1 -1
  17. package/es/table-component/components/async-table-select/index.js +1 -0
  18. package/es/table-component/components/command/Command.d.ts +1 -0
  19. package/es/table-component/components/command/Command.js +6 -1
  20. package/es/table-component/footer/TableFooterCell.js +45 -3
  21. package/es/table-component/footer/TableFooterRow.js +3 -1
  22. package/es/table-component/header/TableHeadCell.js +31 -12
  23. package/es/table-component/header/TableHeadRow.d.ts +1 -1
  24. package/es/table-component/header/TableHeadRow.js +10 -20
  25. package/es/table-component/hook/useColumns.d.ts +5 -7
  26. package/es/table-component/hook/useColumns.js +18 -58
  27. package/es/table-component/hook/utils.d.ts +12 -0
  28. package/es/table-component/hook/utils.js +144 -1
  29. package/es/table-component/style.scss +47 -1
  30. package/es/table-component/table/Grid.d.ts +3 -2
  31. package/es/table-component/table/Grid.js +22 -98
  32. package/es/table-component/type.d.ts +32 -1
  33. package/es/table-component/useContext.d.ts +5 -50
  34. package/es/table-component/useContext.js +3 -49
  35. package/lib/table-component/ColumnsChoose.d.ts +6 -3
  36. package/lib/table-component/ColumnsChoose.js +29 -381
  37. package/lib/table-component/InternalTable.js +30 -16
  38. package/lib/table-component/TableContainer.d.ts +11 -2
  39. package/lib/table-component/TableContainer.js +132 -12
  40. package/lib/table-component/TableContainerEdit.d.ts +10 -7
  41. package/lib/table-component/TableContainerEdit.js +150 -60
  42. package/lib/table-component/body/EditableCell.js +14 -11
  43. package/lib/table-component/body/TableBody.js +1 -1
  44. package/lib/table-component/body/TableBodyCell.d.ts +2 -0
  45. package/lib/table-component/body/TableBodyCell.js +13 -3
  46. package/lib/table-component/body/TableBodyCellEdit.d.ts +2 -1
  47. package/lib/table-component/body/TableBodyCellEdit.js +150 -33
  48. package/lib/table-component/body/TableBodyRow.js +9 -4
  49. package/lib/table-component/components/ControlCheckbox.js +0 -3
  50. package/lib/table-component/components/async-table-select/index.d.ts +1 -1
  51. package/lib/table-component/components/async-table-select/index.js +2 -0
  52. package/lib/table-component/components/command/Command.d.ts +1 -0
  53. package/lib/table-component/components/command/Command.js +6 -1
  54. package/lib/table-component/footer/TableFooterCell.js +46 -2
  55. package/lib/table-component/footer/TableFooterRow.js +3 -1
  56. package/lib/table-component/header/TableHeadCell.js +31 -12
  57. package/lib/table-component/header/TableHeadRow.d.ts +1 -1
  58. package/lib/table-component/header/TableHeadRow.js +10 -20
  59. package/lib/table-component/hook/useColumns.d.ts +5 -7
  60. package/lib/table-component/hook/useColumns.js +17 -57
  61. package/lib/table-component/hook/utils.d.ts +12 -0
  62. package/lib/table-component/hook/utils.js +160 -8
  63. package/lib/table-component/style.scss +47 -1
  64. package/lib/table-component/table/Grid.d.ts +3 -2
  65. package/lib/table-component/table/Grid.js +21 -98
  66. package/lib/table-component/type.d.ts +32 -1
  67. package/lib/table-component/useContext.d.ts +5 -50
  68. package/lib/table-component/useContext.js +4 -50
  69. package/package.json +2 -2
  70. package/es/table-component/table/GridEdit.d.ts +0 -23
  71. package/es/table-component/table/GridEdit.js +0 -282
  72. package/lib/table-component/table/GridEdit.d.ts +0 -23
  73. package/lib/table-component/table/GridEdit.js +0 -284
@@ -1,16 +1,58 @@
1
- import React from "react";
1
+ import React, { useContext } from "react";
2
2
  // import type { Person } from "../makeData";
3
- import { getCommonPinningStyles } from "../hook/utils";
3
+ import { checkDecimalSeparator, checkThousandSeparator, getCommonPinningStyles, getFormat, isEmpty } from "../hook/utils";
4
+ import { TableContext } from "../useContext";
5
+ import classNames from "classnames";
6
+ import { sumByField } from "../../grid-component/hooks";
7
+ import { numericFormatter } from "react-numeric-component";
4
8
  // import type { Person } from "../../tanstack-table/makeData";
5
9
 
6
10
  const TableFooterCell = ({
7
11
  header
8
12
  }) => {
13
+ const isPinned = header.column.getIsPinned();
14
+ const isLastLeftPinnedColumn = isPinned === 'left' && header.column.getIsLastColumn('left');
15
+ const isFirstRightPinnedColumn = isPinned === 'right' && header.column.getIsFirstColumn('right');
16
+ const {
17
+ prefix,
18
+ format,
19
+ dataSource
20
+ } = useContext(TableContext);
21
+ const col = header.column.columnDef.meta ?? {};
22
+ const colFormat = typeof col.format === 'function' ? col.format({}) : col.format;
23
+ const cellFormat = getFormat(colFormat, format);
24
+ const thousandSeparator = cellFormat?.thousandSeparator;
25
+ const decimalSeparator = cellFormat?.decimalSeparator;
26
+
27
+ // const dec = (col.format?.decimalScale || col.format?.decimalScale === 0) ? col.format?.decimalScale : format?.decimalScale
28
+ const dec = cellFormat?.decimalScale;
29
+
30
+ // const sumValue = col.type === 'number' ? sumDataByField(filterDataByColumns4(dataSource, filterStates) as any[], col?.key as string) : 0
31
+ const sumValue = col.type === 'number' ? sumByField(dataSource, col?.field) : 0;
32
+ const value = !isEmpty(sumValue) ? dec || dec === 0 ? parseFloat(Number(sumValue).toFixed(dec)).toString() : sumValue.toString() : '0';
33
+ const cellValue = col.type === 'number' && col.isSummary !== false ? value : '';
34
+ const numberValue = Number(value);
35
+ const numericFormatProps = {
36
+ thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
37
+ decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
38
+ allowNegative: cellFormat?.allowNegative ?? false,
39
+ prefix: cellFormat?.prefix,
40
+ suffix: cellFormat?.suffix,
41
+ decimalScale: dec,
42
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
43
+ };
9
44
  return /*#__PURE__*/React.createElement("td", {
10
45
  // ref={el => {
11
46
  // if (el) columnVirtualizer.measureElement(el)
12
47
  // }}
13
48
  // data-index={header.id}
49
+
50
+ className: classNames(`${prefix}-grid-cell`, {
51
+ // [`${prefix}-grid-cell-ellipsis`]:!wrapSettings || !(wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')),
52
+ // [`${prefix}-grid-cell-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header'),
53
+ [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
54
+ [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn
55
+ }),
14
56
  key: header.id,
15
57
  colSpan: header.colSpan,
16
58
  style: {
@@ -19,6 +61,6 @@ const TableFooterCell = ({
19
61
  width: header?.getSize() ?? header.column.getSize(),
20
62
  backgroundColor: "#fafafa"
21
63
  }
22
- }, header.column.id !== "id" && header.column.id !== "selection_column" ? /*#__PURE__*/React.createElement("span", null, "aaa") : '');
64
+ }, header.column.id !== "id" && header.column.id !== "selection_column" ? /*#__PURE__*/React.createElement("span", null, col.summaryTemplate ? col.summaryTemplate(numberValue, col.field) : numericFormatter(cellValue, numericFormatProps)) : '');
23
65
  };
24
66
  export default TableFooterCell;
@@ -22,7 +22,9 @@ const TableFooterRow = ({
22
22
  style: {
23
23
  display: "flex",
24
24
  width: "100%",
25
- borderTop: "1px solid #e0e0e0"
25
+ borderBottom: "1px solid #e0e0e0",
26
+ borderTop: "1px solid #e0e0e0",
27
+ height: 37
26
28
  }
27
29
  }, fixedLeftColumns.length > 0 ? fixedLeftColumns.map(column => {
28
30
  return /*#__PURE__*/React.createElement(TableFooterCell, {
@@ -12,6 +12,7 @@ import { booleanOperator, nonActionColumn, numberOperator, stringOperator, trans
12
12
  import { extendsObject, getCommonPinningStyles, getDefaultOperator, getTypeFilter } from "../hook/utils";
13
13
  import { TableContext } from "../useContext";
14
14
  import { renderFilter } from "./renderFilter";
15
+ import ReactDOMServer from 'react-dom/server';
15
16
  // import { ColumnTable } from "../type";
16
17
 
17
18
  // import { Tooltip } from 'react-tooltip'
@@ -32,7 +33,8 @@ const TableHeadCell = props => {
32
33
  wrapSettings,
33
34
  selectionSettings,
34
35
  setIsSelectionChange,
35
- id
36
+ id,
37
+ locale
36
38
  } = useContext(TableContext);
37
39
  const isPinned = header.column.getIsPinned();
38
40
  const isLastLeftPinnedColumn = isPinned === 'left' && header.column.getIsLastColumn('left');
@@ -47,6 +49,9 @@ const TableHeadCell = props => {
47
49
  const column = header.column.columnDef;
48
50
  const originalColumn = header.column.columnDef.meta ?? {};
49
51
  const filtered = (header.column.getFilterValue() ?? []).length > 0;
52
+ const cellContent = flexRender(header.column.columnDef.header, header.getContext());
53
+ const html = ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement(React.Fragment, null, cellContent));
54
+ const hasValue = html.trim().length > 0;
50
55
 
51
56
  // const filtered = header.column.getIsFiltered()
52
57
 
@@ -248,7 +253,9 @@ const TableHeadCell = props => {
248
253
  width: header.getSize(),
249
254
  ...getCommonPinningStyles(header.column),
250
255
  ...style
251
- }
256
+ },
257
+ "data-tooltip-id": `${id}-tooltip-content`,
258
+ "data-tooltip-html": !hasValue ? '' : ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement("div", null, cellContent))
252
259
  }, /*#__PURE__*/React.createElement("div", {
253
260
  className: classNames('', {
254
261
  [`${prefix}-grid-filter-column`]: header.column.id !== 'selection_column',
@@ -275,11 +282,12 @@ const TableHeadCell = props => {
275
282
  [`${prefix}-grid-cell-ellipsis`]: !wrapSettings || !(wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')),
276
283
  [`${prefix}-grid-cell-text-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')
277
284
  })
278
- }, flexRender(header.column.columnDef.header, header.getContext()))), !nonActionColumn.includes(header.id) && /*#__PURE__*/React.createElement("span", {
285
+ }, cellContent)), !nonActionColumn.includes(header.id) && /*#__PURE__*/React.createElement("span", {
279
286
  className: "ui-rc-header-trigger"
280
287
  }, header.column.getCanSort() && /*#__PURE__*/React.createElement("div", {
281
288
  style: {
282
- marginInlineEnd: 6
289
+ marginInlineEnd: 6,
290
+ cursor: 'pointer'
283
291
  },
284
292
  onClick: e => {
285
293
  setSorterChange(true);
@@ -290,17 +298,28 @@ const TableHeadCell = props => {
290
298
  }
291
299
  }, header.column.getIsSorted() ? header.column.getIsSorted() === 'asc' ? /*#__PURE__*/React.createElement(ArrowUp, {
292
300
  fontSize: 15,
293
- color: '#000',
294
- "data-tooltip-id": `${id}-tooltip-header-trigger`,
295
- "data-tooltip-content": "Nh\u1EA5p \u0111\u1EC3 s\u1EAFp x\u1EBFp gi\u1EA3m d\u1EA7n"
301
+ color: '#000'
302
+ // data-tooltip-id={`${id}-tooltip-header-trigger`}
303
+ ,
304
+ "data-tooltip-id": `${id}-tooltip-content`
305
+ // data-tooltip-content='Nhấp để sắp xếp giảm dần'
306
+ ,
307
+ "data-tooltip-content": locale?.triggerDesc ?? 'Click to sort descending'
296
308
  }) : /*#__PURE__*/React.createElement(ArrowDown, {
297
309
  fontSize: 15,
298
310
  color: '#000',
299
- "data-tooltip-id": `${id}-tooltip-header-trigger`,
300
- "data-tooltip-content": "Nh\u1EA5p \u0111\u1EC3 h\u1EE7y s\u1EAFp x\u1EBFp"
301
- }) : /*#__PURE__*/React.createElement(SortCancel, {
302
- "data-tooltip-id": `${id}-tooltip-header-trigger`,
303
- "data-tooltip-content": "Nh\u1EA5p \u0111\u1EC3 s\u1EAFp x\u1EBFp t\u0103ng d\u1EA7n",
311
+ "data-tooltip-id": `${id}-tooltip-content`
312
+ // data-tooltip-id={`${id}-tooltip-header-trigger`}
313
+ // data-tooltip-content='Nhấp để hủy sắp xếp'
314
+ ,
315
+ "data-tooltip-content": locale?.cancelSort ?? 'Click to cancel sorting'
316
+ }) : /*#__PURE__*/React.createElement(SortCancel
317
+ // data-tooltip-id={`${id}-tooltip-header-trigger`}
318
+ , {
319
+ "data-tooltip-id": `${id}-tooltip-content`
320
+ // data-tooltip-content='Nhấp để sắp xếp tăng dần'
321
+ ,
322
+ "data-tooltip-content": locale?.triggerAsc ?? 'Click to sort ascending',
304
323
  fontSize: 15,
305
324
  style: {
306
325
  display: 'flex'
@@ -12,5 +12,5 @@ interface TableHeadRowProps<T> {
12
12
  fixedRightColumns: Column<T, unknown>[];
13
13
  rowHeaderVirtual: VirtualItem;
14
14
  }
15
- declare const TableHeadRow: ({ table, columnVirtualizer, rowHeaderVirtualizer, headerGroup, virtualPaddingLeft, virtualPaddingRight, fixedLeftColumns, fixedRightColumns, rowHeaderVirtual }: TableHeadRowProps<any>) => React.JSX.Element;
15
+ declare const TableHeadRow: ({ table, columnVirtualizer, rowHeaderVirtualizer, headerGroup, fixedLeftColumns, fixedRightColumns, rowHeaderVirtual }: TableHeadRowProps<any>) => React.JSX.Element;
16
16
  export default TableHeadRow;
@@ -8,8 +8,8 @@ const TableHeadRow = ({
8
8
  columnVirtualizer,
9
9
  rowHeaderVirtualizer,
10
10
  headerGroup,
11
- virtualPaddingLeft,
12
- virtualPaddingRight,
11
+ // virtualPaddingLeft,
12
+ // virtualPaddingRight,
13
13
  fixedLeftColumns,
14
14
  fixedRightColumns,
15
15
  rowHeaderVirtual
@@ -17,7 +17,12 @@ const TableHeadRow = ({
17
17
  const {
18
18
  prefix
19
19
  } = React.useContext(TableContext);
20
- const virtualColumns = columnVirtualizer.getVirtualItems();
20
+
21
+ // const virtualColumns = columnVirtualizer.getVirtualItems()
22
+ const virtualColumns = columnVirtualizer.measurementsCache;
23
+
24
+ // console.log('virtualColumns', virtualColumns)
25
+
21
26
  const columnOrder = table.getState().columnOrder;
22
27
  return /*#__PURE__*/React.createElement("tr", {
23
28
  key: headerGroup.id,
@@ -45,15 +50,9 @@ const TableHeadRow = ({
45
50
  header: headerGroup.headers.find(h => h.column.id === column.id)
46
51
  // column={column as any}
47
52
  });
48
- }) : null, virtualPaddingLeft ? /*#__PURE__*/React.createElement("th", {
49
- className: "",
50
- style: {
51
- display: 'flex',
52
- width: virtualPaddingLeft
53
- }
54
53
  }) : null, virtualColumns.map(virtualColumn => {
55
54
  const header = headerGroup.headers[virtualColumn.index];
56
- const isFixed = table.getState().columnPinning.left?.includes(header.column.id) || table.getState().columnPinning.right?.includes(header.column.id);
55
+ const isFixed = table.getState().columnPinning.left?.includes(header?.column?.id) || table.getState().columnPinning.right?.includes(header?.column?.id);
57
56
  if (header && !isFixed) {
58
57
  return /*#__PURE__*/React.createElement(TableHeadCell, {
59
58
  key: header.id,
@@ -72,15 +71,6 @@ const TableHeadRow = ({
72
71
  key: column.id,
73
72
  header: headerGroup.headers.find(h => h.column.id === column.id)
74
73
  // column={column as any}
75
- })) : null, virtualPaddingRight ?
76
- /*#__PURE__*/
77
- //fake empty column to the right for virtualization scroll padding
78
- React.createElement("th", {
79
- className: "nnnnnnnnnnnn",
80
- style: {
81
- display: 'flex',
82
- width: virtualPaddingRight
83
- }
84
- }) : null));
74
+ })) : null));
85
75
  };
86
76
  export default TableHeadRow;
@@ -1,11 +1,9 @@
1
- import type { ColumnTable, ExpandableConfig, IFormat } from '../type';
2
- import type { ColumnDef, ExpandedState } from '@tanstack/react-table';
1
+ import type { ColumnsTable, ColumnTable, IFormat } from '../type';
2
+ import type { ColumnDef } from '@tanstack/react-table';
3
3
  export declare const renderValueCell: <T>(column: ColumnTable<T>, value: any, record: T, rowIndex: number, colIndex: number, format?: IFormat, editAble?: boolean) => any;
4
- export declare function convertToTanStackColumns<T>({ columns, expanded, setExpanded, expandable, format, editAble }: {
5
- columns: ColumnTable<T>[];
6
- expanded: ExpandedState;
7
- setExpanded: any;
8
- expandable?: ExpandableConfig<T>;
4
+ export declare function convertToTanStackColumns<T>({ t, columns, format, editAble }: {
5
+ t?: any;
6
+ columns: ColumnsTable<T>;
9
7
  format?: IFormat;
10
8
  editAble?: boolean;
11
9
  }): ColumnDef<T, any>[];
@@ -1,6 +1,6 @@
1
1
  import React, { Fragment } from 'react';
2
2
  import ControlCheckbox from "../components/ControlCheckbox";
3
- import { checkDecimalSeparator, checkThousandSeparator, getFormat, isColor, isEmpty } from "./utils";
3
+ import { checkDecimalSeparator, checkThousandSeparator, getFormat, isColor, isEmpty, sortByType } from "./utils";
4
4
  import { numericFormatter } from 'react-numeric-component';
5
5
  import dayjs from 'dayjs';
6
6
  import moment from 'moment';
@@ -57,13 +57,6 @@ export const renderValueCell = (column, value, record, rowIndex, colIndex, forma
57
57
  }
58
58
  }));
59
59
  case 'checkbox':
60
- // return (
61
- // <Checkbox
62
- // checked={!!value}
63
- //
64
- // />
65
- // )
66
-
67
60
  return /*#__PURE__*/React.createElement(ControlCheckbox, {
68
61
  column: column,
69
62
  record: record,
@@ -84,15 +77,17 @@ export const renderValueCell = (column, value, record, rowIndex, colIndex, forma
84
77
  }
85
78
  };
86
79
  export function convertToTanStackColumns({
80
+ t,
87
81
  columns,
88
- expanded,
89
- setExpanded,
90
- expandable,
82
+ // expanded,
83
+ // setExpanded,
84
+ // expandable,
91
85
  format,
92
86
  editAble
93
87
  }) {
94
- const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0;
95
- return columns.map(col => {
88
+ // const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0
89
+
90
+ return sortByType(columns).map(col => {
96
91
  const {
97
92
  headerText,
98
93
  headerTemplate,
@@ -116,14 +111,13 @@ export function convertToTanStackColumns({
116
111
  return headerTemplate;
117
112
  }
118
113
  } else {
119
- return headerText;
114
+ return t ? t(headerText) : headerText;
120
115
  }
121
116
  },
122
117
  cell: props => {
123
118
  const {
124
119
  getValue,
125
- cell,
126
- row
120
+ cell
127
121
  } = props;
128
122
  const cellValue = props.renderValue() ?? null;
129
123
  const record = cell.row.original;
@@ -141,43 +135,11 @@ export function convertToTanStackColumns({
141
135
  return template;
142
136
  }
143
137
  } else {
144
- return /*#__PURE__*/React.createElement(Fragment, null, cell.column.getIndex() === expandIconColumnIndex && /*#__PURE__*/React.createElement("div", {
145
- className: "ui-rc-table-row-expand-trigger",
146
- style: {
147
- paddingLeft: `${row.depth * 25}px`
148
- }
149
- }, /*#__PURE__*/React.createElement("div", null, row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
150
- // onClick: row.getToggleExpandedHandler(),
151
- onClick: () => {
152
- const keys = Object.keys(expanded);
153
- // @ts-ignore
154
- const tmp = {
155
- ...expanded
156
- };
157
- if (keys.includes(row.id)) {
158
- delete tmp[row.id];
159
- setExpanded(tmp);
160
- } else {
161
- setExpanded(old => ({
162
- ...old,
163
- [row.id]: true
164
- }));
165
- }
166
- },
167
- style: {
168
- cursor: "pointer"
169
- },
170
- className: "ui-rc-table-row-expand"
171
- }, row.getIsExpanded() ? /*#__PURE__*/React.createElement("span", {
172
- className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded"
173
- }) : /*#__PURE__*/React.createElement("span", {
174
- className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
175
- })) : /*#__PURE__*/React.createElement("span", {
176
- className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
177
- }))), renderValueCell(col, cellValue, record, rowIndex, colIndex, format, editAble));
138
+ return /*#__PURE__*/React.createElement(Fragment, null, renderValueCell(col, cellValue, record, rowIndex, colIndex, format, editAble));
178
139
  }
179
140
  },
180
141
  enableResizing: allowResizing !== false,
142
+ enableHiding: false,
181
143
  // enableResizing: true,
182
144
  id: field,
183
145
  size: width,
@@ -187,16 +149,14 @@ export function convertToTanStackColumns({
187
149
  // maxSize: maxWidth,
188
150
  enableSorting: allowSorter !== false || col.sorter !== false
189
151
  };
190
-
191
- // if (field) {
192
- // // @ts-ignore
193
- // newCol.accessorKey = field;
194
-
195
- // }
196
-
197
152
  if (children) {
198
153
  // @ts-ignore
199
- newCol.columns = convertToTanStackColumns(children);
154
+ newCol.columns = convertToTanStackColumns({
155
+ columns: children,
156
+ editAble,
157
+ format,
158
+ t
159
+ });
200
160
  }
201
161
  const meta = {
202
162
  ...restProps
@@ -5,6 +5,8 @@ import type { AnyObject, ColumnsTable, ColumnTable, EditType, FilterOperator, IC
5
5
  import { type CSSProperties } from "react";
6
6
  import dayjs from "dayjs";
7
7
  import type { IPositionCell } from "../useContext";
8
+ import type { ColumnDef } from "@tanstack/react-table";
9
+ import type { TreeDataNode } from "antd";
8
10
  export declare const newGuid: () => any;
9
11
  export declare const convertDayjsToDate: (dateString: string, format?: string) => Date;
10
12
  export declare const convertDateToDayjs: (date: Date | undefined, format?: string) => dayjs.Dayjs;
@@ -116,6 +118,16 @@ export declare function addRowsUp(array: any, n: number): {
116
118
  export declare const convertFilters: (filters: any[]) => any[];
117
119
  export declare function getInvisibleColumns(columns: ColumnTable[]): Record<string, boolean>;
118
120
  export declare const getAllVisibleKeys: (columns: any[]) => any[];
121
+ export declare const getAllVisibleKeys1: (columns: ColumnTable[]) => any[];
119
122
  export declare function getHiddenParentKeys(columns: any[], parentKeys?: string[]): string[];
123
+ export declare function getHiddenParentKeys1(columns: ColumnTable[], parentKeys?: string[]): string[];
120
124
  export declare const getVisibleColumnKeys: (columns: any[]) => string[];
125
+ export declare const getVisibleColumnKeys1: (columns: any[]) => string[];
121
126
  export declare function isObjEqual(obj1: any, obj2: any): boolean;
127
+ export declare const sortByType: <T>(arr: ColumnTable<T>[]) => ColumnTable<T>[];
128
+ export declare function convertColumnsToTreeData<T>(columns: ColumnDef<T, any>[], groupColumns?: string[]): TreeDataNode[];
129
+ export declare const updateColumns1: (columns: ColumnTable[], includes: string[]) => ColumnTable[];
130
+ export declare const convertToObj: (arr: any) => {
131
+ [k: string]: any;
132
+ };
133
+ export declare const getDiffent2Array: (a: any[], b: any[]) => any[];
@@ -1681,6 +1681,24 @@ export const getAllVisibleKeys = columns => {
1681
1681
  traverse(columns);
1682
1682
  return keys;
1683
1683
  };
1684
+ export const getAllVisibleKeys1 = columns => {
1685
+ const keys = [];
1686
+ const traverse = (cols, parentHidden = false) => {
1687
+ for (const col of cols) {
1688
+ if (col.visible === false || parentHidden) {
1689
+ continue;
1690
+ }
1691
+ if (col.field) {
1692
+ keys.push(col.field);
1693
+ }
1694
+ if (col.children) {
1695
+ traverse(col.children, col.visible);
1696
+ }
1697
+ }
1698
+ };
1699
+ traverse(columns);
1700
+ return keys;
1701
+ };
1684
1702
  export function getHiddenParentKeys(columns, parentKeys = []) {
1685
1703
  const hiddenParents = new Set();
1686
1704
  for (const column of columns) {
@@ -1697,11 +1715,32 @@ export function getHiddenParentKeys(columns, parentKeys = []) {
1697
1715
  }
1698
1716
  return Array.from(hiddenParents);
1699
1717
  }
1718
+ export function getHiddenParentKeys1(columns, parentKeys = []) {
1719
+ const hiddenParents = new Set();
1720
+ for (const column of columns) {
1721
+ if (column.children) {
1722
+ const currentPath = column.field ? [...parentKeys, column.field] : [...parentKeys];
1723
+ const childHiddenParents = getHiddenParentKeys(column.children, currentPath);
1724
+ if (childHiddenParents.length > 0) {
1725
+ childHiddenParents.forEach(key => hiddenParents.add(key));
1726
+ currentPath.forEach(key => hiddenParents.add(key));
1727
+ }
1728
+ } else if (column.visible !== false) {
1729
+ parentKeys.forEach(key => hiddenParents.add(key));
1730
+ }
1731
+ }
1732
+ return Array.from(hiddenParents);
1733
+ }
1700
1734
  export const getVisibleColumnKeys = columns => {
1701
1735
  const allKeys = getAllVisibleKeys(columns);
1702
1736
  const allParentKeys = getHiddenParentKeys(columns);
1703
1737
  return allKeys.filter(item => !allParentKeys.includes(item));
1704
1738
  };
1739
+ export const getVisibleColumnKeys1 = columns => {
1740
+ const allKeys = getAllVisibleKeys1(columns);
1741
+ const allParentKeys = getHiddenParentKeys1(columns);
1742
+ return allKeys.filter(item => !allParentKeys.includes(item));
1743
+ };
1705
1744
  export function isObjEqual(obj1, obj2) {
1706
1745
  // Trường hợp tham chiếu bằng nhau
1707
1746
  if (obj1 === obj2) return true;
@@ -1724,4 +1763,108 @@ export function isObjEqual(obj1, obj2) {
1724
1763
  if (!isObjEqual(obj1[key], obj2[key])) return false;
1725
1764
  }
1726
1765
  return true;
1727
- }
1766
+ }
1767
+
1768
+ // Sorting function
1769
+ export const sortByType = arr => {
1770
+ if (arr) {
1771
+ return arr.sort((a, b) => {
1772
+ if (a.fixed === 'left' && b.fixed !== 'left') {
1773
+ return -1;
1774
+ } else if (a.fixed !== 'left' && b.fixed === 'left') {
1775
+ return 1;
1776
+ } else if (a.fixed === 'right' && b.fixed !== 'right') {
1777
+ return 1;
1778
+ } else if (a.fixed !== 'right' && b.fixed === 'right') {
1779
+ return -1;
1780
+ }
1781
+ return 0;
1782
+ });
1783
+ } else {
1784
+ return [];
1785
+ }
1786
+ };
1787
+ export function convertColumnsToTreeData(columns, groupColumns) {
1788
+ // return columns.map((col) => {
1789
+ // const node: TreeDataNode = {
1790
+ // key: String(col.id ?? col.id ?? col.header), // key duy nhất
1791
+ // title: String(col.header ?? col.id ?? ''), // tiêu đề
1792
+ // }
1793
+
1794
+ // // Nếu có children (nested columns)
1795
+ // if ('columns' in col && Array.isArray((col as any).columns)) {
1796
+ // node.children = convertColumnsToTreeData(
1797
+ // (col as any).columns as ColumnDef<T, any>[]
1798
+ // )
1799
+ // }
1800
+
1801
+ // return node
1802
+ // })
1803
+
1804
+ return columns.filter(col => {
1805
+ const meta = col.meta ?? {};
1806
+ const inGroup = groupColumns ? groupColumns.includes(String(col.id ?? col.id)) : false;
1807
+
1808
+ // Điều kiện filter:
1809
+ // - Nếu meta.showInColumnChoose = false => loại bỏ
1810
+ // - Nếu không nằm trong groupColumns và không phải column group => loại bỏ
1811
+ if (meta.showInColumnChoose === false) return false;
1812
+ if (inGroup && !('columns' in col && Array.isArray(col.columns))) {
1813
+ return false;
1814
+ }
1815
+ return true;
1816
+ }).map(col => {
1817
+ const node = {
1818
+ key: String(col.id ?? col.id ?? col.header),
1819
+ // title: () => col.header as any
1820
+ title: col.header
1821
+
1822
+ // title: String(col.header ?? col.id ?? ''),
1823
+ };
1824
+ if ('columns' in col && Array.isArray(col.columns)) {
1825
+ const children = convertColumnsToTreeData(col.columns, groupColumns);
1826
+ if (children.length > 0) {
1827
+ node.children = children;
1828
+ }
1829
+ }
1830
+ return node;
1831
+ });
1832
+ }
1833
+ export const updateColumns1 = (columns, includes) => {
1834
+ return columns.map(column => {
1835
+ const newColumn = {
1836
+ ...column
1837
+ };
1838
+ let hasVisibleChild = false;
1839
+ if (!column.field) {
1840
+ return column;
1841
+ }
1842
+ if (newColumn.children) {
1843
+ newColumn.children = updateColumns1(newColumn.children, includes);
1844
+ hasVisibleChild = newColumn.children.some(child => !child.hidden);
1845
+ }
1846
+
1847
+ // newColumn.hidden = newColumn.key && !includes.includes(newColumn.key)
1848
+ newColumn.visible = !!(newColumn.field && includes.includes(newColumn.field));
1849
+ // newColumn.fixed = newColumn.field && !includes.includes(newColumn.field) ? undefined : newColumn.fixed
1850
+
1851
+ if (newColumn.children && newColumn.children.length > 0) {
1852
+ newColumn.visible = !hasVisibleChild;
1853
+ // newColumn.fixed = !hasVisibleChild ? undefined : newColumn.fixed
1854
+ }
1855
+ return newColumn;
1856
+ });
1857
+ };
1858
+ export const convertToObj = arr => {
1859
+ // const result = Object.keys(obj).reduce((acc: any, key) => {
1860
+ // acc[key] = false;
1861
+ // return acc;
1862
+ // }, {});
1863
+
1864
+ // return result
1865
+
1866
+ return Object.fromEntries(arr.map(key => [key, false]));
1867
+ };
1868
+ export const getDiffent2Array = (a, b) => {
1869
+ return [...a.filter(x => !b.includes(x)), ...b.filter(x => !a.includes(x))];
1870
+ };
@@ -494,6 +494,25 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
494
494
  background-color: $cell-selected-bg !important;
495
495
  }
496
496
 
497
+ &.disable {
498
+ padding: 7px 8px !important;
499
+ background-color: #f0f0f0;
500
+ }
501
+
502
+
503
+ &.isValid {
504
+ &::after {
505
+ content: "";
506
+ position: absolute;
507
+ top: 0;
508
+ right: 0;
509
+ width: 0;
510
+ height: 0;
511
+ border-top: 0 solid transparent;
512
+ border-right: 8px solid red;
513
+ border-bottom: 8px solid transparent;
514
+ }
515
+ }
497
516
  }
498
517
 
499
518
  }
@@ -960,7 +979,8 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
960
979
  .#{$prefix}-checkbox-indeterminate {
961
980
  &:hover {
962
981
  .#{$prefix}-checkbox-inner {
963
- border-color: $primary !important;;
982
+ border-color: $primary !important;
983
+ ;
964
984
  }
965
985
  }
966
986
 
@@ -970,6 +990,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
970
990
  }
971
991
  }
972
992
  }
993
+
973
994
  //.#{$prefix}-checkbox-input {
974
995
  // &:focus-visible {
975
996
  // outline: none;
@@ -1024,6 +1045,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
1024
1045
  border-color: $primary;
1025
1046
  }
1026
1047
  }
1048
+
1027
1049
  &:hover {
1028
1050
  .ui-rc-radio-inner {
1029
1051
  border-color: $primary;
@@ -1080,4 +1102,28 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
1080
1102
  border-color: $primary;
1081
1103
  }
1082
1104
  }
1105
+ }
1106
+
1107
+ .ui-rc-pagination {
1108
+ border-bottom: 1px solid #e0e0e0;
1109
+ border-top: 1px solid #e0e0e0;
1110
+ margin: 0;
1111
+ padding: .75rem 1rem;
1112
+ background-color: #ffffff;
1113
+
1114
+ .ui-rc-pagination-total-text {
1115
+ order: 2;
1116
+ margin-left: auto;
1117
+ }
1118
+
1119
+
1120
+
1121
+ &.pagination-template {
1122
+ position: relative;
1123
+
1124
+
1125
+ }
1126
+
1127
+
1128
+
1083
1129
  }
@@ -8,16 +8,17 @@ type Props<T> = Omit<TableProps<T>, 'columns'> & {
8
8
  prefix: string;
9
9
  columns: ColumnDef<T>[];
10
10
  propsColumns: ColumnsTable;
11
- columnVisibility: VisibilityState;
11
+ columnHidden: VisibilityState;
12
12
  expanded: ExpandedState;
13
+ setExpanded: any;
13
14
  columnPinning: ColumnPinningState;
14
15
  originData: T[];
15
16
  mergedFilterKeys: any;
16
17
  setMergedFilterKeys: any;
17
- isFullScreen: boolean;
18
18
  triggerFilter: Dispatch<SetStateAction<any>>;
19
19
  triggerSorter: Dispatch<SetStateAction<Sorter[]>>;
20
20
  onContextMenu?: (data: T) => (event: any) => void;
21
+ triggerChangeColumns?: (args: any, keys: any) => void;
21
22
  };
22
23
  declare const Grid: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
23
24
  export default Grid;