es-grid-template 1.8.64 → 1.8.65

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 (125) hide show
  1. package/es/grid-component/ColumnsGroup/ColumnsGroup.js +4 -1
  2. package/es/grid-component/TempTable.js +2 -2
  3. package/es/grid-component/hooks/utils.d.ts +2 -8
  4. package/es/grid-component/hooks/utils.js +175 -144
  5. package/es/grid-component/index.d.ts +1 -1
  6. package/es/grid-component/index.js +0 -4
  7. package/es/grid-component/type.d.ts +7 -0
  8. package/es/table-component/type.d.ts +8 -0
  9. package/es/table-virtuoso/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  10. package/es/table-virtuoso/ColumnsGroup/ColumnsGroup.js +232 -0
  11. package/es/table-virtuoso/ColumnsGroup/index.d.ts +1 -0
  12. package/es/table-virtuoso/ColumnsGroup/index.js +1 -0
  13. package/es/{grid-component → table-virtuoso}/InternalTable.d.ts +2 -3
  14. package/es/table-virtuoso/InternalTable.js +413 -0
  15. package/es/table-virtuoso/body/TableBody.d.ts +14 -0
  16. package/es/table-virtuoso/body/TableBody.js +84 -0
  17. package/es/table-virtuoso/body/TableBodyCell.d.ts +14 -0
  18. package/es/table-virtuoso/body/TableBodyCell.js +466 -0
  19. package/es/table-virtuoso/body/TableBodyRow.d.ts +13 -0
  20. package/es/table-virtuoso/body/TableBodyRow.js +116 -0
  21. package/es/table-virtuoso/footer/TableFooterCell.d.ts +7 -0
  22. package/es/table-virtuoso/footer/TableFooterCell.js +54 -0
  23. package/es/table-virtuoso/header/TableHeadCell.d.ts +14 -0
  24. package/es/table-virtuoso/header/TableHeadCell.js +265 -0
  25. package/es/table-virtuoso/header/renderFilter.d.ts +20 -0
  26. package/es/table-virtuoso/header/renderFilter.js +289 -0
  27. package/es/table-virtuoso/hook/constant.d.ts +73 -0
  28. package/es/table-virtuoso/hook/constant.js +240 -0
  29. package/es/table-virtuoso/hook/convert.d.ts +1 -0
  30. package/es/table-virtuoso/hook/convert.js +28 -0
  31. package/es/table-virtuoso/hook/useColumns.d.ts +28 -0
  32. package/es/table-virtuoso/hook/useColumns.js +302 -0
  33. package/es/table-virtuoso/hook/useFilterOperator.d.ts +7 -0
  34. package/es/table-virtuoso/hook/useFilterOperator.js +33 -0
  35. package/es/table-virtuoso/hook/utils.d.ts +159 -0
  36. package/es/table-virtuoso/hook/utils.js +2263 -0
  37. package/es/table-virtuoso/index.d.ts +2 -0
  38. package/es/table-virtuoso/index.js +2 -0
  39. package/es/table-virtuoso/style.d.ts +22 -0
  40. package/es/table-virtuoso/style.js +11 -0
  41. package/es/table-virtuoso/style.scss +1440 -0
  42. package/es/table-virtuoso/table/Grid.d.ts +37 -0
  43. package/es/table-virtuoso/table/Grid.js +302 -0
  44. package/es/table-virtuoso/table/TableContainer.d.ts +49 -0
  45. package/es/table-virtuoso/table/TableContainer.js +305 -0
  46. package/es/table-virtuoso/table/TableWrapper.d.ts +20 -0
  47. package/es/table-virtuoso/table/TableWrapper.js +158 -0
  48. package/es/table-virtuoso/type.d.ts +0 -0
  49. package/es/table-virtuoso/type.js +785 -0
  50. package/es/table-virtuoso/useContext.d.ts +97 -0
  51. package/es/table-virtuoso/useContext.js +21 -0
  52. package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +4 -1
  53. package/lib/grid-component/TempTable.js +2 -2
  54. package/lib/grid-component/hooks/utils.d.ts +2 -8
  55. package/lib/grid-component/hooks/utils.js +176 -152
  56. package/lib/grid-component/index.d.ts +1 -1
  57. package/lib/grid-component/index.js +0 -3
  58. package/lib/grid-component/type.d.ts +7 -0
  59. package/lib/table-component/type.d.ts +8 -0
  60. package/lib/table-virtuoso/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  61. package/lib/table-virtuoso/ColumnsGroup/ColumnsGroup.js +243 -0
  62. package/lib/table-virtuoso/ColumnsGroup/index.d.ts +1 -0
  63. package/lib/table-virtuoso/ColumnsGroup/index.js +16 -0
  64. package/lib/{grid-component → table-virtuoso}/InternalTable.d.ts +2 -3
  65. package/lib/table-virtuoso/InternalTable.js +422 -0
  66. package/lib/table-virtuoso/body/TableBody.d.ts +14 -0
  67. package/lib/table-virtuoso/body/TableBody.js +95 -0
  68. package/lib/table-virtuoso/body/TableBodyCell.d.ts +14 -0
  69. package/lib/table-virtuoso/body/TableBodyCell.js +473 -0
  70. package/lib/table-virtuoso/body/TableBodyRow.d.ts +13 -0
  71. package/lib/table-virtuoso/body/TableBodyRow.js +124 -0
  72. package/lib/table-virtuoso/footer/TableFooterCell.d.ts +7 -0
  73. package/lib/table-virtuoso/footer/TableFooterCell.js +63 -0
  74. package/lib/table-virtuoso/header/TableHeadCell.d.ts +14 -0
  75. package/lib/table-virtuoso/header/TableHeadCell.js +274 -0
  76. package/lib/table-virtuoso/header/renderFilter.d.ts +20 -0
  77. package/lib/table-virtuoso/header/renderFilter.js +299 -0
  78. package/lib/table-virtuoso/hook/constant.d.ts +73 -0
  79. package/lib/table-virtuoso/hook/constant.js +247 -0
  80. package/lib/table-virtuoso/hook/convert.d.ts +1 -0
  81. package/lib/table-virtuoso/hook/convert.js +34 -0
  82. package/lib/table-virtuoso/hook/useColumns.d.ts +28 -0
  83. package/lib/table-virtuoso/hook/useColumns.js +315 -0
  84. package/lib/table-virtuoso/hook/useFilterOperator.d.ts +7 -0
  85. package/lib/table-virtuoso/hook/useFilterOperator.js +40 -0
  86. package/lib/table-virtuoso/hook/utils.d.ts +159 -0
  87. package/lib/table-virtuoso/hook/utils.js +2389 -0
  88. package/lib/table-virtuoso/index.d.ts +2 -0
  89. package/lib/table-virtuoso/index.js +9 -0
  90. package/lib/table-virtuoso/style.d.ts +22 -0
  91. package/lib/table-virtuoso/style.js +18 -0
  92. package/lib/table-virtuoso/style.scss +1440 -0
  93. package/lib/table-virtuoso/table/Grid.d.ts +37 -0
  94. package/lib/table-virtuoso/table/Grid.js +311 -0
  95. package/lib/table-virtuoso/table/TableContainer.d.ts +49 -0
  96. package/lib/table-virtuoso/table/TableContainer.js +313 -0
  97. package/lib/table-virtuoso/table/TableWrapper.d.ts +20 -0
  98. package/lib/table-virtuoso/table/TableWrapper.js +164 -0
  99. package/lib/table-virtuoso/type.d.ts +0 -0
  100. package/lib/table-virtuoso/type.js +786 -0
  101. package/lib/table-virtuoso/useContext.d.ts +97 -0
  102. package/lib/table-virtuoso/useContext.js +27 -0
  103. package/package.json +2 -1
  104. package/es/grid-component/ConvertColumnTable.d.ts +0 -7
  105. package/es/grid-component/ConvertColumnTable.js +0 -144
  106. package/es/grid-component/InternalTable.js +0 -1170
  107. package/es/grid-component/table/Grid.d.ts +0 -23
  108. package/es/grid-component/table/Grid.js +0 -49
  109. package/es/grid-component/table/GridEdit.d.ts +0 -23
  110. package/es/grid-component/table/GridEdit.js +0 -2726
  111. package/es/grid-component/table/Group.d.ts +0 -21
  112. package/es/grid-component/table/Group.js +0 -195
  113. package/es/grid-component/table/InfiniteTable.d.ts +0 -23
  114. package/es/grid-component/table/InfiniteTable.js +0 -101
  115. package/lib/grid-component/ConvertColumnTable.d.ts +0 -7
  116. package/lib/grid-component/ConvertColumnTable.js +0 -153
  117. package/lib/grid-component/InternalTable.js +0 -1178
  118. package/lib/grid-component/table/Grid.d.ts +0 -23
  119. package/lib/grid-component/table/Grid.js +0 -58
  120. package/lib/grid-component/table/GridEdit.d.ts +0 -23
  121. package/lib/grid-component/table/GridEdit.js +0 -2723
  122. package/lib/grid-component/table/Group.d.ts +0 -21
  123. package/lib/grid-component/table/Group.js +0 -204
  124. package/lib/grid-component/table/InfiniteTable.d.ts +0 -23
  125. package/lib/grid-component/table/InfiniteTable.js +0 -109
