es-grid-template 1.7.36 → 1.7.38
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.
- package/LICENSE +21 -21
- package/README.md +1 -1
- package/es/grid-component/ContextMenu.d.ts +2 -3
- package/es/grid-component/ContextMenu.js +2 -2
- package/es/grid-component/InternalTable.d.ts +1 -1
- package/es/grid-component/InternalTable.js +31 -39
- package/es/grid-component/hooks/constant.js +6 -6
- package/es/grid-component/hooks/content/TooltipContent.d.ts +2 -1
- package/es/grid-component/hooks/useColumns.d.ts +3 -1
- package/es/grid-component/hooks/utils.d.ts +1 -1
- package/es/grid-component/styles.scss +1437 -1437
- package/es/table-component/ContextMenu.d.ts +2 -3
- package/es/table-component/ContextMenu.js +2 -2
- package/es/table-component/InternalTable.d.ts +6 -6
- package/es/table-component/InternalTable.js +32 -29
- package/es/table-component/TableContainer.d.ts +5 -5
- package/es/table-component/TableContainer.js +31 -32
- package/es/table-component/TableContainerEdit.d.ts +1 -1
- package/es/table-component/TableContainerEdit.js +248 -217
- package/es/table-component/body/EditableCell.js +154 -157
- package/es/table-component/body/TableBody.d.ts +1 -1
- package/es/table-component/body/TableBody.js +5 -5
- package/es/table-component/body/TableBodyCell.js +37 -18
- package/es/table-component/body/TableBodyCellEdit.d.ts +4 -4
- package/es/table-component/body/TableBodyCellEdit.js +61 -53
- package/es/table-component/body/TableBodyRow.js +0 -1
- package/es/table-component/footer/TableFooterCell.d.ts +3 -3
- package/es/table-component/footer/TableFooterCell.js +8 -6
- package/es/table-component/header/TableHead.d.ts +5 -5
- package/es/table-component/header/TableHead.js +2 -2
- package/es/table-component/hook/constant.js +6 -6
- package/es/table-component/hook/useFilterOperator.d.ts +1 -1
- package/es/table-component/hook/utils.d.ts +2 -2
- package/es/table-component/hook/utils.js +202 -154
- package/es/table-component/style.scss +1197 -1197
- package/es/table-component/table/Grid.js +1 -1
- package/es/table-component/table/TableWrapper.d.ts +4 -4
- package/es/table-component/table/TableWrapper.js +23 -20
- package/es/table-component/type.d.ts +40 -40
- package/es/table-component/useContext.d.ts +4 -3
- package/es/table-component/useContext.js +4 -4
- package/lib/grid-component/ContextMenu.d.ts +2 -3
- package/lib/grid-component/InternalTable.d.ts +1 -1
- package/lib/grid-component/InternalTable.js +25 -33
- package/lib/grid-component/hooks/constant.js +6 -6
- package/lib/grid-component/hooks/content/TooltipContent.d.ts +2 -1
- package/lib/grid-component/hooks/useColumns.d.ts +3 -1
- package/lib/grid-component/hooks/utils.d.ts +1 -1
- package/lib/grid-component/styles.scss +1437 -1437
- package/lib/table-component/ContextMenu.d.ts +2 -3
- package/lib/table-component/InternalTable.d.ts +6 -6
- package/lib/table-component/InternalTable.js +23 -22
- package/lib/table-component/TableContainer.d.ts +5 -5
- package/lib/table-component/TableContainer.js +24 -26
- package/lib/table-component/TableContainerEdit.d.ts +1 -1
- package/lib/table-component/TableContainerEdit.js +247 -216
- package/lib/table-component/body/EditableCell.js +153 -156
- package/lib/table-component/body/TableBody.d.ts +1 -1
- package/lib/table-component/body/TableBody.js +5 -5
- package/lib/table-component/body/TableBodyCell.js +36 -17
- package/lib/table-component/body/TableBodyCellEdit.d.ts +4 -4
- package/lib/table-component/body/TableBodyCellEdit.js +58 -50
- package/lib/table-component/body/TableBodyRow.js +0 -1
- package/lib/table-component/footer/TableFooterCell.d.ts +3 -3
- package/lib/table-component/footer/TableFooterCell.js +7 -5
- package/lib/table-component/header/TableHead.d.ts +5 -5
- package/lib/table-component/header/TableHead.js +1 -1
- package/lib/table-component/hook/constant.js +6 -6
- package/lib/table-component/hook/useFilterOperator.d.ts +1 -1
- package/lib/table-component/hook/utils.d.ts +2 -2
- package/lib/table-component/hook/utils.js +201 -153
- package/lib/table-component/style.scss +1197 -1197
- package/lib/table-component/table/Grid.js +1 -1
- package/lib/table-component/table/TableWrapper.d.ts +4 -4
- package/lib/table-component/table/TableWrapper.js +23 -20
- package/lib/table-component/type.d.ts +40 -40
- package/lib/table-component/useContext.d.ts +4 -3
- package/lib/table-component/useContext.js +3 -3
- package/package.json +2 -2
- package/CHANGELOG.md +0 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SELECTION_COLUMN } from "rc-master-ui/es/table/hooks/useSelection";
|
|
2
|
-
import { v4 as uuidv4 } from
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
3
|
import { presetPalettes } from "@ant-design/colors";
|
|
4
4
|
|
|
5
5
|
// import type { AnyObject } from './type';
|
|
@@ -18,7 +18,7 @@ export const newGuid = () => {
|
|
|
18
18
|
export const convertDayjsToDate = (dateString, format) => {
|
|
19
19
|
const dayjsDate = dayjs(dateString, format); // Parse using the provided format
|
|
20
20
|
if (!dayjsDate.isValid()) {
|
|
21
|
-
throw new Error(
|
|
21
|
+
throw new Error("Invalid date or format");
|
|
22
22
|
}
|
|
23
23
|
// return moment(dayjsDate.toDate()).format() // Convert to JavaScript Date
|
|
24
24
|
return dayjsDate.toDate(); // Convert to JavaScript Date
|
|
@@ -83,7 +83,7 @@ export const extendsObject = (...list) => {
|
|
|
83
83
|
return result;
|
|
84
84
|
};
|
|
85
85
|
export const isEmpty = d => {
|
|
86
|
-
return d === null || d === undefined || d ===
|
|
86
|
+
return d === null || d === undefined || d === "";
|
|
87
87
|
};
|
|
88
88
|
export const getFormat = (colFormat, format) => {
|
|
89
89
|
return {
|
|
@@ -118,74 +118,82 @@ export function convertFormat(formatStr) {
|
|
|
118
118
|
// return char; // separator
|
|
119
119
|
// }).join('');
|
|
120
120
|
|
|
121
|
-
return formatStr.split(
|
|
122
|
-
if (char ===
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (char ===
|
|
121
|
+
return formatStr.split("").map(char => {
|
|
122
|
+
if (char === "D" || char === "d") {
|
|
123
|
+
return "d";
|
|
124
|
+
}
|
|
125
|
+
if (char === "Y" || char === "y") {
|
|
126
|
+
return "y";
|
|
127
|
+
}
|
|
128
|
+
if ("Hhmsa".includes(char)) {
|
|
129
|
+
return char;
|
|
130
|
+
} // giờ, phút, giây, am/pm
|
|
131
|
+
if (char === "M" || char === "m") {
|
|
132
|
+
return char;
|
|
133
|
+
} // tháng: giữ nguyên
|
|
126
134
|
return char; // dấu phân cách
|
|
127
|
-
}).join(
|
|
135
|
+
}).join("");
|
|
128
136
|
}
|
|
129
137
|
export const getDatepickerFormat = (type, format) => {
|
|
130
|
-
const typeFormat = type ? type.toLowerCase() :
|
|
138
|
+
const typeFormat = type ? type.toLowerCase() : "";
|
|
131
139
|
switch (typeFormat) {
|
|
132
140
|
case "date":
|
|
133
141
|
case "daterange":
|
|
134
|
-
return format?.dateFormat ??
|
|
142
|
+
return format?.dateFormat ?? "DD/MM/YYYY";
|
|
135
143
|
case "datetime":
|
|
136
|
-
return format?.datetimeFormat ??
|
|
144
|
+
return format?.datetimeFormat ?? "DD/MM/YYYY HH:mm";
|
|
137
145
|
case "week":
|
|
138
|
-
return format?.weekFormat ??
|
|
146
|
+
return format?.weekFormat ?? "DD/MM";
|
|
139
147
|
case "month":
|
|
140
|
-
return format?.monthFormat ??
|
|
148
|
+
return format?.monthFormat ?? "MM/YYYY";
|
|
141
149
|
case "quarter":
|
|
142
|
-
return format?.dateFormat ??
|
|
150
|
+
return format?.dateFormat ?? "DD/MM/YYYY";
|
|
143
151
|
case "year":
|
|
144
|
-
return format?.yearFormat ??
|
|
152
|
+
return format?.yearFormat ?? "YYYY";
|
|
145
153
|
case "time":
|
|
146
|
-
return format?.timeFormat ??
|
|
154
|
+
return format?.timeFormat ?? "HH:mm";
|
|
147
155
|
default:
|
|
148
|
-
return
|
|
156
|
+
return "DD/MM/YYYY";
|
|
149
157
|
}
|
|
150
158
|
};
|
|
151
159
|
export const getDateRangeFormat = (type, format) => {
|
|
152
|
-
const typeFormat = type ? type.toLowerCase() :
|
|
160
|
+
const typeFormat = type ? type.toLowerCase() : "";
|
|
153
161
|
switch (typeFormat) {
|
|
154
162
|
case "date":
|
|
155
163
|
case "daterange":
|
|
156
|
-
return convertFormat(format?.dateFormat ??
|
|
164
|
+
return convertFormat(format?.dateFormat ?? "dd/MM/yyyy");
|
|
157
165
|
case "datetime":
|
|
158
|
-
return format?.datetimeFormat ??
|
|
166
|
+
return format?.datetimeFormat ?? "dd/MM/yyyy HH:mm";
|
|
159
167
|
case "week":
|
|
160
|
-
return format?.weekFormat ??
|
|
168
|
+
return format?.weekFormat ?? "dd/MM";
|
|
161
169
|
case "month":
|
|
162
|
-
return format?.monthFormat ??
|
|
170
|
+
return format?.monthFormat ?? "MM/yyyy";
|
|
163
171
|
case "quarter":
|
|
164
|
-
return format?.dateFormat ??
|
|
172
|
+
return format?.dateFormat ?? "dd/MM/yyyy";
|
|
165
173
|
case "year":
|
|
166
|
-
return format?.yearFormat ??
|
|
174
|
+
return format?.yearFormat ?? "yyyy";
|
|
167
175
|
case "time":
|
|
168
|
-
return format?.timeFormat ??
|
|
176
|
+
return format?.timeFormat ?? "HH:mm";
|
|
169
177
|
default:
|
|
170
|
-
return
|
|
178
|
+
return "dd/MM/yyyy";
|
|
171
179
|
}
|
|
172
180
|
};
|
|
173
181
|
export const getTypeFilter = col => {
|
|
174
182
|
if (col?.typeFilter) {
|
|
175
183
|
return col.typeFilter;
|
|
176
184
|
}
|
|
177
|
-
const type = col?.type ??
|
|
185
|
+
const type = col?.type ?? "Text";
|
|
178
186
|
switch (type) {
|
|
179
187
|
case "number":
|
|
180
|
-
return
|
|
188
|
+
return "Number";
|
|
181
189
|
case "date":
|
|
182
|
-
return
|
|
190
|
+
return "Date";
|
|
183
191
|
case "datetime":
|
|
184
|
-
return
|
|
192
|
+
return "Datetime";
|
|
185
193
|
case "boolean":
|
|
186
|
-
return
|
|
194
|
+
return "Checkbox";
|
|
187
195
|
case "checkbox":
|
|
188
|
-
return
|
|
196
|
+
return "Checkbox";
|
|
189
197
|
|
|
190
198
|
// case "week": return ''
|
|
191
199
|
// case "month": return 'Month'
|
|
@@ -194,7 +202,7 @@ export const getTypeFilter = col => {
|
|
|
194
202
|
// case "time": return col.format?.timeFormat ? col.format?.timeFormat : 'HH:mm'
|
|
195
203
|
case "string":
|
|
196
204
|
default:
|
|
197
|
-
return
|
|
205
|
+
return "Text";
|
|
198
206
|
}
|
|
199
207
|
};
|
|
200
208
|
export const addRowIdArray = inputArray => {
|
|
@@ -215,7 +223,7 @@ export const addRowIdArray = inputArray => {
|
|
|
215
223
|
export function groupArrayByColumns(arr, columns) {
|
|
216
224
|
const result = [];
|
|
217
225
|
const checkEmpty = d => {
|
|
218
|
-
return d === null || d === undefined || d ===
|
|
226
|
+
return d === null || d === undefined || d === "";
|
|
219
227
|
};
|
|
220
228
|
if (columns) {
|
|
221
229
|
arr.forEach(item => {
|
|
@@ -276,7 +284,7 @@ export const checkThousandSeparator = (thousandSeparator, decimalSeparator) => {
|
|
|
276
284
|
if (thousandSeparator) {
|
|
277
285
|
if (decimalSeparator) {
|
|
278
286
|
if (thousandSeparator === decimalSeparator) {
|
|
279
|
-
return
|
|
287
|
+
return ",";
|
|
280
288
|
} else {
|
|
281
289
|
return thousandSeparator;
|
|
282
290
|
}
|
|
@@ -291,7 +299,7 @@ export const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
|
|
|
291
299
|
if (decimalSeparator) {
|
|
292
300
|
if (thousandSeparator) {
|
|
293
301
|
if (thousandSeparator === decimalSeparator) {
|
|
294
|
-
return
|
|
302
|
+
return ".";
|
|
295
303
|
} else {
|
|
296
304
|
return decimalSeparator;
|
|
297
305
|
}
|
|
@@ -299,10 +307,10 @@ export const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
|
|
|
299
307
|
return decimalSeparator;
|
|
300
308
|
}
|
|
301
309
|
} else {
|
|
302
|
-
if (thousandSeparator && thousandSeparator ===
|
|
303
|
-
return
|
|
310
|
+
if (thousandSeparator && thousandSeparator === ".") {
|
|
311
|
+
return ",";
|
|
304
312
|
}
|
|
305
|
-
return
|
|
313
|
+
return ".";
|
|
306
314
|
}
|
|
307
315
|
};
|
|
308
316
|
export const getFixedFields = (columns, type) => {
|
|
@@ -321,7 +329,9 @@ export const getFixedFields = (columns, type) => {
|
|
|
321
329
|
return result;
|
|
322
330
|
};
|
|
323
331
|
export function areStringArraysEqual(a, b) {
|
|
324
|
-
if (a.length !== b.length)
|
|
332
|
+
if (a.length !== b.length) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
325
335
|
const sortedA = [...a].sort();
|
|
326
336
|
const sortedB = [...b].sort();
|
|
327
337
|
return sortedA.every((val, index) => val === sortedB[index]);
|
|
@@ -332,36 +342,36 @@ export const getDefaultOperator = col => {
|
|
|
332
342
|
}
|
|
333
343
|
if (col.typeFilter) {
|
|
334
344
|
switch (col.typeFilter) {
|
|
335
|
-
case
|
|
336
|
-
case
|
|
337
|
-
case
|
|
338
|
-
case
|
|
339
|
-
case
|
|
340
|
-
case
|
|
341
|
-
case
|
|
342
|
-
case
|
|
343
|
-
case
|
|
344
|
-
case
|
|
345
|
-
case
|
|
346
|
-
case
|
|
347
|
-
case
|
|
348
|
-
return
|
|
349
|
-
case
|
|
345
|
+
case "Number":
|
|
346
|
+
case "Date":
|
|
347
|
+
case "Datetime":
|
|
348
|
+
case "Time":
|
|
349
|
+
case "Month":
|
|
350
|
+
case "Quarter":
|
|
351
|
+
case "Year":
|
|
352
|
+
case "Week":
|
|
353
|
+
case "Dropdown":
|
|
354
|
+
case "Checkbox":
|
|
355
|
+
case "CheckboxDropdown":
|
|
356
|
+
case "CheckboxTree":
|
|
357
|
+
case "DropTree":
|
|
358
|
+
return "equal";
|
|
359
|
+
case "Text":
|
|
350
360
|
default:
|
|
351
|
-
return
|
|
361
|
+
return "contains";
|
|
352
362
|
}
|
|
353
363
|
}
|
|
354
364
|
switch (col.type) {
|
|
355
|
-
case
|
|
356
|
-
case
|
|
357
|
-
case
|
|
358
|
-
case
|
|
359
|
-
case
|
|
360
|
-
case
|
|
361
|
-
return
|
|
362
|
-
case
|
|
365
|
+
case "number":
|
|
366
|
+
case "date":
|
|
367
|
+
case "datetime":
|
|
368
|
+
case "week":
|
|
369
|
+
case "year":
|
|
370
|
+
case "quarter":
|
|
371
|
+
return "equal";
|
|
372
|
+
case "string":
|
|
363
373
|
default:
|
|
364
|
-
return
|
|
374
|
+
return "contains";
|
|
365
375
|
}
|
|
366
376
|
};
|
|
367
377
|
export function isEqualSet(setA, setB) {
|
|
@@ -450,24 +460,24 @@ export function getCellsByPosition(cellSet, position = "bottom") {
|
|
|
450
460
|
}
|
|
451
461
|
export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
|
|
452
462
|
const selectors = Array.from(selectedCells).map(pos => {
|
|
453
|
-
const [row1, col1] = pos.split(
|
|
463
|
+
const [row1, col1] = pos.split("-");
|
|
454
464
|
return `[data-row-index="${row1}"][data-col-index="${col1}"]`;
|
|
455
465
|
});
|
|
456
466
|
const table = document.querySelector(`#${id}`);
|
|
457
467
|
|
|
458
468
|
//// xóa class các ô đã chọn trước đó
|
|
459
|
-
const cellsSelected = table ? table?.querySelectorAll(
|
|
469
|
+
const cellsSelected = table ? table?.querySelectorAll(".ui-rc-table-cell.selected-bg") : null;
|
|
460
470
|
if (cellsSelected) {
|
|
461
471
|
cellsSelected.forEach(cell => {
|
|
462
|
-
cell.classList.remove(
|
|
472
|
+
cell.classList.remove("selected-bg");
|
|
463
473
|
});
|
|
464
474
|
}
|
|
465
475
|
|
|
466
476
|
/// thêm class
|
|
467
|
-
const cells = table && selectors.length > 0 ? table?.querySelectorAll(selectors.join(
|
|
477
|
+
const cells = table && selectors.length > 0 ? table?.querySelectorAll(selectors.join(",")) : null;
|
|
468
478
|
if (cells) {
|
|
469
479
|
cells.forEach(cell => {
|
|
470
|
-
cell.classList.add(
|
|
480
|
+
cell.classList.add("selected-bg");
|
|
471
481
|
});
|
|
472
482
|
}
|
|
473
483
|
const rowsArray = [...new Set([...selectedCells].map(item => item.split("-")[0]))];
|
|
@@ -475,7 +485,7 @@ export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
|
|
|
475
485
|
const cellsIndex = table && rowsSelectors.length > 0 ? table?.querySelectorAll(rowsSelectors) : null;
|
|
476
486
|
if (cellsIndex && isFocusCellIndex !== false) {
|
|
477
487
|
cellsIndex.forEach(cell => {
|
|
478
|
-
cell.classList.add(
|
|
488
|
+
cell.classList.add("focus");
|
|
479
489
|
});
|
|
480
490
|
}
|
|
481
491
|
|
|
@@ -501,16 +511,16 @@ export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
|
|
|
501
511
|
};
|
|
502
512
|
export const onRemoveBgSelectedCell = (selectedCells, id, rowsSelected) => {
|
|
503
513
|
const table = document.querySelector(`#${id}`);
|
|
504
|
-
const cells = table ? table?.querySelectorAll(
|
|
514
|
+
const cells = table ? table?.querySelectorAll(".ui-rc-table-cell.selected-bg") : null;
|
|
505
515
|
if (cells) {
|
|
506
516
|
cells.forEach(cell => {
|
|
507
|
-
cell.classList.remove(
|
|
517
|
+
cell.classList.remove("selected-bg");
|
|
508
518
|
});
|
|
509
519
|
}
|
|
510
|
-
const cellsIndex = table ? table?.querySelectorAll(
|
|
520
|
+
const cellsIndex = table ? table?.querySelectorAll(".ui-rc-table-cell.focus") : null;
|
|
511
521
|
if (cellsIndex) {
|
|
512
522
|
cellsIndex.forEach(cell => {
|
|
513
|
-
cell.classList.remove(
|
|
523
|
+
cell.classList.remove("focus");
|
|
514
524
|
});
|
|
515
525
|
}
|
|
516
526
|
|
|
@@ -522,7 +532,7 @@ export const onRemoveBgSelectedCell = (selectedCells, id, rowsSelected) => {
|
|
|
522
532
|
const cellsSelectedIndex = table && rowsSelectedSelectors.length > 0 ? table?.querySelectorAll(rowsSelectedSelectors) : null;
|
|
523
533
|
if (cellsSelectedIndex) {
|
|
524
534
|
cellsSelectedIndex.forEach(cell => {
|
|
525
|
-
cell.classList.remove(
|
|
535
|
+
cell.classList.remove("selected");
|
|
526
536
|
});
|
|
527
537
|
}
|
|
528
538
|
}
|
|
@@ -648,8 +658,12 @@ export const findItemByKey = (array, key, value) => {
|
|
|
648
658
|
return null;
|
|
649
659
|
};
|
|
650
660
|
export const isFormattedNumber = str => {
|
|
651
|
-
if (!str)
|
|
652
|
-
|
|
661
|
+
if (!str) {
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
if (typeof str !== "string") {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
653
667
|
const regexUS = /^\d{1,3}(,\d{3})*(\.\d+)?$/; // 100,000.111
|
|
654
668
|
const regexEU = /^\d{1,3}(\.\d{3})*(,\d+)?$/; // 100.000,111
|
|
655
669
|
|
|
@@ -658,47 +672,49 @@ export const isFormattedNumber = str => {
|
|
|
658
672
|
return regexUS.test(str) || regexEU.test(str) || regexDecimalOnly.test(str);
|
|
659
673
|
};
|
|
660
674
|
export const detectSeparators = str => {
|
|
661
|
-
if (typeof str !==
|
|
662
|
-
|
|
663
|
-
|
|
675
|
+
if (typeof str !== "string") {
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
const hasComma = str.includes(",");
|
|
679
|
+
const hasDot = str.includes(".");
|
|
664
680
|
|
|
665
681
|
// Trường hợp có cả dấu , và .
|
|
666
682
|
if (hasComma && hasDot) {
|
|
667
|
-
const lastComma = str.lastIndexOf(
|
|
668
|
-
const lastDot = str.lastIndexOf(
|
|
683
|
+
const lastComma = str.lastIndexOf(",");
|
|
684
|
+
const lastDot = str.lastIndexOf(".");
|
|
669
685
|
return lastComma > lastDot ? {
|
|
670
|
-
thousandSeparator:
|
|
671
|
-
decimalSeparator:
|
|
686
|
+
thousandSeparator: ".",
|
|
687
|
+
decimalSeparator: ","
|
|
672
688
|
} : {
|
|
673
|
-
thousandSeparator:
|
|
674
|
-
decimalSeparator:
|
|
689
|
+
thousandSeparator: ",",
|
|
690
|
+
decimalSeparator: "."
|
|
675
691
|
};
|
|
676
692
|
}
|
|
677
693
|
|
|
678
694
|
// Trường hợp chỉ có dấu phẩy
|
|
679
695
|
if (hasComma && !hasDot) {
|
|
680
|
-
const parts = str.split(
|
|
696
|
+
const parts = str.split(",");
|
|
681
697
|
if (parts.length === 2) {
|
|
682
698
|
return parts[1].length === 3 ? {
|
|
683
|
-
thousandSeparator:
|
|
699
|
+
thousandSeparator: ",",
|
|
684
700
|
decimalSeparator: null
|
|
685
701
|
} : {
|
|
686
702
|
thousandSeparator: null,
|
|
687
|
-
decimalSeparator:
|
|
703
|
+
decimalSeparator: ","
|
|
688
704
|
};
|
|
689
705
|
}
|
|
690
706
|
}
|
|
691
707
|
|
|
692
708
|
// Trường hợp chỉ có dấu chấm
|
|
693
709
|
if (hasDot && !hasComma) {
|
|
694
|
-
const parts = str.split(
|
|
710
|
+
const parts = str.split(".");
|
|
695
711
|
if (parts.length === 2) {
|
|
696
712
|
return parts[1].length === 3 ? {
|
|
697
|
-
thousandSeparator:
|
|
713
|
+
thousandSeparator: ".",
|
|
698
714
|
decimalSeparator: null
|
|
699
715
|
} : {
|
|
700
716
|
thousandSeparator: null,
|
|
701
|
-
decimalSeparator:
|
|
717
|
+
decimalSeparator: "."
|
|
702
718
|
};
|
|
703
719
|
}
|
|
704
720
|
}
|
|
@@ -723,7 +739,7 @@ export function isDateString(str) {
|
|
|
723
739
|
}
|
|
724
740
|
function parseToDate(str) {
|
|
725
741
|
if (/^\d{2}\/\d{4}$/.test(str)) {
|
|
726
|
-
const [month, year] = str.split(
|
|
742
|
+
const [month, year] = str.split("/");
|
|
727
743
|
return new Date(parseInt(year), parseInt(month) - 1, 1);
|
|
728
744
|
}
|
|
729
745
|
return new Date(str);
|
|
@@ -736,19 +752,19 @@ export function compareDates(date1, date2) {
|
|
|
736
752
|
|
|
737
753
|
// Helper: compare MM/YYYY date string with itemValue
|
|
738
754
|
export function compareDate(itemValue, value) {
|
|
739
|
-
const [month, year] = value.split(
|
|
755
|
+
const [month, year] = value.split("/").map(Number);
|
|
740
756
|
const date = new Date(itemValue);
|
|
741
757
|
return date.getMonth() + 1 === month && date.getFullYear() === year;
|
|
742
758
|
}
|
|
743
759
|
export const removeVietnameseTones = str => {
|
|
744
760
|
if (!str) {
|
|
745
|
-
return
|
|
761
|
+
return "";
|
|
746
762
|
}
|
|
747
|
-
return str.normalize(
|
|
748
|
-
.replace(/[\u0300-\u036f]/g,
|
|
749
|
-
.replace(/đ/g,
|
|
750
|
-
.replace(/Đ/g,
|
|
751
|
-
.replace(/\s+/g,
|
|
763
|
+
return str.normalize("NFD") // Tách các ký tự có dấu thành ký tự cơ bản + dấu
|
|
764
|
+
.replace(/[\u0300-\u036f]/g, "") // Xóa dấu
|
|
765
|
+
.replace(/đ/g, "d") // Thay thế đ
|
|
766
|
+
.replace(/Đ/g, "D").replace(/[^a-zA-Z0-9\s]/g, "") // Loại bỏ ký tự đặc biệt
|
|
767
|
+
.replace(/\s+/g, " ") // Thay nhiều khoảng trắng thành 1 khoảng trắng
|
|
752
768
|
.trim();
|
|
753
769
|
};
|
|
754
770
|
export const shouldInclude = (item, queries) => {
|
|
@@ -768,8 +784,8 @@ export const shouldInclude = (item, queries) => {
|
|
|
768
784
|
const isDateComparison = isDate(itemValue) || isDateString(value);
|
|
769
785
|
const itemDate = isDateComparison ? new Date(itemValue) : null;
|
|
770
786
|
const queryDate = isDateComparison ? parseToDate(value) : null;
|
|
771
|
-
const itemStr = removeVietnameseTones(itemValue?.toString().toLowerCase?.() ??
|
|
772
|
-
const queryStr = removeVietnameseTones(value?.toString().toLowerCase?.() ??
|
|
787
|
+
const itemStr = removeVietnameseTones(itemValue?.toString().toLowerCase?.() ?? "");
|
|
788
|
+
const queryStr = removeVietnameseTones(value?.toString().toLowerCase?.() ?? "");
|
|
773
789
|
switch (operator.toLowerCase()) {
|
|
774
790
|
case "equal":
|
|
775
791
|
condition = isDateComparison ? compareDates(itemDate, queryDate) : itemValue === value;
|
|
@@ -818,9 +834,15 @@ export const shouldInclude = (item, queries) => {
|
|
|
818
834
|
};
|
|
819
835
|
function compareValues(a, b, order) {
|
|
820
836
|
const desc = order === "descend";
|
|
821
|
-
if (a == null && b == null)
|
|
822
|
-
|
|
823
|
-
|
|
837
|
+
if (a == null && b == null) {
|
|
838
|
+
return 0;
|
|
839
|
+
}
|
|
840
|
+
if (a == null) {
|
|
841
|
+
return desc ? 1 : -1;
|
|
842
|
+
}
|
|
843
|
+
if (b == null) {
|
|
844
|
+
return desc ? -1 : 1;
|
|
845
|
+
}
|
|
824
846
|
|
|
825
847
|
// Nếu là số
|
|
826
848
|
if (typeof a === "number" && typeof b === "number") {
|
|
@@ -844,7 +866,9 @@ export function sortData(data, sorter) {
|
|
|
844
866
|
order
|
|
845
867
|
} of sorter) {
|
|
846
868
|
const result = compareValues(a[field], b[field], order);
|
|
847
|
-
if (result !== 0)
|
|
869
|
+
if (result !== 0) {
|
|
870
|
+
return result;
|
|
871
|
+
}
|
|
848
872
|
}
|
|
849
873
|
return 0;
|
|
850
874
|
});
|
|
@@ -883,7 +907,7 @@ export const getAllRowKey = data => {
|
|
|
883
907
|
return a.length ? a.map(it => it.rowId) : undefined;
|
|
884
908
|
};
|
|
885
909
|
export const isEditable = (column, rowData) => {
|
|
886
|
-
if (column && typeof column.editEnable ===
|
|
910
|
+
if (column && typeof column.editEnable === "function") {
|
|
887
911
|
return column.editEnable(rowData);
|
|
888
912
|
}
|
|
889
913
|
return column?.editEnable;
|
|
@@ -892,7 +916,7 @@ export const checkFieldKey = key => {
|
|
|
892
916
|
if (key) {
|
|
893
917
|
return key;
|
|
894
918
|
} else {
|
|
895
|
-
return
|
|
919
|
+
return "value";
|
|
896
920
|
}
|
|
897
921
|
};
|
|
898
922
|
export const convertArrayWithIndent = (inputArray, parentIndent = 0) => {
|
|
@@ -945,16 +969,16 @@ export const isObjEmpty = obj => {
|
|
|
945
969
|
}
|
|
946
970
|
};
|
|
947
971
|
export const isDisable = (column, rowData) => {
|
|
948
|
-
if (column && typeof column?.disable ===
|
|
972
|
+
if (column && typeof column?.disable === "function") {
|
|
949
973
|
return column.disable(rowData);
|
|
950
974
|
}
|
|
951
975
|
return !!column?.disable;
|
|
952
976
|
};
|
|
953
977
|
export const customWeekStartEndFormat = (value, weekFormat) => {
|
|
954
|
-
return `${dayjs(value).startOf(
|
|
978
|
+
return `${dayjs(value).startOf("week").format(weekFormat)} ~ ${dayjs(value).endOf("week").format(weekFormat)}`;
|
|
955
979
|
};
|
|
956
980
|
export const parseBooleanToValue = (value, type) => {
|
|
957
|
-
return type ===
|
|
981
|
+
return type === "boolean" ? value : Number(value);
|
|
958
982
|
};
|
|
959
983
|
export const isNameColor = strColor => {
|
|
960
984
|
const s = new Option().style;
|
|
@@ -978,13 +1002,13 @@ export const genPresets = (presets = presetPalettes) => {
|
|
|
978
1002
|
}));
|
|
979
1003
|
};
|
|
980
1004
|
export const getEditType = (column, rowData) => {
|
|
981
|
-
if (column && typeof column.editType ===
|
|
1005
|
+
if (column && typeof column.editType === "function") {
|
|
982
1006
|
return column.editType(rowData);
|
|
983
1007
|
}
|
|
984
|
-
return column?.editType ??
|
|
1008
|
+
return column?.editType ?? "text";
|
|
985
1009
|
};
|
|
986
1010
|
export const getDefaultValue = defaultValue => {
|
|
987
|
-
if (defaultValue && typeof defaultValue ===
|
|
1011
|
+
if (defaultValue && typeof defaultValue === "function") {
|
|
988
1012
|
return defaultValue();
|
|
989
1013
|
}
|
|
990
1014
|
return defaultValue;
|
|
@@ -993,23 +1017,25 @@ export const flattenData = (childrenColumnName, data) => {
|
|
|
993
1017
|
let list = [];
|
|
994
1018
|
(data || []).forEach(record => {
|
|
995
1019
|
list.push(record);
|
|
996
|
-
if (record && typeof record ===
|
|
1020
|
+
if (record && typeof record === "object" && childrenColumnName in record) {
|
|
997
1021
|
list = [...list, ...flattenData(childrenColumnName, record[childrenColumnName])];
|
|
998
1022
|
}
|
|
999
1023
|
});
|
|
1000
1024
|
return list;
|
|
1001
1025
|
};
|
|
1002
1026
|
export const getSelectedCellMatrix = (table, startCell, endCell) => {
|
|
1003
|
-
if (!startCell || !endCell)
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1027
|
+
if (!startCell || !endCell) {
|
|
1028
|
+
return {
|
|
1029
|
+
rowIds: [],
|
|
1030
|
+
colIds: [],
|
|
1031
|
+
startRowIndex: undefined,
|
|
1032
|
+
endRowIndex: undefined,
|
|
1033
|
+
startColIndex: undefined,
|
|
1034
|
+
endColIndex: undefined,
|
|
1035
|
+
colRange: [],
|
|
1036
|
+
rowRange: []
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1013
1039
|
|
|
1014
1040
|
// const rowIds = table.getRowModel().rows.map(r => r.id);
|
|
1015
1041
|
const rowIds = table.getRowModel().flatRows.map(r => r.id);
|
|
@@ -1045,14 +1071,14 @@ export function addRowsDownWithCtrl(arr, n) {
|
|
|
1045
1071
|
const isValidDate = item => {
|
|
1046
1072
|
// return !isNaN(Date.parse(d))
|
|
1047
1073
|
|
|
1048
|
-
if (typeof item ===
|
|
1074
|
+
if (typeof item === "number") {
|
|
1049
1075
|
// return 'number'
|
|
1050
1076
|
return false;
|
|
1051
1077
|
}
|
|
1052
|
-
if (typeof item ===
|
|
1078
|
+
if (typeof item === "string") {
|
|
1053
1079
|
// Kiểm tra nếu là chuỗi ISO date hợp lệ
|
|
1054
1080
|
const date = new Date(item);
|
|
1055
|
-
if (!isNaN(date.getTime()) && item.includes(
|
|
1081
|
+
if (!isNaN(date.getTime()) && item.includes("T")) {
|
|
1056
1082
|
// return 'date'
|
|
1057
1083
|
return true;
|
|
1058
1084
|
}
|
|
@@ -1330,14 +1356,14 @@ export function addRowsUpWithCtrl(array, n) {
|
|
|
1330
1356
|
const isValidDate = item => {
|
|
1331
1357
|
// return !isNaN(Date.parse(d))
|
|
1332
1358
|
|
|
1333
|
-
if (typeof item ===
|
|
1359
|
+
if (typeof item === "number") {
|
|
1334
1360
|
// return 'number'
|
|
1335
1361
|
return false;
|
|
1336
1362
|
}
|
|
1337
|
-
if (typeof item ===
|
|
1363
|
+
if (typeof item === "string") {
|
|
1338
1364
|
// Kiểm tra nếu là chuỗi ISO date hợp lệ
|
|
1339
1365
|
const date = new Date(item);
|
|
1340
|
-
if (!isNaN(date.getTime()) && item.includes(
|
|
1366
|
+
if (!isNaN(date.getTime()) && item.includes("T")) {
|
|
1341
1367
|
// return 'date'
|
|
1342
1368
|
return true;
|
|
1343
1369
|
}
|
|
@@ -1635,7 +1661,7 @@ export const convertFilters = filters => {
|
|
|
1635
1661
|
operator: "lessthanorequal"
|
|
1636
1662
|
});
|
|
1637
1663
|
}
|
|
1638
|
-
} else if (column?.typeFilter ===
|
|
1664
|
+
} else if (column?.typeFilter === "Checkbox") {
|
|
1639
1665
|
filteredKeys.forEach(value => {
|
|
1640
1666
|
result.push({
|
|
1641
1667
|
key,
|
|
@@ -1650,7 +1676,7 @@ export const convertFilters = filters => {
|
|
|
1650
1676
|
key,
|
|
1651
1677
|
field: column?.field,
|
|
1652
1678
|
value: filteredKeys[0],
|
|
1653
|
-
predicate:
|
|
1679
|
+
predicate: "and",
|
|
1654
1680
|
operator
|
|
1655
1681
|
});
|
|
1656
1682
|
}
|
|
@@ -1661,7 +1687,7 @@ export function getInvisibleColumns(columns) {
|
|
|
1661
1687
|
const result = {};
|
|
1662
1688
|
for (const col of columns) {
|
|
1663
1689
|
if (col.visible === false || col.hidden) {
|
|
1664
|
-
result[col.field ??
|
|
1690
|
+
result[col.field ?? ""] = false;
|
|
1665
1691
|
}
|
|
1666
1692
|
}
|
|
1667
1693
|
return result;
|
|
@@ -1746,10 +1772,12 @@ export const getVisibleColumnKeys1 = columns => {
|
|
|
1746
1772
|
};
|
|
1747
1773
|
export function isObjEqual(obj1, obj2) {
|
|
1748
1774
|
// Trường hợp tham chiếu bằng nhau
|
|
1749
|
-
if (obj1 === obj2)
|
|
1775
|
+
if (obj1 === obj2) {
|
|
1776
|
+
return true;
|
|
1777
|
+
}
|
|
1750
1778
|
|
|
1751
1779
|
// Nếu 1 trong 2 không phải object hoặc null thì so sánh trực tiếp
|
|
1752
|
-
if (typeof obj1 !==
|
|
1780
|
+
if (typeof obj1 !== "object" || obj1 === null || typeof obj2 !== "object" || obj2 === null) {
|
|
1753
1781
|
return obj1 === obj2;
|
|
1754
1782
|
}
|
|
1755
1783
|
|
|
@@ -1758,12 +1786,18 @@ export function isObjEqual(obj1, obj2) {
|
|
|
1758
1786
|
const keys2 = Object.keys(obj2);
|
|
1759
1787
|
|
|
1760
1788
|
// Nếu số key khác nhau thì khác nhau
|
|
1761
|
-
if (keys1.length !== keys2.length)
|
|
1789
|
+
if (keys1.length !== keys2.length) {
|
|
1790
|
+
return false;
|
|
1791
|
+
}
|
|
1762
1792
|
|
|
1763
1793
|
// Duyệt và so sánh từng key
|
|
1764
1794
|
for (const key of keys1) {
|
|
1765
|
-
if (!keys2.includes(key))
|
|
1766
|
-
|
|
1795
|
+
if (!keys2.includes(key)) {
|
|
1796
|
+
return false;
|
|
1797
|
+
}
|
|
1798
|
+
if (!isObjEqual(obj1[key], obj2[key])) {
|
|
1799
|
+
return false;
|
|
1800
|
+
}
|
|
1767
1801
|
}
|
|
1768
1802
|
return true;
|
|
1769
1803
|
}
|
|
@@ -1772,13 +1806,13 @@ export function isObjEqual(obj1, obj2) {
|
|
|
1772
1806
|
export const sortByType = arr => {
|
|
1773
1807
|
if (arr) {
|
|
1774
1808
|
return arr.sort((a, b) => {
|
|
1775
|
-
if ((a.fixed ?? a.fixedType) ===
|
|
1809
|
+
if ((a.fixed ?? a.fixedType) === "left" && (b.fixed ?? b.fixedType) !== "left") {
|
|
1776
1810
|
return -1;
|
|
1777
|
-
} else if ((a.fixed ?? a.fixedType) !==
|
|
1811
|
+
} else if ((a.fixed ?? a.fixedType) !== "left" && (b.fixed ?? b.fixedType) === "left") {
|
|
1778
1812
|
return 1;
|
|
1779
|
-
} else if ((a.fixed ?? a.fixedType) ===
|
|
1813
|
+
} else if ((a.fixed ?? a.fixedType) === "right" && (b.fixed ?? b.fixedType) !== "right") {
|
|
1780
1814
|
return 1;
|
|
1781
|
-
} else if ((a.fixed ?? a.fixedType) !==
|
|
1815
|
+
} else if ((a.fixed ?? a.fixedType) !== "right" && (b.fixed ?? b.fixedType) === "right") {
|
|
1782
1816
|
return -1;
|
|
1783
1817
|
}
|
|
1784
1818
|
return 0;
|
|
@@ -1811,8 +1845,10 @@ export function convertColumnsToTreeData(columns, groupColumns) {
|
|
|
1811
1845
|
// Điều kiện filter:
|
|
1812
1846
|
// - Nếu meta.showInColumnChoose = false => loại bỏ
|
|
1813
1847
|
// - Nếu không nằm trong groupColumns và không phải column group => loại bỏ
|
|
1814
|
-
if (meta.showInColumnChoose === false)
|
|
1815
|
-
|
|
1848
|
+
if (meta.showInColumnChoose === false) {
|
|
1849
|
+
return false;
|
|
1850
|
+
}
|
|
1851
|
+
if (inGroup && !("columns" in col && Array.isArray(col.columns))) {
|
|
1816
1852
|
return false;
|
|
1817
1853
|
}
|
|
1818
1854
|
return true;
|
|
@@ -1824,7 +1860,7 @@ export function convertColumnsToTreeData(columns, groupColumns) {
|
|
|
1824
1860
|
|
|
1825
1861
|
// title: String(col.header ?? col.id ?? ''),
|
|
1826
1862
|
};
|
|
1827
|
-
if (
|
|
1863
|
+
if ("columns" in col && Array.isArray(col.columns)) {
|
|
1828
1864
|
const children = convertColumnsToTreeData(col.columns, groupColumns);
|
|
1829
1865
|
if (children.length > 0) {
|
|
1830
1866
|
node.children = children;
|
|
@@ -1877,20 +1913,32 @@ export const getDiffent2Array = (a, b) => {
|
|
|
1877
1913
|
return [...a.filter(x => !b.includes(x)), ...b.filter(x => !a.includes(x))];
|
|
1878
1914
|
};
|
|
1879
1915
|
export function isTree(arr) {
|
|
1880
|
-
if (!Array.isArray(arr))
|
|
1916
|
+
if (!Array.isArray(arr)) {
|
|
1917
|
+
return false;
|
|
1918
|
+
}
|
|
1881
1919
|
function checkNode(node) {
|
|
1882
|
-
if (typeof node !== "object" || node === null)
|
|
1920
|
+
if (typeof node !== "object" || node === null) {
|
|
1921
|
+
return false;
|
|
1922
|
+
}
|
|
1883
1923
|
if ("children" in node) {
|
|
1884
|
-
if (!Array.isArray(node.children))
|
|
1885
|
-
|
|
1924
|
+
if (!Array.isArray(node.children)) {
|
|
1925
|
+
return false;
|
|
1926
|
+
}
|
|
1927
|
+
if (node.children.length === 0) {
|
|
1928
|
+
return false;
|
|
1929
|
+
}
|
|
1886
1930
|
for (const child of node.children) {
|
|
1887
|
-
if (!checkNode(child))
|
|
1931
|
+
if (!checkNode(child)) {
|
|
1932
|
+
return false;
|
|
1933
|
+
}
|
|
1888
1934
|
}
|
|
1889
1935
|
}
|
|
1890
1936
|
return true;
|
|
1891
1937
|
}
|
|
1892
1938
|
for (const item of arr) {
|
|
1893
|
-
if (!checkNode(item))
|
|
1939
|
+
if (!checkNode(item)) {
|
|
1940
|
+
return false;
|
|
1941
|
+
}
|
|
1894
1942
|
}
|
|
1895
1943
|
return true;
|
|
1896
1944
|
}
|