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
|
@@ -82,7 +82,7 @@ export type ToolbarClick = {
|
|
|
82
82
|
item: any;
|
|
83
83
|
column: any;
|
|
84
84
|
};
|
|
85
|
-
export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTemplate'> & {
|
|
85
|
+
export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTemplate' | 'title'> & {
|
|
86
86
|
field?: string;
|
|
87
87
|
key?: any;
|
|
88
88
|
type?: IColumnType;
|
|
@@ -178,6 +178,7 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
|
|
|
178
178
|
onDataChange?: (data: RecordType[]) => void;
|
|
179
179
|
defaultValue?: AnyObject | (() => AnyObject);
|
|
180
180
|
summary?: boolean | ((data: readonly RecordType[]) => React.ReactNode);
|
|
181
|
+
showEmptyText?: boolean;
|
|
181
182
|
}
|
|
182
183
|
export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<RecordType>, 'columns'> {
|
|
183
184
|
columns: ColumnsTable<RecordType>;
|
|
@@ -9,4 +9,4 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
|
9
9
|
const GridStyle = exports.GridStyle = _styledComponents.default.div.withConfig({
|
|
10
10
|
displayName: "GridStyle",
|
|
11
11
|
componentId: "es-grid-template__sc-sueu2e-0"
|
|
12
|
-
})([".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;
|
|
12
|
+
})([".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);
|
|
@@ -8,6 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _reactResizable = require("react-resizable");
|
|
11
|
+
require("react-resizable/css/styles.css");
|
|
11
12
|
var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
|
|
12
13
|
var _hooks = require("./hooks");
|
|
13
14
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
@@ -42,7 +43,7 @@ const ResizableTitle = props => {
|
|
|
42
43
|
width: width,
|
|
43
44
|
height: 0,
|
|
44
45
|
handle: /*#__PURE__*/_react.default.createElement("span", {
|
|
45
|
-
className: "
|
|
46
|
+
className: "rc-resizable-handle",
|
|
46
47
|
onClick: e => {
|
|
47
48
|
e.stopPropagation();
|
|
48
49
|
}
|
|
@@ -15,7 +15,6 @@ require("dayjs/locale/vi");
|
|
|
15
15
|
var _ContextMenu = _interopRequireDefault(require("./ContextMenu"));
|
|
16
16
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
17
17
|
var _hooks = require("./hooks");
|
|
18
|
-
var _antd = require("antd");
|
|
19
18
|
var _columns = require("./hooks/columns");
|
|
20
19
|
var _pagination = _interopRequireDefault(require("rc-master-ui/es/pagination"));
|
|
21
20
|
var _LoadingSpinner = _interopRequireDefault(require("./LoadingSpinner"));
|
|
@@ -23,6 +22,8 @@ var _ColumnsChoose = require("./ColumnsChoose");
|
|
|
23
22
|
var _useMergedState = _interopRequireDefault(require("rc-util/lib/hooks/useMergedState"));
|
|
24
23
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
25
24
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
25
|
+
// import {ConfigProvider} from "antd";
|
|
26
|
+
|
|
26
27
|
const convertFilters = filters => {
|
|
27
28
|
const result = [];
|
|
28
29
|
filters.forEach(({
|
|
@@ -132,6 +133,7 @@ const TableGrid = props => {
|
|
|
132
133
|
getRowKey,
|
|
133
134
|
groupColumns,
|
|
134
135
|
groupToolbar,
|
|
136
|
+
showEmptyText,
|
|
135
137
|
...rest
|
|
136
138
|
} = props;
|
|
137
139
|
const {
|
|
@@ -294,17 +296,7 @@ const TableGrid = props => {
|
|
|
294
296
|
const handleChange = sorter => {
|
|
295
297
|
onSorter?.(sorter);
|
|
296
298
|
};
|
|
297
|
-
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(
|
|
298
|
-
theme: {
|
|
299
|
-
components: {
|
|
300
|
-
Table: {
|
|
301
|
-
rowHoverBg: '#eb461912',
|
|
302
|
-
rowSelectedBg: '#eb4619',
|
|
303
|
-
rowSelectedHoverBg: '#eb4619'
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}, /*#__PURE__*/_react.default.createElement(_ContextMenu.default, {
|
|
299
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_ContextMenu.default, {
|
|
308
300
|
open: menuVisible,
|
|
309
301
|
pos: position,
|
|
310
302
|
setOpen: setMenuVisible,
|
|
@@ -317,10 +309,10 @@ const TableGrid = props => {
|
|
|
317
309
|
}, rest, {
|
|
318
310
|
locale: {
|
|
319
311
|
...locale,
|
|
320
|
-
emptyText: /*#__PURE__*/_react.default.createElement(_rcMasterUi.Empty, {
|
|
312
|
+
emptyText: showEmptyText !== false ? /*#__PURE__*/_react.default.createElement(_rcMasterUi.Empty, {
|
|
321
313
|
image: _rcMasterUi.Empty.PRESENTED_IMAGE_SIMPLE,
|
|
322
314
|
description: locale?.emptyText
|
|
323
|
-
})
|
|
315
|
+
}) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null)
|
|
324
316
|
},
|
|
325
317
|
loading: {
|
|
326
318
|
spinning: columns && columns.length === 0 || loading === true,
|
|
@@ -455,6 +447,6 @@ const TableGrid = props => {
|
|
|
455
447
|
// @ts-ignore
|
|
456
448
|
,
|
|
457
449
|
showTotal: (total, range) => `${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
|
|
458
|
-
}, pagination)), bottomToolbar?.())
|
|
450
|
+
}, pagination)), bottomToolbar?.());
|
|
459
451
|
};
|
|
460
452
|
var _default = exports.default = TableGrid;
|
|
@@ -25,15 +25,14 @@ const HeaderContent = props => {
|
|
|
25
25
|
headerTooltip,
|
|
26
26
|
headerText,
|
|
27
27
|
columnGroupText,
|
|
28
|
-
headerTemplate
|
|
29
|
-
title
|
|
28
|
+
headerTemplate
|
|
30
29
|
} = props.column ?? {};
|
|
31
30
|
const text = _react.default.useMemo(() => {
|
|
32
|
-
return columnGroupText ?? headerText
|
|
33
|
-
}, [columnGroupText, headerText
|
|
31
|
+
return columnGroupText ?? headerText;
|
|
32
|
+
}, [columnGroupText, headerText]);
|
|
34
33
|
const tooltip = _react.default.useMemo(() => {
|
|
35
|
-
return headerTooltip ?? columnGroupText ?? headerText
|
|
36
|
-
}, [columnGroupText, headerText, headerTooltip
|
|
34
|
+
return headerTooltip ?? columnGroupText ?? headerText;
|
|
35
|
+
}, [columnGroupText, headerText, headerTooltip]);
|
|
37
36
|
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
38
37
|
const {
|
|
39
38
|
refs,
|
|
@@ -73,7 +72,7 @@ const HeaderContent = props => {
|
|
|
73
72
|
// style={{flex: 1}}
|
|
74
73
|
,
|
|
75
74
|
className: (0, _classnames.default)('', {})
|
|
76
|
-
}), headerTemplate ? (0, _utils.getTemplate)(headerTemplate) :
|
|
75
|
+
}), headerTemplate ? (0, _utils.getTemplate)(headerTemplate) : text), isOpen && (headerTooltip !== false || headerTemplate || headerTooltip || columnGroupText || headerText) && /*#__PURE__*/_react.default.createElement(_react2.FloatingPortal, {
|
|
77
76
|
root: document.body
|
|
78
77
|
}, /*#__PURE__*/_react.default.createElement(TooltipStyle, (0, _extends2.default)({
|
|
79
78
|
className: "Tooltip",
|
|
@@ -167,7 +167,9 @@ const useColumns = config => {
|
|
|
167
167
|
// title: t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title,
|
|
168
168
|
// title: () => (<span>aaa</span>),
|
|
169
169
|
title: () => /*#__PURE__*/React.createElement(_HeaderContent.default, {
|
|
170
|
-
column:
|
|
170
|
+
column: {
|
|
171
|
+
...col
|
|
172
|
+
},
|
|
171
173
|
t: t
|
|
172
174
|
}),
|
|
173
175
|
// title: () => (<span>{t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title}</span>),
|
|
@@ -192,7 +194,13 @@ const useColumns = config => {
|
|
|
192
194
|
}
|
|
193
195
|
if (col.key === 'command') {
|
|
194
196
|
return {
|
|
195
|
-
...transformedColumn
|
|
197
|
+
...transformedColumn,
|
|
198
|
+
onCell: () => ({
|
|
199
|
+
className: 'cell-number',
|
|
200
|
+
style: {
|
|
201
|
+
padding: '2px 8px'
|
|
202
|
+
}
|
|
203
|
+
})
|
|
196
204
|
};
|
|
197
205
|
}
|
|
198
206
|
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[];
|
|
@@ -5,20 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.addRowIdArray = void 0;
|
|
8
|
-
exports.addRows = addRows;
|
|
9
|
-
exports.addRows1 = addRows1;
|
|
10
|
-
exports.addRows2 = addRows2;
|
|
11
|
-
exports.addRows4 = addRows4;
|
|
12
|
-
exports.addRows6 = addRows6;
|
|
13
|
-
exports.addRows7 = addRows7;
|
|
14
8
|
exports.addRows8 = addRows8;
|
|
15
|
-
exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
|
|
16
|
-
exports.cloneRows = cloneRows;
|
|
17
|
-
exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertFlatColumn = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = void 0;
|
|
9
|
+
exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertFlatColumn = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
|
|
18
10
|
exports.findAllChildrenKeys = findAllChildrenKeys;
|
|
19
11
|
exports.getFirstSelectCell = exports.getEditType = exports.getDefaultValue = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = exports.findItemByKey = void 0;
|
|
20
12
|
exports.getHiddenParentKeys = getHiddenParentKeys;
|
|
21
|
-
exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.removeColumns = exports.parseBooleanToValue = exports.newGuid = exports.
|
|
13
|
+
exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.removeColumns = exports.parseBooleanToValue = exports.newGuid = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isDisable = exports.isColor = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = exports.getRowsPasteIndex = exports.getRowNumber = exports.getLastSelectCell = void 0;
|
|
22
14
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
23
15
|
var _moment = _interopRequireDefault(require("moment/moment"));
|
|
24
16
|
var _uuid = require("uuid");
|
|
@@ -554,401 +546,7 @@ const getRowsPasteIndex = pasteRows => {
|
|
|
554
546
|
const result = Array.from(pasteRows).map(item => parseInt(item.split("-")[0]));
|
|
555
547
|
return [...new Set(result)];
|
|
556
548
|
};
|
|
557
|
-
|
|
558
|
-
// export const fff = [
|
|
559
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
560
|
-
// ]
|
|
561
|
-
//
|
|
562
|
-
// export const oooo = [
|
|
563
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
564
|
-
// [1,'1998-11-04T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
565
|
-
// [1,'1998-11-05T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
566
|
-
// [1,'1998-11-06T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
567
|
-
// ]
|
|
568
|
-
//
|
|
569
|
-
// export const iii = [
|
|
570
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
571
|
-
// [2,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
572
|
-
// [3,'1998-11-19T18:20:45+07:00', "tess", "C", true],
|
|
573
|
-
// ]
|
|
574
|
-
//
|
|
575
|
-
// export const jjj = [
|
|
576
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
577
|
-
// [2,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
578
|
-
// [3,'1998-11-19T18:20:45+07:00', "tess", "C", true],
|
|
579
|
-
//
|
|
580
|
-
// [4,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
581
|
-
// [5,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
582
|
-
// [6,'1998-11-19T18:20:45+07:00', "tess", "C", true],
|
|
583
|
-
// ]
|
|
584
|
-
//
|
|
585
|
-
//
|
|
586
549
|
exports.getRowsPasteIndex = getRowsPasteIndex;
|
|
587
|
-
const mmm = exports.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]];
|
|
588
|
-
//
|
|
589
|
-
// export const nnn = [
|
|
590
|
-
// [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
591
|
-
// [2,'1998-11-04T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
592
|
-
// [3,'1998-11-05T18:20:45+07:00', "tess", "C", true],
|
|
593
|
-
//
|
|
594
|
-
// [4,'1998-11-06T18:20:45+07:00', "Fadel Groves", "C", true],
|
|
595
|
-
// [5,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
|
|
596
|
-
// [6,'1998-11-08T18:20:45+07:00', "tess", "C", true],
|
|
597
|
-
// ]
|
|
598
|
-
|
|
599
|
-
function cloneRows(array, numRows) {
|
|
600
|
-
const result = [...array]; // Sao chép mảng ban đầu
|
|
601
|
-
|
|
602
|
-
for (let i = 0; i < numRows; i++) {
|
|
603
|
-
const lastId = result[result.length - 1][0]; // Lấy ID cuối cùng hiện có
|
|
604
|
-
|
|
605
|
-
for (let j = 0; j < array.length - 1; j++) {
|
|
606
|
-
// Nhân bản trừ dòng cuối
|
|
607
|
-
const newRow = [lastId + j + 1, array[j][1]]; // Tăng ID và giữ nguyên giá trị cột 2
|
|
608
|
-
result.push(newRow);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return result;
|
|
612
|
-
}
|
|
613
|
-
function addRows1(arr, n) {
|
|
614
|
-
// const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
615
|
-
// const baseIndex = arr[arr.length - 1][0]; // Lấy chỉ mục cuối cùng
|
|
616
|
-
//
|
|
617
|
-
// for (let i = 0; i < n; i++) {
|
|
618
|
-
// const newIndex = baseIndex + 1 + i;
|
|
619
|
-
// 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
|
|
620
|
-
// newArr.push(newRow);
|
|
621
|
-
// }
|
|
622
|
-
//
|
|
623
|
-
// return newArr;
|
|
624
|
-
|
|
625
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
626
|
-
|
|
627
|
-
if (arr.length === 1) {
|
|
628
|
-
// Nếu chỉ có một phần tử, lặp lại phần tử đó n lần
|
|
629
|
-
for (let i = 0; i < n; i++) {
|
|
630
|
-
newArr.push([...arr[0]]);
|
|
631
|
-
}
|
|
632
|
-
} else {
|
|
633
|
-
const baseIndex = arr[arr.length - 1][0]; // Lấy chỉ mục cuối cùng
|
|
634
|
-
|
|
635
|
-
for (let i = 0; i < n; i++) {
|
|
636
|
-
const newIndex = baseIndex + 1 + i;
|
|
637
|
-
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
|
|
638
|
-
newArr.push(newRow);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
return newArr;
|
|
642
|
-
}
|
|
643
|
-
function addRows2(arr, n) {
|
|
644
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
645
|
-
const addedRows = [];
|
|
646
|
-
if (arr.length === 1) {
|
|
647
|
-
// Nếu chỉ có một phần tử, lặp lại phần tử đó n lần
|
|
648
|
-
for (let i = 0; i < n; i++) {
|
|
649
|
-
newArr.push([...arr[0]]);
|
|
650
|
-
addedRows.push([...arr[0]]);
|
|
651
|
-
}
|
|
652
|
-
} else {
|
|
653
|
-
const differences = [];
|
|
654
|
-
for (let i = 1; i < arr.length; i++) {
|
|
655
|
-
differences.push(arr[i][0] - arr[i - 1][0]);
|
|
656
|
-
}
|
|
657
|
-
const step = differences.reduce((a, b) => a + b, 0) / differences.length; // Tính khoảng cách trung bình
|
|
658
|
-
|
|
659
|
-
for (let i = 0; i < n; i++) {
|
|
660
|
-
const newIndex = newArr[newArr.length - 1][0] + step;
|
|
661
|
-
const newRow = [newIndex, ...arr[i % arr.length].slice(1)]; // Lặp lại nội dung theo vòng tròn
|
|
662
|
-
newArr.push(newRow);
|
|
663
|
-
addedRows.push(newRow);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return {
|
|
667
|
-
newArr,
|
|
668
|
-
addedRows
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
function addRows(arr, n) {
|
|
672
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
673
|
-
const addedRows = [];
|
|
674
|
-
if (arr.length === 1) {
|
|
675
|
-
for (let i = 0; i < n; i++) {
|
|
676
|
-
newArr.push([...arr[0]]);
|
|
677
|
-
addedRows.push([...arr[0]]);
|
|
678
|
-
}
|
|
679
|
-
} else {
|
|
680
|
-
const diffs = arr[0].map((_, colIndex) => {
|
|
681
|
-
if (typeof arr[0][colIndex] === 'number') {
|
|
682
|
-
return arr[1][colIndex] - arr[0][colIndex];
|
|
683
|
-
} else if (!isNaN(Date.parse(arr[0][colIndex]))) {
|
|
684
|
-
console.log('Date.parse(arr[0][colIndex])', Date.parse(arr[0][colIndex]));
|
|
685
|
-
console.log('arr[0][colIndex]', arr[0][colIndex]);
|
|
686
|
-
// @ts-ignore
|
|
687
|
-
return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
|
|
688
|
-
}
|
|
689
|
-
return null;
|
|
690
|
-
});
|
|
691
|
-
console.log('diffs', diffs);
|
|
692
|
-
for (let i = 0; i < n; i++) {
|
|
693
|
-
const lastRow = [...newArr[newArr.length - 1]];
|
|
694
|
-
const newRow = lastRow.map((value, colIndex) => {
|
|
695
|
-
if (typeof value === 'number' && diffs[colIndex] !== null) {
|
|
696
|
-
return value + diffs[colIndex];
|
|
697
|
-
} else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
|
|
698
|
-
const lastDate = new Date(value);
|
|
699
|
-
return (0, _moment.default)(new Date(lastDate.getTime() + diffs[colIndex])).format();
|
|
700
|
-
} else return arr[i % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
701
|
-
// arr[i % arr.length].slice(1)
|
|
702
|
-
// return value;
|
|
703
|
-
});
|
|
704
|
-
newArr.push(newRow);
|
|
705
|
-
addedRows.push(newRow);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
return {
|
|
709
|
-
newArr,
|
|
710
|
-
addedRows
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
function addRows4(arr, n) {
|
|
714
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
715
|
-
const addedRows = [];
|
|
716
|
-
if (arr.length === 1) {
|
|
717
|
-
for (let i = 0; i < n; i++) {
|
|
718
|
-
newArr.push([...arr[0]]);
|
|
719
|
-
addedRows.push([...arr[0]]);
|
|
720
|
-
}
|
|
721
|
-
} else {
|
|
722
|
-
const diffs = arr[0].map((_, colIndex) => {
|
|
723
|
-
if (typeof arr[0][colIndex] === 'number') {
|
|
724
|
-
return arr[1][colIndex] - arr[0][colIndex];
|
|
725
|
-
} else if (!isNaN(Date.parse(arr[0][colIndex]))) {
|
|
726
|
-
// @ts-ignore
|
|
727
|
-
return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
|
|
728
|
-
}
|
|
729
|
-
return null;
|
|
730
|
-
});
|
|
731
|
-
for (let i = 0; i < n; i++) {
|
|
732
|
-
const lastRow = [...newArr[newArr.length - 1]];
|
|
733
|
-
const newRow = lastRow.map((value, colIndex) => {
|
|
734
|
-
if (typeof value === 'number' && diffs[colIndex] !== null) {
|
|
735
|
-
return value + diffs[colIndex];
|
|
736
|
-
} else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
|
|
737
|
-
const lastDate = new Date(value);
|
|
738
|
-
return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
|
|
739
|
-
} else if (typeof value === 'string') {
|
|
740
|
-
return arr[(i + 1) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
741
|
-
}
|
|
742
|
-
return value;
|
|
743
|
-
});
|
|
744
|
-
newArr.push(newRow);
|
|
745
|
-
addedRows.push(newRow);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
return {
|
|
749
|
-
newArr,
|
|
750
|
-
addedRows
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
function addRows6(arr, n) {
|
|
754
|
-
// const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
755
|
-
// const addedRows = [];
|
|
756
|
-
//
|
|
757
|
-
// if (arr.length === 1) {
|
|
758
|
-
// for (let i = 0; i < n; i++) {
|
|
759
|
-
// newArr.push([...arr[0]]);
|
|
760
|
-
// addedRows.push([...arr[0]]);
|
|
761
|
-
// }
|
|
762
|
-
// } else {
|
|
763
|
-
// const diffs = arr[0].map((_: any, colIndex: number) => {
|
|
764
|
-
// if (typeof arr[0][colIndex] === 'number') {
|
|
765
|
-
// return arr[1][colIndex] - arr[0][colIndex];
|
|
766
|
-
// } else if (!isNaN(Date.parse(arr[0][colIndex])) && arr.length === 2) {
|
|
767
|
-
// // @ts-ignore
|
|
768
|
-
// return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
|
|
769
|
-
// }
|
|
770
|
-
// return null;
|
|
771
|
-
// });
|
|
772
|
-
//
|
|
773
|
-
// for (let i = 0; i < n; i++) {
|
|
774
|
-
// const lastRow = [...newArr[newArr.length - 1]];
|
|
775
|
-
//
|
|
776
|
-
// const newRow = lastRow.map((value, colIndex) => {
|
|
777
|
-
// if (typeof value === 'number' && diffs[colIndex] !== null) {
|
|
778
|
-
// return value + diffs[colIndex];
|
|
779
|
-
// } else if (!isNaN(Date.parse(value))) {
|
|
780
|
-
// if (arr.length > 2) {
|
|
781
|
-
// return arr[(i) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
782
|
-
// } else if (diffs[colIndex] !== null) {
|
|
783
|
-
// const lastDate = new Date(value);
|
|
784
|
-
// return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
|
|
785
|
-
// }
|
|
786
|
-
// } else if (typeof value === 'string') {
|
|
787
|
-
// return arr[(i) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
788
|
-
// }
|
|
789
|
-
// return value;
|
|
790
|
-
// });
|
|
791
|
-
//
|
|
792
|
-
// newArr.push(newRow);
|
|
793
|
-
// addedRows.push(newRow);
|
|
794
|
-
// }
|
|
795
|
-
// }
|
|
796
|
-
//
|
|
797
|
-
// return { newArr, addedRows };
|
|
798
|
-
|
|
799
|
-
const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
|
|
800
|
-
const addedRows = [];
|
|
801
|
-
if (arr.length === 1) {
|
|
802
|
-
for (let i = 0; i < n; i++) {
|
|
803
|
-
newArr.push([...arr[0]]);
|
|
804
|
-
addedRows.push([...arr[0]]);
|
|
805
|
-
}
|
|
806
|
-
} else {
|
|
807
|
-
const diffs = arr[0].map((_, colIndex) => {
|
|
808
|
-
if (typeof arr[0][colIndex] === 'number') {
|
|
809
|
-
return arr[1][colIndex] - arr[0][colIndex];
|
|
810
|
-
} else if (!isNaN(Date.parse(arr[0][colIndex]))) {
|
|
811
|
-
// @ts-ignore
|
|
812
|
-
const dateDiffs = arr.slice(1).map((row, i) => new Date(row[colIndex]) - new Date(arr[i][colIndex]));
|
|
813
|
-
const avgDiff = dateDiffs.reduce((a, b) => a + b, 0) / dateDiffs.length;
|
|
814
|
-
return avgDiff || null;
|
|
815
|
-
}
|
|
816
|
-
return null;
|
|
817
|
-
});
|
|
818
|
-
for (let i = 0; i < n; i++) {
|
|
819
|
-
const lastRow = [...newArr[newArr.length - 1]];
|
|
820
|
-
const newRow = lastRow.map((value, colIndex) => {
|
|
821
|
-
if (typeof value === 'number' && diffs[colIndex] !== null) {
|
|
822
|
-
return value + diffs[colIndex];
|
|
823
|
-
} else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
|
|
824
|
-
const lastDate = new Date(value);
|
|
825
|
-
return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
|
|
826
|
-
} else {
|
|
827
|
-
return arr[i % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
|
|
828
|
-
}
|
|
829
|
-
});
|
|
830
|
-
newArr.push(newRow);
|
|
831
|
-
addedRows.push(newRow);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
return {
|
|
835
|
-
newArr,
|
|
836
|
-
addedRows
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
function addRows7(arr, n) {
|
|
840
|
-
if (!Array.isArray(arr) || arr.length === 0) return arr;
|
|
841
|
-
const m = arr.length;
|
|
842
|
-
const numCols = arr[0].length;
|
|
843
|
-
const newRows = [];
|
|
844
|
-
|
|
845
|
-
// Hàm kiểm tra kiểu date hợp lệ
|
|
846
|
-
const isValidDate = d => {
|
|
847
|
-
return !isNaN(Date.parse(d));
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
// Lấy giá trị mẫu của cột j từ hàng i (i thuộc [0, m-1])
|
|
851
|
-
const getSample = j => arr[0][j];
|
|
852
|
-
|
|
853
|
-
// Xác định cho mỗi cột chế độ xử lý:
|
|
854
|
-
// mode = 'number-stepping' | 'date-stepping' | 'cycle'
|
|
855
|
-
const modes = [];
|
|
856
|
-
const steps = []; // bước tăng, nếu có (cho number hoặc date)
|
|
857
|
-
|
|
858
|
-
for (let j = 0; j < numCols; j++) {
|
|
859
|
-
const sample = getSample(j);
|
|
860
|
-
if (m === 1) {
|
|
861
|
-
// 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.
|
|
862
|
-
if (typeof sample === "number") {
|
|
863
|
-
modes[j] = "number-constant";
|
|
864
|
-
} else if (isValidDate(sample)) {
|
|
865
|
-
modes[j] = "date-stepping";
|
|
866
|
-
steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
|
|
867
|
-
} else {
|
|
868
|
-
modes[j] = "cycle";
|
|
869
|
-
}
|
|
870
|
-
} else if (m === 2) {
|
|
871
|
-
// 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
|
|
872
|
-
const first = arr[0][j],
|
|
873
|
-
second = arr[1][j];
|
|
874
|
-
if (typeof first === "number" && typeof second === "number") {
|
|
875
|
-
modes[j] = "number-stepping";
|
|
876
|
-
steps[j] = second - first;
|
|
877
|
-
} else if (isValidDate(first) && isValidDate(second)) {
|
|
878
|
-
modes[j] = "date-stepping";
|
|
879
|
-
steps[j] = Date.parse(second) - Date.parse(first);
|
|
880
|
-
} else {
|
|
881
|
-
modes[j] = "cycle";
|
|
882
|
-
}
|
|
883
|
-
} else {
|
|
884
|
-
// mảng có >2 hàng
|
|
885
|
-
const first = arr[0][j],
|
|
886
|
-
second = arr[1][j],
|
|
887
|
-
third = arr[2][j];
|
|
888
|
-
if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
|
|
889
|
-
const step1 = second - first;
|
|
890
|
-
const step2 = third - second;
|
|
891
|
-
if (step1 === step2) {
|
|
892
|
-
modes[j] = "number-stepping";
|
|
893
|
-
steps[j] = step1;
|
|
894
|
-
} else {
|
|
895
|
-
modes[j] = "cycle";
|
|
896
|
-
}
|
|
897
|
-
} else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
|
|
898
|
-
const step1 = Date.parse(second) - Date.parse(first);
|
|
899
|
-
const step2 = Date.parse(third) - Date.parse(second);
|
|
900
|
-
if (step1 === step2) {
|
|
901
|
-
modes[j] = "date-stepping";
|
|
902
|
-
steps[j] = step1;
|
|
903
|
-
} else {
|
|
904
|
-
modes[j] = "cycle";
|
|
905
|
-
}
|
|
906
|
-
} else {
|
|
907
|
-
modes[j] = "cycle";
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
// Tạo các dòng mới (thêm n dòng)
|
|
913
|
-
// 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
|
|
914
|
-
// Nếu chế độ là cycle thì dùng arr[i mod m][j]
|
|
915
|
-
for (let i = 0; i < n; i++) {
|
|
916
|
-
const newRow = [];
|
|
917
|
-
for (let j = 0; j < numCols; j++) {
|
|
918
|
-
let newValue;
|
|
919
|
-
switch (modes[j]) {
|
|
920
|
-
case "number-constant":
|
|
921
|
-
// mảng có 1 hàng, số giữ nguyên
|
|
922
|
-
newValue = arr[0][j];
|
|
923
|
-
break;
|
|
924
|
-
case "number-stepping":
|
|
925
|
-
{
|
|
926
|
-
// lấy giá trị cuối của cột j trong mảng ban đầu
|
|
927
|
-
const lastValue = arr[m - 1][j];
|
|
928
|
-
newValue = lastValue + (i + 1) * steps[j];
|
|
929
|
-
}
|
|
930
|
-
break;
|
|
931
|
-
case "date-stepping":
|
|
932
|
-
{
|
|
933
|
-
// 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ũ)
|
|
934
|
-
const lastDate = new Date(arr[m - 1][j]);
|
|
935
|
-
const newTime = lastDate.getTime() + (i + 1) * steps[j];
|
|
936
|
-
// Giữ định dạng ISO với timezone tương tự nếu cần.
|
|
937
|
-
newValue = new Date(newTime).toISOString();
|
|
938
|
-
}
|
|
939
|
-
break;
|
|
940
|
-
case "cycle":
|
|
941
|
-
default:
|
|
942
|
-
// Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
|
|
943
|
-
newValue = arr[i % m][j];
|
|
944
|
-
break;
|
|
945
|
-
}
|
|
946
|
-
newRow.push(newValue);
|
|
947
|
-
}
|
|
948
|
-
newRows.push(newRow);
|
|
949
|
-
}
|
|
950
|
-
return arr.concat(newRows);
|
|
951
|
-
}
|
|
952
550
|
function addRows8(arr, n) {
|
|
953
551
|
if (!Array.isArray(arr) || arr.length === 0) return {
|
|
954
552
|
combined: arr,
|
|
@@ -1086,7 +684,7 @@ const transformColumns = (cols, convertColumns, t) => {
|
|
|
1086
684
|
return {
|
|
1087
685
|
...column,
|
|
1088
686
|
key: column.field ?? column.dataIndex ?? column.key,
|
|
1089
|
-
title: t ? t(column.headerText
|
|
687
|
+
title: t ? t(column.headerText) : column.headerText,
|
|
1090
688
|
ellipsis: column.ellipsis !== false,
|
|
1091
689
|
align: column.textAlign ?? column.align,
|
|
1092
690
|
children: transformColumns(column.children, convertColumns)
|
|
@@ -1147,8 +745,6 @@ const transformColumns1 = (cols, sortMultiple) => {
|
|
|
1147
745
|
exports.transformColumns1 = transformColumns1;
|
|
1148
746
|
const removeColumns = (columns, groupColumns) => {
|
|
1149
747
|
const ttt = [...columns];
|
|
1150
|
-
|
|
1151
|
-
// @ts-ignore
|
|
1152
748
|
return ttt.filter(column => !groupColumns.includes(column.field)).map(column => {
|
|
1153
749
|
const newCol = {
|
|
1154
750
|
...column
|
|
@@ -1172,16 +768,4 @@ const convertFlatColumn = array => {
|
|
|
1172
768
|
});
|
|
1173
769
|
return result;
|
|
1174
770
|
};
|
|
1175
|
-
|
|
1176
|
-
// export const getColumnsByKeys = (columns: ColumnsTable, keys: string[]) => {
|
|
1177
|
-
// if (!columns || !keys) {
|
|
1178
|
-
// return[]
|
|
1179
|
-
// }
|
|
1180
|
-
//
|
|
1181
|
-
// return flatColumns2(columns).filter((column) => keys.includes(column.field as string)).map((it) => {
|
|
1182
|
-
// return {...it, value: it.field, label: it.headerText}
|
|
1183
|
-
// })
|
|
1184
|
-
//
|
|
1185
|
-
//
|
|
1186
|
-
// }
|
|
1187
771
|
exports.convertFlatColumn = convertFlatColumn;
|