@@ -0,0 +1,73 @@
1
+ export declare const defaultWidth: number;
2
+ export declare const defaultRowHeight: number;
3
+ export type IOperator = {
4
+ value: string;
5
+ label: string;
6
+ key: string;
7
+ };
8
+ export declare const numberOperator: IOperator[];
9
+ export declare const stringOperator: IOperator[];
10
+ export declare const dateOperator: IOperator[];
11
+ export declare const dateTimeOperator: IOperator[];
12
+ export declare const booleanOperator: IOperator[];
13
+ export declare const translateOption: (options: IOperator[], t: any) => any[];
14
+ export declare const transferFontSize: any;
15
+ export declare const defaultDateFormat = "d/m/Y";
16
+ export declare const defaultDateTimeFormat = "d/m/Y H:i";
17
+ export declare const defaultTimeFormat = "H:i";
18
+ export declare const defaultPageSizes: number[];
19
+ export declare const alignToFlex: any;
20
+ export declare const optionsSize: {
21
+ label: string;
22
+ value: string;
23
+ width: number;
24
+ height: number;
25
+ }[];
26
+ export declare const paperSize: {
27
+ a4: {
28
+ width: number;
29
+ height: number;
30
+ };
31
+ a3: {
32
+ width: number;
33
+ height: number;
34
+ };
35
+ letter: {
36
+ width: number;
37
+ height: number;
38
+ };
39
+ };
40
+ export declare const optionFont: {
41
+ value: string;
42
+ label: string;
43
+ }[];
44
+ export declare const optionsPaperOrientation: any[];
45
+ export declare const optionFontSize: {
46
+ value: number;
47
+ label: string;
48
+ }[];
49
+ /**
50
+ * Sort order for BaseTable
51
+ */
52
+ declare const SortOrder: {
53
+ /**
54
+ * Sort data in ascending order
55
+ */
56
+ ascend: string;
57
+ /**
58
+ * Sort data in descending order
59
+ */
60
+ descend: string;
61
+ };
62
+ export default SortOrder;
63
+ export declare const valueToBoolean: {
64
+ true: boolean;
65
+ false: boolean;
66
+ 1: boolean;
67
+ 0: boolean;
68
+ };
69
+ export declare const booleanToValue: {
70
+ true: number;
71
+ false: number;
72
+ };
73
+ export declare const nonActionColumn: string[];
@@ -0,0 +1,240 @@
1
+ export const defaultWidth = 100;
2
+ export const defaultRowHeight = 35;
3
+ export const numberOperator = [{
4
+ value: 'equal',
5
+ label: 'Equal',
6
+ key: '=='
7
+ }, {
8
+ value: 'greaterthan',
9
+ label: 'Greater than',
10
+ key: '>'
11
+ }, {
12
+ value: 'greaterthanorequal',
13
+ label: 'Greater than or equal',
14
+ key: '>='
15
+ }, {
16
+ value: 'lessthan',
17
+ label: 'Less than',
18
+ key: '<'
19
+ }, {
20
+ value: 'lessthanorequal',
21
+ label: 'Less than or equal',
22
+ key: '<='
23
+ }, {
24
+ value: 'notequal',
25
+ label: 'Not equal',
26
+ key: '!='
27
+ }];
28
+ export const stringOperator = [{
29
+ value: 'startswith',
30
+ key: '_=',
31
+ label: 'Starts with'
32
+ }, {
33
+ value: 'endswith',
34
+ key: '|=',
35
+ label: 'Ends with'
36
+ }, {
37
+ value: 'contains',
38
+ key: '~=',
39
+ label: 'Contains'
40
+ }, {
41
+ value: 'equal',
42
+ key: '==',
43
+ label: 'Equal'
44
+ }, {
45
+ value: 'notequal',
46
+ key: '!=',
47
+ label: 'Not equal'
48
+ }];
49
+ export const dateOperator = [{
50
+ value: 'equal',
51
+ key: '==',
52
+ label: 'Equal'
53
+ }, {
54
+ value: 'notequal',
55
+ key: '!=',
56
+ label: 'Not equal'
57
+ }, {
58
+ value: 'greaterthan',
59
+ key: '>',
60
+ label: 'Greater than'
61
+ }, {
62
+ value: 'lessthan',
63
+ key: '<',
64
+ label: 'Less than'
65
+ }];
66
+ export const dateTimeOperator = [{
67
+ value: 'equal',
68
+ key: '==',
69
+ label: 'Equal'
70
+ }, {
71
+ value: 'notequal',
72
+ key: '!=',
73
+ label: 'Not equal'
74
+ }, {
75
+ value: 'greaterthan',
76
+ key: '>',
77
+ label: 'Greater than'
78
+ }, {
79
+ value: 'lessthan',
80
+ key: '<',
81
+ label: 'Less than'
82
+ }];
83
+ export const booleanOperator = [{
84
+ value: 'equal',
85
+ key: '==',
86
+ label: 'Equal'
87
+ }, {
88
+ value: 'notequal',
89
+ key: '!=',
90
+ label: 'Not equal'
91
+ }];
92
+ export const translateOption = (options, t) => {
93
+ if (!t) {
94
+ return options;
95
+ }
96
+ return options.map(it => ({
97
+ ...it,
98
+ label: t(it.label)
99
+ }));
100
+ };
101
+ export const transferFontSize = {
102
+ 6: 8,
103
+ 7: 9,
104
+ 8: 11,
105
+ 9: 12,
106
+ 10: 13,
107
+ 11: 15,
108
+ 12: 16,
109
+ 13: 17,
110
+ 14: 19,
111
+ 15: 20,
112
+ 16: 21,
113
+ 17: 23,
114
+ 18: 24,
115
+ 19: 25,
116
+ 20: 27,
117
+ 21: 28,
118
+ 22: 29,
119
+ 24: 32,
120
+ 26: 35,
121
+ 27: 36,
122
+ 28: 37
123
+ };
124
+ export const defaultDateFormat = 'd/m/Y';
125
+ export const defaultDateTimeFormat = 'd/m/Y H:i';
126
+ export const defaultTimeFormat = 'H:i';
127
+ export const defaultPageSizes = [20, 30, 50, 100];
128
+ export const alignToFlex = {
129
+ center: 'center',
130
+ left: 'start',
131
+ right: 'end'
132
+ };
133
+ export const optionsSize = [{
134
+ label: 'letter',
135
+ value: 'letter',
136
+ width: 21.59,
137
+ height: 27.94
138
+ }, {
139
+ label: 'A3',
140
+ value: 'a3',
141
+ width: 27.94,
142
+ height: 42
143
+ }, {
144
+ label: 'A4',
145
+ value: 'a4',
146
+ width: 21,
147
+ height: 29.7
148
+ }];
149
+ export const paperSize = {
150
+ a4: {
151
+ width: 21,
152
+ height: 29.7
153
+ },
154
+ a3: {
155
+ width: 27.94,
156
+ height: 42
157
+ },
158
+ letter: {
159
+ width: 21.59,
160
+ height: 27.94
161
+ }
162
+ };
163
+ export const optionFont = [{
164
+ value: 'Times New Roman',
165
+ label: 'Times New Roman'
166
+ }, {
167
+ value: 'Calibri',
168
+ label: 'Calibri (Body)'
169
+ }];
170
+ // portrait' | 'landscape'
171
+ export const optionsPaperOrientation = [{
172
+ value: 'portrait',
173
+ label: 'portrait'
174
+ }, {
175
+ value: 'landscape',
176
+ label: 'landscape'
177
+ }];
178
+ export const optionFontSize = [{
179
+ value: 8,
180
+ label: '8'
181
+ }, {
182
+ value: 9,
183
+ label: '9'
184
+ }, {
185
+ value: 10,
186
+ label: '10'
187
+ }, {
188
+ value: 11,
189
+ label: '11'
190
+ }, {
191
+ value: 12,
192
+ label: '12'
193
+ }, {
194
+ value: 13,
195
+ label: '13'
196
+ }, {
197
+ value: 14,
198
+ label: '14'
199
+ }, {
200
+ value: 16,
201
+ label: '16'
202
+ }, {
203
+ value: 18,
204
+ label: '18'
205
+ }, {
206
+ value: 24,
207
+ label: '24'
208
+ }, {
209
+ value: 36,
210
+ label: '36'
211
+ }, {
212
+ value: 48,
213
+ label: '48'
214
+ }];
215
+
216
+ /**
217
+ * Sort order for BaseTable
218
+ */
219
+ const SortOrder = {
220
+ /**
221
+ * Sort data in ascending order
222
+ */
223
+ ascend: 'Ascending',
224
+ /**
225
+ * Sort data in descending order
226
+ */
227
+ descend: 'Descending'
228
+ };
229
+ export default SortOrder;
230
+ export const valueToBoolean = {
231
+ true: true,
232
+ false: false,
233
+ 1: true,
234
+ 0: false
235
+ };
236
+ export const booleanToValue = {
237
+ true: 1,
238
+ false: 0
239
+ };
240
+ export const nonActionColumn = ['#', 'command', 'selection_column'];
@@ -0,0 +1 @@
1
+ export declare function convertColumns(columns: any[]): any[];
@@ -0,0 +1,28 @@
1
+ import { createColumnHelper } from '@tanstack/react-table';
2
+ const columnHelper = createColumnHelper();
3
+ export function convertColumns(columns) {
4
+ return columns.map(col => {
5
+ if (col.columns) {
6
+ // Group column
7
+ return columnHelper.group({
8
+ ...col,
9
+ columns: convertColumns(col.columns) // đệ quy
10
+ });
11
+ } else {
12
+ // Accessor column
13
+ let accessor;
14
+
15
+ // Ưu tiên accessorKey nếu có, nếu không thì dùng hàm row => row[col.id]
16
+ if (col.accessorKey) {
17
+ accessor = col.accessorKey;
18
+ } else if (col.id) {
19
+ accessor = row => row[col.id];
20
+ } else {
21
+ throw new Error('Column không có accessorKey hoặc id');
22
+ }
23
+ return columnHelper.accessor(accessor, {
24
+ ...col
25
+ });
26
+ }
27
+ });
28
+ }
@@ -0,0 +1,28 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ import type { ColumnsTable, ColumnTable, IFormat, SelectionSettings } from '../../table-component/type';
3
+ import type { Cell, ColumnDef } from '@tanstack/react-table';
4
+ export declare const renderValueCell: <T>(column: ColumnTable<T>, value: any, record: T, rowIndex: number, colIndex: number, format?: IFormat, editAble?: boolean) => any;
5
+ export declare function convertToTanStackColumns<T>({ t, columns, format, editAble }: {
6
+ t?: any;
7
+ columns: ColumnsTable<T>;
8
+ format?: IFormat;
9
+ editAble?: boolean;
10
+ }): ColumnDef<T, any>[];
11
+ export type ToggleRow<T> = {
12
+ e: any;
13
+ cell: Cell<T, unknown>;
14
+ selectionSettings?: SelectionSettings;
15
+ isSelectionChange?: {
16
+ isChange: boolean;
17
+ type: string;
18
+ rowData: T;
19
+ rowsData: T[];
20
+ };
21
+ setIsSelectionChange: Dispatch<SetStateAction<{
22
+ isChange: boolean;
23
+ type: string;
24
+ rowData: T;
25
+ rowsData: T[];
26
+ }>>;
27
+ };
28
+ export declare const toggleRowSelection: <T>(props: ToggleRow<T>) => void;
@@ -0,0 +1,302 @@
1
+ import React, { Fragment } from 'react';
2
+ // import ControlCheckbox from '../components/ControlCheckbox'
3
+ import { checkDecimalSeparator, checkThousandSeparator, countUnselectedChildren, excludeItems, getAllChildren, getFormat, isColor, isEmpty, sortByType, toggleRowAndChildren } from "./utils";
4
+ import { numericFormatter } from 'react-numeric-component';
5
+ import dayjs from 'dayjs';
6
+ import moment from 'moment';
7
+ import ControlCheckbox from "../../table-component/components/ControlCheckbox";
8
+ export const renderValueCell = (column, value, record, rowIndex, colIndex, format, editAble) => {
9
+ switch (column?.type) {
10
+ case 'number':
11
+ const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
12
+ const cellFormat = getFormat(colFormat, format);
13
+ const thousandSeparator = cellFormat?.thousandSeparator;
14
+ const decimalSeparator = cellFormat?.decimalSeparator;
15
+ const dec = cellFormat?.decimalScale;
16
+
17
+ // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? parseFloat(Number(value).toFixed(dec)).toString() : value.toString()) : '0'
18
+
19
+ const tmpval = typeof value === 'string' ? Number(value) : value;
20
+ const numericFormatProps = {
21
+ thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
22
+ decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
23
+ allowNegative: cellFormat?.allowNegative ?? true,
24
+ prefix: cellFormat?.prefix,
25
+ suffix: cellFormat?.suffix,
26
+ decimalScale: dec,
27
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
28
+ };
29
+
30
+ // if ( typeof value === "string") {
31
+ // const ttt = removeNumericFormat(value, undefined, numericFormatProps )
32
+ //
33
+ // }
34
+
35
+ const contentNumber = !isEmpty(value) ? dec || dec === 0 ? parseFloat(tmpval.toFixed(dec)).toString() : tmpval.toString() : '0';
36
+ // const contentNumber = !isEmpty(value) ? ((dec || dec === 0) ? tmpval.toString() : tmpval.toString()) : '0'
37
+
38
+ return !isEmpty(contentNumber) ? numericFormatter(contentNumber, numericFormatProps) : '';
39
+ case 'date':
40
+ return value ? dayjs(value).format(format?.dateFormat ?? 'DD/MM/YYYY') : '';
41
+ case 'time':
42
+ return value ? value : '';
43
+ case 'year':
44
+ const year = value ? moment(value).format('yyyy') : '';
45
+ return /*#__PURE__*/React.createElement(Fragment, null, year);
46
+ case 'datetime':
47
+ return value ? moment(value).format(format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm') : '';
48
+ case 'boolean':
49
+ return value ? 'true' : 'false';
50
+ case 'color':
51
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
52
+ className: 'w-100 h-100',
53
+ style: {
54
+ backgroundColor: isColor(value) ? value : '#fff',
55
+ border: '1px solid #f0f0f0',
56
+ height: '100%',
57
+ minHeight: 20
58
+ }
59
+ }));
60
+ case 'checkbox':
61
+ return /*#__PURE__*/React.createElement(ControlCheckbox, {
62
+ column: column,
63
+ record: record,
64
+ rowIndex: rowIndex,
65
+ colIndex: colIndex,
66
+ checked: !!value,
67
+ checkValue: value,
68
+ editAble: editAble
69
+ });
70
+ case 'file':
71
+ const nameFile = typeof value === 'object' && !Array.isArray(value) ? value.name : Array.isArray(value) ? value.map(it => typeof it === 'object' ? it.name : it).filter(Boolean).join(", ") : '';
72
+ return value ? nameFile : '';
73
+ default:
74
+ if (Array.isArray(value)) {
75
+ return value.join(', ');
76
+ }
77
+ return value;
78
+ }
79
+ };
80
+ export function convertToTanStackColumns({
81
+ t,
82
+ columns,
83
+ format,
84
+ editAble
85
+ }) {
86
+ return sortByType(columns).map(col => {
87
+ const {
88
+ headerText,
89
+ headerTemplate,
90
+ field,
91
+ width,
92
+ allowResizing,
93
+ minWidth,
94
+ template,
95
+ allowSortering,
96
+ allowFiltering
97
+ } = col;
98
+ const {
99
+ children,
100
+ ...restProps
101
+ } = col;
102
+ const newCol = {
103
+ header: () => {
104
+ if (headerTemplate) {
105
+ if (typeof headerTemplate === 'function') {
106
+ return headerTemplate(col);
107
+ } else {
108
+ return headerTemplate;
109
+ }
110
+ } else {
111
+ return t ? t(headerText) : headerText;
112
+ // return field
113
+ }
114
+ },
115
+ cell: props => {
116
+ const {
117
+ getValue,
118
+ cell
119
+ } = props;
120
+ const cellValue = props.renderValue() ?? null;
121
+ const record = cell.row.original;
122
+ const colIndex = cell.column.getIndex();
123
+ const rowIndex = cell.row.index;
124
+ if (template) {
125
+ if (typeof template === 'function') {
126
+ return template({
127
+ field: field ?? '',
128
+ index: cell.row.index,
129
+ rowData: cell.row.original,
130
+ value: getValue()
131
+ });
132
+ } else {
133
+ return template;
134
+ }
135
+ } else {
136
+ return /*#__PURE__*/React.createElement(Fragment, null, renderValueCell(col, cellValue, record, rowIndex, colIndex, format, editAble));
137
+ }
138
+ },
139
+ enableResizing: allowResizing !== false,
140
+ // enableHiding: false,
141
+ // enableResizing: true,
142
+ id: field,
143
+ size: width,
144
+ accessorKey: field,
145
+ sortDescFirst: false,
146
+ minSize: minWidth,
147
+ // maxSize: maxWidth,
148
+ enableSorting: allowSortering !== false,
149
+ // enableSorting: false,
150
+ // enableColumnFilter: allowFiltering !== false && !nonActionColumn.includes(field)
151
+ enableColumnFilter: allowFiltering !== false
152
+ };
153
+ if (children) {
154
+ newCol.size = undefined;
155
+ // @ts-ignore
156
+ newCol.columns = convertToTanStackColumns({
157
+ columns: children,
158
+ editAble,
159
+ format,
160
+ t
161
+ });
162
+ }
163
+ const meta = {
164
+ ...restProps
165
+ };
166
+ if (Object.keys(meta).length > 0) {
167
+ newCol.meta = meta;
168
+ }
169
+ return newCol;
170
+ });
171
+ }
172
+ export const toggleRowSelection = props => {
173
+ const {
174
+ selectionSettings,
175
+ cell,
176
+ isSelectionChange,
177
+ e,
178
+ setIsSelectionChange
179
+ } = props;
180
+ const {
181
+ row
182
+ } = cell;
183
+ const {
184
+ rowsData
185
+ } = isSelectionChange ?? {};
186
+ const prevSelected = rowsData && rowsData.length > 0 ? [...rowsData] : [];
187
+ if (selectionSettings?.checkStrictly || selectionSettings?.type === 'single') {
188
+ row.getToggleSelectedHandler()(e);
189
+ if (row.getIsSelected()) {
190
+ // đã chọn
191
+
192
+ // xóa row ra list selected
193
+ const newRowsSelected = prevSelected.filter(it => it.id !== row.id);
194
+ setIsSelectionChange({
195
+ isChange: true,
196
+ type: 'rowSelected',
197
+ rowData: row.original,
198
+ rowsData: newRowsSelected ?? []
199
+ });
200
+ } else {
201
+ // chưa selected
202
+
203
+ const checkedRows = [...prevSelected, row];
204
+ setIsSelectionChange({
205
+ isChange: true,
206
+ type: 'rowSelected',
207
+ rowData: row.original,
208
+ rowsData: selectionSettings?.type === 'single' ? [row] : checkedRows
209
+ });
210
+ }
211
+ return;
212
+ }
213
+ if (row.subRows && row.subRows.length > 0) {
214
+ // click vào row cha
215
+
216
+ const allChild = getAllChildren(row);
217
+ toggleRowAndChildren(row, !row.getIsSelected());
218
+ if (row.getIsSelected()) {
219
+ // đã chọn
220
+
221
+ // const aaa = isSelectionChange?.rowsData.filter((it) => it.id !== row.id)
222
+
223
+ const newRowsSelected = excludeItems(prevSelected, [...allChild, row]);
224
+ setIsSelectionChange({
225
+ isChange: true,
226
+ type: 'rowSelected',
227
+ rowData: row.original,
228
+ rowsData: newRowsSelected ?? []
229
+ });
230
+ } else {
231
+ // chưa selected
232
+
233
+ let checkedRows = [];
234
+ if (row.subRows && row.subRows.length > 0) {
235
+ checkedRows = [...prevSelected, row, ...allChild];
236
+ } else {
237
+ checkedRows = [...prevSelected, row];
238
+ }
239
+ setIsSelectionChange({
240
+ isChange: true,
241
+ type: 'rowSelected',
242
+ rowData: row.original,
243
+ rowsData: checkedRows
244
+ });
245
+ }
246
+ } else {
247
+ // click vào row không có cha
248
+
249
+ row.getToggleSelectedHandler()(e);
250
+ if (row.getIsSelected()) {
251
+ // đã chọn
252
+
253
+ const rowParent = row.getParentRow();
254
+ // const rowParent1 = row.getParentRows()
255
+
256
+ let newCheckedRows = [];
257
+ if (rowParent) {}
258
+ if (rowParent && countUnselectedChildren(row) === 1) {
259
+ newCheckedRows = prevSelected.filter(it => it.id !== row.id && it.id !== rowParent.id);
260
+ } else {
261
+ // xóa row ra list selected
262
+ // const newRowsSelected = prevSelected.filter((it) => it.id !== row.id)
263
+ newCheckedRows = prevSelected.filter(it => it.id !== row.id);
264
+ }
265
+ setIsSelectionChange({
266
+ isChange: true,
267
+ type: 'rowSelected',
268
+ rowData: row.original,
269
+ rowsData: newCheckedRows ?? []
270
+ });
271
+ } else {
272
+ // chưa selected
273
+
274
+ let checkedRows = [];
275
+ const rowParent = row.getParentRow();
276
+
277
+ // nếu có cha và cha chưa được chọn và tất cả con đã chọn => thêm row cha vào
278
+ if (rowParent && !rowParent.getIsSelected() && countUnselectedChildren(row) === 1) {
279
+ rowParent.toggleSelected(!rowParent.getIsSelected());
280
+ checkedRows = [...prevSelected, row, rowParent];
281
+ } else {
282
+ // chỉ thêm vào row hiện tại
283
+
284
+ const isInclude = prevSelected.findIndex(it => it.id === cell.row.id);
285
+ if (isInclude > -1) {
286
+ // cập nhật data row hiện tại
287
+
288
+ prevSelected[isInclude] = row;
289
+ checkedRows = [...prevSelected];
290
+ } else {
291
+ checkedRows = [...prevSelected, row];
292
+ }
293
+ }
294
+ setIsSelectionChange({
295
+ isChange: true,
296
+ type: 'rowSelected',
297
+ rowData: row.original,
298
+ rowsData: checkedRows
299
+ });
300
+ }
301
+ }
302
+ };
@@ -0,0 +1,7 @@
1
+ import type { Table } from '@tanstack/react-table';
2
+ import type { FilterOperator } from '../../table-component/type';
3
+ export declare function useFilterOperator(table: Table<any>): {
4
+ setFilterOperator: (columnId: string, operator: FilterOperator) => void;
5
+ getFilterOperator: (columnId: string) => FilterOperator;
6
+ };
7
+ export declare function customStringFilterFn(row: any, columnId: any, filterValue: any): boolean;