es-grid-template 1.2.1 → 1.2.3
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/assets/index.css +36 -17
- package/assets/index.scss +1064 -1006
- package/es/grid-component/GridStyle.js +1 -1
- package/es/grid-component/InternalTable.d.ts +1 -0
- package/es/grid-component/InternalTable.js +2 -1
- package/es/grid-component/TableGrid.js +6 -15
- package/es/grid-component/hooks/content/HeaderContent.js +6 -7
- package/es/grid-component/hooks/useColumns.js +10 -2
- package/es/grid-component/hooks/utils.d.ts +2 -22
- package/es/grid-component/hooks/utils.js +2 -410
- package/es/grid-component/styles.scss +63 -5
- package/es/grid-component/table/Grid.js +17 -1
- package/es/grid-component/table/GridEdit.js +384 -159
- package/es/grid-component/type.d.ts +2 -1
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/InternalTable.d.ts +1 -0
- package/lib/grid-component/InternalTable.js +2 -1
- package/lib/grid-component/TableGrid.js +7 -15
- package/lib/grid-component/hooks/content/HeaderContent.js +6 -7
- package/lib/grid-component/hooks/useColumns.js +10 -2
- package/lib/grid-component/hooks/utils.d.ts +2 -22
- package/lib/grid-component/hooks/utils.js +3 -419
- package/lib/grid-component/styles.scss +63 -5
- package/lib/grid-component/table/Grid.js +17 -1
- package/lib/grid-component/table/GridEdit.js +383 -158
- package/lib/grid-component/type.d.ts +2 -1
- package/package.json +2 -2
|
@@ -2,4 +2,4 @@ import styled from "styled-components";
|
|
|
2
2
|
export const GridStyle = styled.div.withConfig({
|
|
3
3
|
displayName: "GridStyle",
|
|
4
4
|
componentId: "es-grid-template__sc-sueu2e-0"
|
|
5
|
-
})([".ui-rc-table-container{min-height:", ";}.ui-rc-toolbar-bottom{position:relative;padding:.25rem 1rem;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;
|
|
5
|
+
})([".ui-rc-table-container{min-height:", ";}.ui-rc-toolbar-bottom{position:relative;padding:.25rem 1rem;background-color:#ffffff;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}.toolbar-button{border-radius:0;.ant-btn{border-radius:0;}}}.ui-rc-pagination{border-bottom:1px solid #e0e0e0;border-top:1px solid #e0e0e0;margin:0;padding:.75rem 1rem;background-color:#ffffff;.ui-rc-pagination-total-text{order:2;margin-left:auto;}&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;visibility:visible;right:0;}&.pagination-template{position:relative;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}}}.react-resizable{position:relative;background-clip:padding-box;}.rc-resizable-handle{position:absolute;right:0px;bottom:0;z-index:1;width:5px;height:100%;cursor:col-resize;&.none{cursor:auto;display:none;}}"], props => props.heightTable ? typeof props.heightTable === 'string' ? props.heightTable : `${props.heightTable}px` : undefined);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { Resizable } from "react-resizable";
|
|
4
|
+
import 'react-resizable/css/styles.css';
|
|
4
5
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
5
6
|
import { addRowIdArray,
|
|
6
7
|
// convertFlatColumn,
|
|
@@ -39,7 +40,7 @@ const ResizableTitle = props => {
|
|
|
39
40
|
width: width,
|
|
40
41
|
height: 0,
|
|
41
42
|
handle: /*#__PURE__*/React.createElement("span", {
|
|
42
|
-
className: "
|
|
43
|
+
className: "rc-resizable-handle",
|
|
43
44
|
onClick: e => {
|
|
44
45
|
e.stopPropagation();
|
|
45
46
|
}
|
|
@@ -14,7 +14,7 @@ isEmpty,
|
|
|
14
14
|
sumDataByField
|
|
15
15
|
// updateArrayByKey
|
|
16
16
|
} from "./hooks";
|
|
17
|
-
import {
|
|
17
|
+
// import {ConfigProvider} from "antd";
|
|
18
18
|
import { flatColumns } from "./hooks/columns";
|
|
19
19
|
import Pagination from "rc-master-ui/es/pagination";
|
|
20
20
|
import ComponentSpinner from "./LoadingSpinner";
|
|
@@ -129,6 +129,7 @@ const TableGrid = props => {
|
|
|
129
129
|
getRowKey,
|
|
130
130
|
groupColumns,
|
|
131
131
|
groupToolbar,
|
|
132
|
+
showEmptyText,
|
|
132
133
|
...rest
|
|
133
134
|
} = props;
|
|
134
135
|
const {
|
|
@@ -291,17 +292,7 @@ const TableGrid = props => {
|
|
|
291
292
|
const handleChange = sorter => {
|
|
292
293
|
onSorter?.(sorter);
|
|
293
294
|
};
|
|
294
|
-
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(
|
|
295
|
-
theme: {
|
|
296
|
-
components: {
|
|
297
|
-
Table: {
|
|
298
|
-
rowHoverBg: '#eb461912',
|
|
299
|
-
rowSelectedBg: '#eb4619',
|
|
300
|
-
rowSelectedHoverBg: '#eb4619'
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}, /*#__PURE__*/React.createElement(ContextMenu, {
|
|
295
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextMenu, {
|
|
305
296
|
open: menuVisible,
|
|
306
297
|
pos: position,
|
|
307
298
|
setOpen: setMenuVisible,
|
|
@@ -314,10 +305,10 @@ const TableGrid = props => {
|
|
|
314
305
|
}, rest, {
|
|
315
306
|
locale: {
|
|
316
307
|
...locale,
|
|
317
|
-
emptyText: /*#__PURE__*/React.createElement(Empty, {
|
|
308
|
+
emptyText: showEmptyText !== false ? /*#__PURE__*/React.createElement(Empty, {
|
|
318
309
|
image: Empty.PRESENTED_IMAGE_SIMPLE,
|
|
319
310
|
description: locale?.emptyText
|
|
320
|
-
})
|
|
311
|
+
}) : /*#__PURE__*/React.createElement(React.Fragment, null)
|
|
321
312
|
},
|
|
322
313
|
loading: {
|
|
323
314
|
spinning: columns && columns.length === 0 || loading === true,
|
|
@@ -452,6 +443,6 @@ const TableGrid = props => {
|
|
|
452
443
|
// @ts-ignore
|
|
453
444
|
,
|
|
454
445
|
showTotal: (total, range) => `${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
|
|
455
|
-
}, pagination)), bottomToolbar?.())
|
|
446
|
+
}, pagination)), bottomToolbar?.());
|
|
456
447
|
};
|
|
457
448
|
export default TableGrid;
|
|
@@ -18,15 +18,14 @@ const HeaderContent = props => {
|
|
|
18
18
|
headerTooltip,
|
|
19
19
|
headerText,
|
|
20
20
|
columnGroupText,
|
|
21
|
-
headerTemplate
|
|
22
|
-
title
|
|
21
|
+
headerTemplate
|
|
23
22
|
} = props.column ?? {};
|
|
24
23
|
const text = React.useMemo(() => {
|
|
25
|
-
return columnGroupText ?? headerText
|
|
26
|
-
}, [columnGroupText, headerText
|
|
24
|
+
return columnGroupText ?? headerText;
|
|
25
|
+
}, [columnGroupText, headerText]);
|
|
27
26
|
const tooltip = React.useMemo(() => {
|
|
28
|
-
return headerTooltip ?? columnGroupText ?? headerText
|
|
29
|
-
}, [columnGroupText, headerText, headerTooltip
|
|
27
|
+
return headerTooltip ?? columnGroupText ?? headerText;
|
|
28
|
+
}, [columnGroupText, headerText, headerTooltip]);
|
|
30
29
|
const [isOpen, setIsOpen] = useState(false);
|
|
31
30
|
const {
|
|
32
31
|
refs,
|
|
@@ -66,7 +65,7 @@ const HeaderContent = props => {
|
|
|
66
65
|
// style={{flex: 1}}
|
|
67
66
|
,
|
|
68
67
|
className: classnames('', {})
|
|
69
|
-
}), headerTemplate ? getTemplate(headerTemplate) :
|
|
68
|
+
}), headerTemplate ? getTemplate(headerTemplate) : text), isOpen && (headerTooltip !== false || headerTemplate || headerTooltip || columnGroupText || headerText) && /*#__PURE__*/React.createElement(FloatingPortal, {
|
|
70
69
|
root: document.body
|
|
71
70
|
}, /*#__PURE__*/React.createElement(TooltipStyle, _extends({
|
|
72
71
|
className: "Tooltip",
|
|
@@ -156,7 +156,9 @@ const useColumns = config => {
|
|
|
156
156
|
// title: t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title,
|
|
157
157
|
// title: () => (<span>aaa</span>),
|
|
158
158
|
title: () => /*#__PURE__*/React.createElement(HeaderContent, {
|
|
159
|
-
column:
|
|
159
|
+
column: {
|
|
160
|
+
...col
|
|
161
|
+
},
|
|
160
162
|
t: t
|
|
161
163
|
}),
|
|
162
164
|
// title: () => (<span>{t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title}</span>),
|
|
@@ -181,7 +183,13 @@ const useColumns = config => {
|
|
|
181
183
|
}
|
|
182
184
|
if (col.key === 'command') {
|
|
183
185
|
return {
|
|
184
|
-
...transformedColumn
|
|
186
|
+
...transformedColumn,
|
|
187
|
+
onCell: () => ({
|
|
188
|
+
className: 'cell-number',
|
|
189
|
+
style: {
|
|
190
|
+
padding: '2px 8px'
|
|
191
|
+
}
|
|
192
|
+
})
|
|
185
193
|
};
|
|
186
194
|
}
|
|
187
195
|
return {
|
|
@@ -5,7 +5,7 @@ import type { ColumnEditType, ColumnsType, ColumnTable, GetRowKey } from "../typ
|
|
|
5
5
|
import type { SelectionSettings } from "../type";
|
|
6
6
|
import type { AnyObject } from "../type";
|
|
7
7
|
import type { Key } from "react";
|
|
8
|
-
import type { ColumnsTable } from "
|
|
8
|
+
import type { ColumnsTable } from "./../index";
|
|
9
9
|
export declare const newGuid: () => any;
|
|
10
10
|
export declare const sumDataByField: (data: any[], field: string) => any;
|
|
11
11
|
export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
|
|
@@ -55,26 +55,6 @@ export declare const getFirstSelectCell: (selectCells: any) => {
|
|
|
55
55
|
col: number;
|
|
56
56
|
};
|
|
57
57
|
export declare const getRowsPasteIndex: (pasteRows: any) => number[];
|
|
58
|
-
export declare const mmm: (string | number | boolean)[][];
|
|
59
|
-
export declare function cloneRows(array: any[], numRows: number): any[];
|
|
60
|
-
export declare function addRows1(arr: any[], n: number): any[];
|
|
61
|
-
export declare function addRows2(arr: any[], n: number): {
|
|
62
|
-
newArr: any[];
|
|
63
|
-
addedRows: any[];
|
|
64
|
-
};
|
|
65
|
-
export declare function addRows(arr: any[], n: number): {
|
|
66
|
-
newArr: any[];
|
|
67
|
-
addedRows: any[];
|
|
68
|
-
};
|
|
69
|
-
export declare function addRows4(arr: any[], n: number): {
|
|
70
|
-
newArr: any[];
|
|
71
|
-
addedRows: any[];
|
|
72
|
-
};
|
|
73
|
-
export declare function addRows6(arr: any, n: number): {
|
|
74
|
-
newArr: any[];
|
|
75
|
-
addedRows: any[];
|
|
76
|
-
};
|
|
77
|
-
export declare function addRows7(arr: any, n: number): any;
|
|
78
58
|
export declare function addRows8(arr: any, n: number): {
|
|
79
59
|
combined: any;
|
|
80
60
|
addedRows: any[];
|
|
@@ -84,5 +64,5 @@ export declare function addRows8(arr: any, n: number): {
|
|
|
84
64
|
};
|
|
85
65
|
export declare const transformColumns: <RecordType>(cols: ColumnsTable<RecordType>, convertColumns: any[], t?: any) => ColumnsTable<RecordType>;
|
|
86
66
|
export declare const transformColumns1: <RecordType>(cols: ColumnsTable<RecordType>, sortMultiple?: boolean) => ColumnsTable<RecordType>;
|
|
87
|
-
export declare const removeColumns: <RecordType>(columns: ColumnsTable
|
|
67
|
+
export declare const removeColumns: <RecordType>(columns: ColumnsTable<RecordType>, groupColumns: string[]) => ColumnsTable<RecordType>;
|
|
88
68
|
export declare const convertFlatColumn: (array: ColumnsTable) => ColumnsTable[];
|
|
@@ -494,400 +494,6 @@ export const getRowsPasteIndex = pasteRows => {
|
|
|
494
494
|
const result = Array.from(pasteRows).map(item => parseInt(item.split("-")[0]));
|
|
495
495
|
return [...new Set(result)];
|
|
496
496
|
};
|
|
497
|
-
|
|
498
|
-
// export const fff = [
|
|
499
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
500
|
-
// ]
|
|
501
|
-
//
|
|
502
|
-
// export const oooo = [
|
|
503
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
504
|
-
// [1,'1998-11-04T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
505
|
-
// [1,'1998-11-05T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
506
|
-
// [1,'1998-11-06T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
507
|
-
// ]
|
|
508
|
-
//
|
|
509
|
-
// export const iii = [
|
|
510
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
511
|
-
// [2,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
512
|
-
// [3,'1998-11-19T18:20:45+07:00', "tess", "C", true],
|
|
513
|
-
// ]
|
|
514
|
-
//
|
|
515
|
-
// export const jjj = [
|
|
516
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
517
|
-
// [2,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
518
|
-
// [3,'1998-11-19T18:20:45+07:00', "tess", "C", true],
|
|
519
|
-
//
|
|
520
|
-
// [4,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
521
|
-
// [5,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
522
|
-
// [6,'1998-11-19T18:20:45+07:00', "tess", "C", true],
|
|
523
|
-
// ]
|
|
524
|
-
//
|
|
525
|
-
//
|
|
526
|
-
export const mmm = [[1, '1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true], [3, '1998-11-04T18:20:45+07:00', "Fahey Roads", "C", true], [5, '1998-11-05T18:20:45+07:00', "tess", "C", true]];
|
|
527
|
-
//
|
|
528
|
-
// export const nnn = [
|
|
529
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
530
|
-
// [2,'1998-11-04T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
531
|
-
// [3,'1998-11-05T18:20:45+07:00', "tess", "C", true],
|
|
532
|
-
//
|
|
533
|
-
// [4,'1998-11-06T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
534
|
-
// [5,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
535
|
-
// [6,'1998-11-08T18:20:45+07:00', "tess", "C", true],
|
|
536
|
-
// ]
|
|
537
|
-
|
|
538
|
-
export function cloneRows(array, numRows) {
|
|
539
|
-
const result = [...array]; // Sao chép mảng ban đầu
|
|
540
|
-
|
|
541
|
-
for (let i = 0; i < numRows; i++) {
|
|
542
|
-
const lastId = result[result.length - 1][0]; // Lấy ID cuối cùng hiện có
|
|
543
|
-
|
|
544
|
-
for (let j = 0; j < array.length - 1; j++) {
|
|
545
|
-
// Nhân bản trừ dòng cuối
|
|
546
|
-
const newRow = [lastId + j + 1, array[j][1]]; // Tăng ID và giữ nguyên giá trị cột 2
|
|
547
|
-
result.push(newRow);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return result;
|
|
551
|
-
}
|
|
552
|
-
export function addRows1(arr, n) {
|
|
553
|
-
// const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
554
|
-
// const baseIndex = arr[arr.length - 1][0]; // Lấy chỉ mục cuối cùng
|
|
555
|
-
//
|
|
556
|
-
// for (let i = 0; i < n; i++) {
|
|
557
|
-
// const newIndex = baseIndex + 1 + i;
|
|
558
|
-
// const newRow = [newIndex, ...arr[i % arr.length].slice(1)]; // Lặp lại các phần tử còn lại theo vòng tròn
|
|
559
|
-
// newArr.push(newRow);
|
|
560
|
-
// }
|
|
561
|
-
//
|
|
562
|
-
// return newArr;
|
|
563
|
-
|
|
564
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
565
|
-
|
|
566
|
-
if (arr.length === 1) {
|
|
567
|
-
// Nếu chỉ có một phần tử, lặp lại phần tử đó n lần
|
|
568
|
-
for (let i = 0; i < n; i++) {
|
|
569
|
-
newArr.push([...arr[0]]);
|
|
570
|
-
}
|
|
571
|
-
} else {
|
|
572
|
-
const baseIndex = arr[arr.length - 1][0]; // Lấy chỉ mục cuối cùng
|
|
573
|
-
|
|
574
|
-
for (let i = 0; i < n; i++) {
|
|
575
|
-
const newIndex = baseIndex + 1 + i;
|
|
576
|
-
const newRow = [newIndex, ...arr[i % arr.length].slice(1)]; // Lặp lại các phần tử còn lại theo vòng tròn
|
|
577
|
-
newArr.push(newRow);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return newArr;
|
|
581
|
-
}
|
|
582
|
-
export function addRows2(arr, n) {
|
|
583
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
584
|
-
const addedRows = [];
|
|
585
|
-
if (arr.length === 1) {
|
|
586
|
-
// Nếu chỉ có một phần tử, lặp lại phần tử đó n lần
|
|
587
|
-
for (let i = 0; i < n; i++) {
|
|
588
|
-
newArr.push([...arr[0]]);
|
|
589
|
-
addedRows.push([...arr[0]]);
|
|
590
|
-
}
|
|
591
|
-
} else {
|
|
592
|
-
const differences = [];
|
|
593
|
-
for (let i = 1; i < arr.length; i++) {
|
|
594
|
-
differences.push(arr[i][0] - arr[i - 1][0]);
|
|
595
|
-
}
|
|
596
|
-
const step = differences.reduce((a, b) => a + b, 0) / differences.length; // Tính khoảng cách trung bình
|
|
597
|
-
|
|
598
|
-
for (let i = 0; i < n; i++) {
|
|
599
|
-
const newIndex = newArr[newArr.length - 1][0] + step;
|
|
600
|
-
const newRow = [newIndex, ...arr[i % arr.length].slice(1)]; // Lặp lại nội dung theo vòng tròn
|
|
601
|
-
newArr.push(newRow);
|
|
602
|
-
addedRows.push(newRow);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
return {
|
|
606
|
-
newArr,
|
|
607
|
-
addedRows
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
export function addRows(arr, n) {
|
|
611
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
612
|
-
const addedRows = [];
|
|
613
|
-
if (arr.length === 1) {
|
|
614
|
-
for (let i = 0; i < n; i++) {
|
|
615
|
-
newArr.push([...arr[0]]);
|
|
616
|
-
addedRows.push([...arr[0]]);
|
|
617
|
-
}
|
|
618
|
-
} else {
|
|
619
|
-
const diffs = arr[0].map((_, colIndex) => {
|
|
620
|
-
if (typeof arr[0][colIndex] === 'number') {
|
|
621
|
-
return arr[1][colIndex] - arr[0][colIndex];
|
|
622
|
-
} else if (!isNaN(Date.parse(arr[0][colIndex]))) {
|
|
623
|
-
console.log('Date.parse(arr[0][colIndex])', Date.parse(arr[0][colIndex]));
|
|
624
|
-
console.log('arr[0][colIndex]', arr[0][colIndex]);
|
|
625
|
-
// @ts-ignore
|
|
626
|
-
return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
|
|
627
|
-
}
|
|
628
|
-
return null;
|
|
629
|
-
});
|
|
630
|
-
console.log('diffs', diffs);
|
|
631
|
-
for (let i = 0; i < n; i++) {
|
|
632
|
-
const lastRow = [...newArr[newArr.length - 1]];
|
|
633
|
-
const newRow = lastRow.map((value, colIndex) => {
|
|
634
|
-
if (typeof value === 'number' && diffs[colIndex] !== null) {
|
|
635
|
-
return value + diffs[colIndex];
|
|
636
|
-
} else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
|
|
637
|
-
const lastDate = new Date(value);
|
|
638
|
-
return moment(new Date(lastDate.getTime() + diffs[colIndex])).format();
|
|
639
|
-
} else return arr[i % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
640
|
-
// arr[i % arr.length].slice(1)
|
|
641
|
-
// return value;
|
|
642
|
-
});
|
|
643
|
-
newArr.push(newRow);
|
|
644
|
-
addedRows.push(newRow);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
return {
|
|
648
|
-
newArr,
|
|
649
|
-
addedRows
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
export function addRows4(arr, n) {
|
|
653
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
654
|
-
const addedRows = [];
|
|
655
|
-
if (arr.length === 1) {
|
|
656
|
-
for (let i = 0; i < n; i++) {
|
|
657
|
-
newArr.push([...arr[0]]);
|
|
658
|
-
addedRows.push([...arr[0]]);
|
|
659
|
-
}
|
|
660
|
-
} else {
|
|
661
|
-
const diffs = arr[0].map((_, colIndex) => {
|
|
662
|
-
if (typeof arr[0][colIndex] === 'number') {
|
|
663
|
-
return arr[1][colIndex] - arr[0][colIndex];
|
|
664
|
-
} else if (!isNaN(Date.parse(arr[0][colIndex]))) {
|
|
665
|
-
// @ts-ignore
|
|
666
|
-
return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
|
|
667
|
-
}
|
|
668
|
-
return null;
|
|
669
|
-
});
|
|
670
|
-
for (let i = 0; i < n; i++) {
|
|
671
|
-
const lastRow = [...newArr[newArr.length - 1]];
|
|
672
|
-
const newRow = lastRow.map((value, colIndex) => {
|
|
673
|
-
if (typeof value === 'number' && diffs[colIndex] !== null) {
|
|
674
|
-
return value + diffs[colIndex];
|
|
675
|
-
} else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
|
|
676
|
-
const lastDate = new Date(value);
|
|
677
|
-
return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
|
|
678
|
-
} else if (typeof value === 'string') {
|
|
679
|
-
return arr[(i + 1) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
680
|
-
}
|
|
681
|
-
return value;
|
|
682
|
-
});
|
|
683
|
-
newArr.push(newRow);
|
|
684
|
-
addedRows.push(newRow);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
return {
|
|
688
|
-
newArr,
|
|
689
|
-
addedRows
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
export function addRows6(arr, n) {
|
|
693
|
-
// const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
694
|
-
// const addedRows = [];
|
|
695
|
-
//
|
|
696
|
-
// if (arr.length === 1) {
|
|
697
|
-
// for (let i = 0; i < n; i++) {
|
|
698
|
-
// newArr.push([...arr[0]]);
|
|
699
|
-
// addedRows.push([...arr[0]]);
|
|
700
|
-
// }
|
|
701
|
-
// } else {
|
|
702
|
-
// const diffs = arr[0].map((_: any, colIndex: number) => {
|
|
703
|
-
// if (typeof arr[0][colIndex] === 'number') {
|
|
704
|
-
// return arr[1][colIndex] - arr[0][colIndex];
|
|
705
|
-
// } else if (!isNaN(Date.parse(arr[0][colIndex])) && arr.length === 2) {
|
|
706
|
-
// // @ts-ignore
|
|
707
|
-
// return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
|
|
708
|
-
// }
|
|
709
|
-
// return null;
|
|
710
|
-
// });
|
|
711
|
-
//
|
|
712
|
-
// for (let i = 0; i < n; i++) {
|
|
713
|
-
// const lastRow = [...newArr[newArr.length - 1]];
|
|
714
|
-
//
|
|
715
|
-
// const newRow = lastRow.map((value, colIndex) => {
|
|
716
|
-
// if (typeof value === 'number' && diffs[colIndex] !== null) {
|
|
717
|
-
// return value + diffs[colIndex];
|
|
718
|
-
// } else if (!isNaN(Date.parse(value))) {
|
|
719
|
-
// if (arr.length > 2) {
|
|
720
|
-
// return arr[(i) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
721
|
-
// } else if (diffs[colIndex] !== null) {
|
|
722
|
-
// const lastDate = new Date(value);
|
|
723
|
-
// return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
|
|
724
|
-
// }
|
|
725
|
-
// } else if (typeof value === 'string') {
|
|
726
|
-
// return arr[(i) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
727
|
-
// }
|
|
728
|
-
// return value;
|
|
729
|
-
// });
|
|
730
|
-
//
|
|
731
|
-
// newArr.push(newRow);
|
|
732
|
-
// addedRows.push(newRow);
|
|
733
|
-
// }
|
|
734
|
-
// }
|
|
735
|
-
//
|
|
736
|
-
// return { newArr, addedRows };
|
|
737
|
-
|
|
738
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
739
|
-
const addedRows = [];
|
|
740
|
-
if (arr.length === 1) {
|
|
741
|
-
for (let i = 0; i < n; i++) {
|
|
742
|
-
newArr.push([...arr[0]]);
|
|
743
|
-
addedRows.push([...arr[0]]);
|
|
744
|
-
}
|
|
745
|
-
} else {
|
|
746
|
-
const diffs = arr[0].map((_, colIndex) => {
|
|
747
|
-
if (typeof arr[0][colIndex] === 'number') {
|
|
748
|
-
return arr[1][colIndex] - arr[0][colIndex];
|
|
749
|
-
} else if (!isNaN(Date.parse(arr[0][colIndex]))) {
|
|
750
|
-
// @ts-ignore
|
|
751
|
-
const dateDiffs = arr.slice(1).map((row, i) => new Date(row[colIndex]) - new Date(arr[i][colIndex]));
|
|
752
|
-
const avgDiff = dateDiffs.reduce((a, b) => a + b, 0) / dateDiffs.length;
|
|
753
|
-
return avgDiff || null;
|
|
754
|
-
}
|
|
755
|
-
return null;
|
|
756
|
-
});
|
|
757
|
-
for (let i = 0; i < n; i++) {
|
|
758
|
-
const lastRow = [...newArr[newArr.length - 1]];
|
|
759
|
-
const newRow = lastRow.map((value, colIndex) => {
|
|
760
|
-
if (typeof value === 'number' && diffs[colIndex] !== null) {
|
|
761
|
-
return value + diffs[colIndex];
|
|
762
|
-
} else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
|
|
763
|
-
const lastDate = new Date(value);
|
|
764
|
-
return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
|
|
765
|
-
} else {
|
|
766
|
-
return arr[i % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
newArr.push(newRow);
|
|
770
|
-
addedRows.push(newRow);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
return {
|
|
774
|
-
newArr,
|
|
775
|
-
addedRows
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
export function addRows7(arr, n) {
|
|
779
|
-
if (!Array.isArray(arr) || arr.length === 0) return arr;
|
|
780
|
-
const m = arr.length;
|
|
781
|
-
const numCols = arr[0].length;
|
|
782
|
-
const newRows = [];
|
|
783
|
-
|
|
784
|
-
// Hàm kiểm tra kiểu date hợp lệ
|
|
785
|
-
const isValidDate = d => {
|
|
786
|
-
return !isNaN(Date.parse(d));
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
// Lấy giá trị mẫu của cột j từ hàng i (i thuộc [0, m-1])
|
|
790
|
-
const getSample = j => arr[0][j];
|
|
791
|
-
|
|
792
|
-
// Xác định cho mỗi cột chế độ xử lý:
|
|
793
|
-
// mode = 'number-stepping' | 'date-stepping' | 'cycle'
|
|
794
|
-
const modes = [];
|
|
795
|
-
const steps = []; // bước tăng, nếu có (cho number hoặc date)
|
|
796
|
-
|
|
797
|
-
for (let j = 0; j < numCols; j++) {
|
|
798
|
-
const sample = getSample(j);
|
|
799
|
-
if (m === 1) {
|
|
800
|
-
// Nếu mảng chỉ có 1 hàng: nếu là số thì giữ nguyên; nếu là date thì tăng 1 ngày; còn lại giữ nguyên.
|
|
801
|
-
if (typeof sample === "number") {
|
|
802
|
-
modes[j] = "number-constant";
|
|
803
|
-
} else if (isValidDate(sample)) {
|
|
804
|
-
modes[j] = "date-stepping";
|
|
805
|
-
steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
|
|
806
|
-
} else {
|
|
807
|
-
modes[j] = "cycle";
|
|
808
|
-
}
|
|
809
|
-
} else if (m === 2) {
|
|
810
|
-
// Nếu mảng có 2 hàng: nếu là số thì tính bước = row2 - row1, tương tự với date
|
|
811
|
-
const first = arr[0][j],
|
|
812
|
-
second = arr[1][j];
|
|
813
|
-
if (typeof first === "number" && typeof second === "number") {
|
|
814
|
-
modes[j] = "number-stepping";
|
|
815
|
-
steps[j] = second - first;
|
|
816
|
-
} else if (isValidDate(first) && isValidDate(second)) {
|
|
817
|
-
modes[j] = "date-stepping";
|
|
818
|
-
steps[j] = Date.parse(second) - Date.parse(first);
|
|
819
|
-
} else {
|
|
820
|
-
modes[j] = "cycle";
|
|
821
|
-
}
|
|
822
|
-
} else {
|
|
823
|
-
// mảng có >2 hàng
|
|
824
|
-
const first = arr[0][j],
|
|
825
|
-
second = arr[1][j],
|
|
826
|
-
third = arr[2][j];
|
|
827
|
-
if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
|
|
828
|
-
const step1 = second - first;
|
|
829
|
-
const step2 = third - second;
|
|
830
|
-
if (step1 === step2) {
|
|
831
|
-
modes[j] = "number-stepping";
|
|
832
|
-
steps[j] = step1;
|
|
833
|
-
} else {
|
|
834
|
-
modes[j] = "cycle";
|
|
835
|
-
}
|
|
836
|
-
} else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
|
|
837
|
-
const step1 = Date.parse(second) - Date.parse(first);
|
|
838
|
-
const step2 = Date.parse(third) - Date.parse(second);
|
|
839
|
-
if (step1 === step2) {
|
|
840
|
-
modes[j] = "date-stepping";
|
|
841
|
-
steps[j] = step1;
|
|
842
|
-
} else {
|
|
843
|
-
modes[j] = "cycle";
|
|
844
|
-
}
|
|
845
|
-
} else {
|
|
846
|
-
modes[j] = "cycle";
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
// Tạo các dòng mới (thêm n dòng)
|
|
852
|
-
// Với mỗi cột, nếu chế độ là stepping thì lấy giá trị cuối của mảng ban đầu, cộng thêm (i+1)*step
|
|
853
|
-
// Nếu chế độ là cycle thì dùng arr[i mod m][j]
|
|
854
|
-
for (let i = 0; i < n; i++) {
|
|
855
|
-
const newRow = [];
|
|
856
|
-
for (let j = 0; j < numCols; j++) {
|
|
857
|
-
let newValue;
|
|
858
|
-
switch (modes[j]) {
|
|
859
|
-
case "number-constant":
|
|
860
|
-
// mảng có 1 hàng, số giữ nguyên
|
|
861
|
-
newValue = arr[0][j];
|
|
862
|
-
break;
|
|
863
|
-
case "number-stepping":
|
|
864
|
-
{
|
|
865
|
-
// lấy giá trị cuối của cột j trong mảng ban đầu
|
|
866
|
-
const lastValue = arr[m - 1][j];
|
|
867
|
-
newValue = lastValue + (i + 1) * steps[j];
|
|
868
|
-
}
|
|
869
|
-
break;
|
|
870
|
-
case "date-stepping":
|
|
871
|
-
{
|
|
872
|
-
// lấy giá trị cuối, chuyển về date, cộng thêm (i+1)*step, convert về ISO string giữ định dạng ban đầu (nếu cần giữ định dạng như cũ)
|
|
873
|
-
const lastDate = new Date(arr[m - 1][j]);
|
|
874
|
-
const newTime = lastDate.getTime() + (i + 1) * steps[j];
|
|
875
|
-
// Giữ định dạng ISO với timezone tương tự nếu cần.
|
|
876
|
-
newValue = new Date(newTime).toISOString();
|
|
877
|
-
}
|
|
878
|
-
break;
|
|
879
|
-
case "cycle":
|
|
880
|
-
default:
|
|
881
|
-
// Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
|
|
882
|
-
newValue = arr[i % m][j];
|
|
883
|
-
break;
|
|
884
|
-
}
|
|
885
|
-
newRow.push(newValue);
|
|
886
|
-
}
|
|
887
|
-
newRows.push(newRow);
|
|
888
|
-
}
|
|
889
|
-
return arr.concat(newRows);
|
|
890
|
-
}
|
|
891
497
|
export function addRows8(arr, n) {
|
|
892
498
|
if (!Array.isArray(arr) || arr.length === 0) return {
|
|
893
499
|
combined: arr,
|
|
@@ -1025,7 +631,7 @@ export const transformColumns = (cols, convertColumns, t) => {
|
|
|
1025
631
|
return {
|
|
1026
632
|
...column,
|
|
1027
633
|
key: column.field ?? column.dataIndex ?? column.key,
|
|
1028
|
-
title: t ? t(column.headerText
|
|
634
|
+
title: t ? t(column.headerText) : column.headerText,
|
|
1029
635
|
ellipsis: column.ellipsis !== false,
|
|
1030
636
|
align: column.textAlign ?? column.align,
|
|
1031
637
|
children: transformColumns(column.children, convertColumns)
|
|
@@ -1084,8 +690,6 @@ export const transformColumns1 = (cols, sortMultiple) => {
|
|
|
1084
690
|
};
|
|
1085
691
|
export const removeColumns = (columns, groupColumns) => {
|
|
1086
692
|
const ttt = [...columns];
|
|
1087
|
-
|
|
1088
|
-
// @ts-ignore
|
|
1089
693
|
return ttt.filter(column => !groupColumns.includes(column.field)).map(column => {
|
|
1090
694
|
const newCol = {
|
|
1091
695
|
...column
|
|
@@ -1107,16 +711,4 @@ export const convertFlatColumn = array => {
|
|
|
1107
711
|
}
|
|
1108
712
|
});
|
|
1109
713
|
return result;
|
|
1110
|
-
};
|
|
1111
|
-
|
|
1112
|
-
// export const getColumnsByKeys = (columns: ColumnsTable, keys: string[]) => {
|
|
1113
|
-
// if (!columns || !keys) {
|
|
1114
|
-
// return[]
|
|
1115
|
-
// }
|
|
1116
|
-
//
|
|
1117
|
-
// return flatColumns2(columns).filter((column) => keys.includes(column.field as string)).map((it) => {
|
|
1118
|
-
// return {...it, value: it.field, label: it.headerText}
|
|
1119
|
-
// })
|
|
1120
|
-
//
|
|
1121
|
-
//
|
|
1122
|
-
// }
|
|
714
|
+
};
|