es-grid-template 1.8.71 → 1.8.72
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/es/grid-component/TempTable.js +2 -1
- package/es/group-component/ColumnsChoose.d.ts +13 -0
- package/es/group-component/ColumnsChoose.js +211 -0
- package/es/group-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/es/group-component/ColumnsGroup/ColumnsGroup.js +230 -0
- package/es/group-component/ColumnsGroup/index.d.ts +1 -0
- package/es/group-component/ColumnsGroup/index.js +1 -0
- package/es/group-component/ContextMenu.d.ts +19 -0
- package/es/group-component/ContextMenu.js +74 -0
- package/es/group-component/InternalTable.d.ts +8 -0
- package/es/group-component/InternalTable.js +224 -0
- package/es/group-component/TableContainer.d.ts +49 -0
- package/es/group-component/TableContainer.js +375 -0
- package/es/group-component/TableContainerEdit.d.ts +48 -0
- package/es/group-component/TableContainerEdit.js +2068 -0
- package/es/group-component/body/EditableCell.d.ts +16 -0
- package/es/group-component/body/EditableCell.js +1066 -0
- package/es/group-component/body/TableBody.d.ts +14 -0
- package/es/group-component/body/TableBody.js +82 -0
- package/es/group-component/body/TableBodyCell.d.ts +12 -0
- package/es/group-component/body/TableBodyCell.js +587 -0
- package/es/group-component/body/TableBodyCellEdit.d.ts +17 -0
- package/es/group-component/body/TableBodyCellEdit.js +1398 -0
- package/es/group-component/body/TableBodyCellEmpty.d.ts +12 -0
- package/es/group-component/body/TableBodyCellEmpty.js +149 -0
- package/es/group-component/body/TableBodyRow.d.ts +21 -0
- package/es/group-component/body/TableBodyRow.js +199 -0
- package/es/group-component/body/TableBodyRowGroupCell.d.ts +12 -0
- package/es/group-component/body/TableBodyRowGroupCell.js +567 -0
- package/es/group-component/components/ControlCheckbox.d.ts +13 -0
- package/es/group-component/components/ControlCheckbox.js +84 -0
- package/es/group-component/components/EditForm/EditForm.d.ts +27 -0
- package/es/group-component/components/EditForm/EditForm.js +394 -0
- package/es/group-component/components/EditForm/index.d.ts +1 -0
- package/es/group-component/components/EditForm/index.js +1 -0
- package/es/group-component/components/InputControl/InputControl.d.ts +27 -0
- package/es/group-component/components/InputControl/InputControl.js +118 -0
- package/es/group-component/components/InputControl/index.d.ts +1 -0
- package/es/group-component/components/InputControl/index.js +1 -0
- package/es/group-component/components/async-select/index.d.ts +11 -0
- package/es/group-component/components/async-select/index.js +38 -0
- package/es/group-component/components/async-table-select/index.d.ts +11 -0
- package/es/group-component/components/async-table-select/index.js +40 -0
- package/es/group-component/components/checkbox-control/index.d.ts +13 -0
- package/es/group-component/components/checkbox-control/index.js +40 -0
- package/es/group-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/es/group-component/components/checkbox-filter/CheckboxFilter.js +258 -0
- package/es/group-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/es/group-component/components/checkbox-filter/FilterSearch.js +36 -0
- package/es/group-component/components/command/Command.d.ts +10 -0
- package/es/group-component/components/command/Command.js +35 -0
- package/es/group-component/components/number/index.d.ts +12 -0
- package/es/group-component/components/number/index.js +42 -0
- package/es/group-component/components/number-range/index.d.ts +13 -0
- package/es/group-component/components/number-range/index.js +79 -0
- package/es/group-component/features/operator.d.ts +24 -0
- package/es/group-component/features/operator.js +62 -0
- package/es/group-component/footer/TableFooter.d.ts +7 -0
- package/es/group-component/footer/TableFooter.js +34 -0
- package/es/group-component/footer/TableFooterCell.d.ts +7 -0
- package/es/group-component/footer/TableFooterCell.js +66 -0
- package/es/group-component/footer/TableFooterRow.d.ts +8 -0
- package/es/group-component/footer/TableFooterRow.js +30 -0
- package/es/group-component/header/TableHead.d.ts +15 -0
- package/es/group-component/header/TableHead.js +98 -0
- package/es/group-component/header/TableHeadCell.d.ts +15 -0
- package/es/group-component/header/TableHeadCell.js +310 -0
- package/es/group-component/header/TableHeadCell2.d.ts +17 -0
- package/es/group-component/header/TableHeadCell2.js +321 -0
- package/es/group-component/header/TableHeadGroupCell.d.ts +17 -0
- package/es/group-component/header/TableHeadGroupCell.js +94 -0
- package/es/group-component/header/TableHeadRow.d.ts +15 -0
- package/es/group-component/header/TableHeadRow.js +52 -0
- package/es/group-component/header/renderFilter.d.ts +20 -0
- package/es/group-component/header/renderFilter.js +291 -0
- package/es/group-component/hook/convert.d.ts +1 -0
- package/es/group-component/hook/convert.js +28 -0
- package/es/group-component/hook/useColumns.d.ts +28 -0
- package/es/group-component/hook/useColumns.js +306 -0
- package/es/group-component/hook/useFilterOperator.d.ts +7 -0
- package/es/group-component/hook/useFilterOperator.js +33 -0
- package/es/group-component/hook/utils.d.ts +220 -0
- package/es/group-component/hook/utils.js +2340 -0
- package/es/group-component/index.d.ts +2 -0
- package/es/group-component/index.js +2 -0
- package/es/group-component/style.d.ts +22 -0
- package/es/group-component/style.js +48 -0
- package/es/group-component/style.scss +1438 -0
- package/es/group-component/table/Grid.d.ts +33 -0
- package/es/group-component/table/Grid.js +438 -0
- package/es/group-component/table/TableWrapper.d.ts +33 -0
- package/es/group-component/table/TableWrapper.js +250 -0
- package/es/group-component/useContext.d.ts +100 -0
- package/es/group-component/useContext.js +21 -0
- package/es/table-component/InternalTable.js +6 -1
- package/es/table-component/TableContainer.js +4 -2
- package/es/table-component/body/TableBodyCell.js +49 -40
- package/es/table-component/body/TableBodyRow.js +4 -1
- package/es/table-component/hook/utils.d.ts +1 -0
- package/es/table-component/hook/utils.js +15 -7
- package/es/table-component/style.js +1 -1
- package/es/table-component/table/Grid.js +3 -0
- package/es/table-component/useContext.d.ts +5 -0
- package/es/table-virtuoso/InternalTable.js +2 -2
- package/es/table-virtuoso/body/TableBodyCell.js +2 -7
- package/es/table-virtuoso/body/TableBodyCellRowGroup.d.ts +14 -0
- package/es/table-virtuoso/body/TableBodyCellRowGroup.js +196 -0
- package/es/table-virtuoso/body/TableBodyRow.d.ts +1 -1
- package/es/table-virtuoso/body/TableBodyRow.js +43 -1
- package/es/table-virtuoso/hook/utils.d.ts +1 -0
- package/es/table-virtuoso/hook/utils.js +29 -0
- package/es/table-virtuoso/style.js +3 -1
- package/es/table-virtuoso/table/Grid.js +2 -2
- package/es/table-virtuoso/table/TableWrapper.d.ts +7 -1
- package/es/table-virtuoso/table/TableWrapper.js +24 -5
- package/es/table-virtuoso/useContext.d.ts +6 -3
- package/es/table-virtuoso/useContext.js +18 -0
- package/lib/grid-component/TempTable.js +2 -1
- package/lib/group-component/ColumnsChoose.d.ts +13 -0
- package/lib/group-component/ColumnsChoose.js +221 -0
- package/lib/group-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/lib/group-component/ColumnsGroup/ColumnsGroup.js +241 -0
- package/lib/group-component/ColumnsGroup/index.d.ts +1 -0
- package/lib/group-component/ColumnsGroup/index.js +16 -0
- package/lib/group-component/ContextMenu.d.ts +19 -0
- package/lib/group-component/ContextMenu.js +83 -0
- package/lib/group-component/InternalTable.d.ts +8 -0
- package/lib/group-component/InternalTable.js +233 -0
- package/lib/group-component/TableContainer.d.ts +49 -0
- package/lib/group-component/TableContainer.js +382 -0
- package/lib/group-component/TableContainerEdit.d.ts +48 -0
- package/lib/group-component/TableContainerEdit.js +2075 -0
- package/lib/group-component/body/EditableCell.d.ts +16 -0
- package/lib/group-component/body/EditableCell.js +1075 -0
- package/lib/group-component/body/TableBody.d.ts +14 -0
- package/lib/group-component/body/TableBody.js +91 -0
- package/lib/group-component/body/TableBodyCell.d.ts +12 -0
- package/lib/group-component/body/TableBodyCell.js +595 -0
- package/lib/group-component/body/TableBodyCellEdit.d.ts +17 -0
- package/lib/group-component/body/TableBodyCellEdit.js +1405 -0
- package/lib/group-component/body/TableBodyCellEmpty.d.ts +12 -0
- package/lib/group-component/body/TableBodyCellEmpty.js +156 -0
- package/lib/group-component/body/TableBodyRow.d.ts +21 -0
- package/lib/group-component/body/TableBodyRow.js +206 -0
- package/lib/group-component/body/TableBodyRowGroupCell.d.ts +12 -0
- package/lib/group-component/body/TableBodyRowGroupCell.js +575 -0
- package/lib/group-component/components/ControlCheckbox.d.ts +13 -0
- package/lib/group-component/components/ControlCheckbox.js +92 -0
- package/lib/group-component/components/EditForm/EditForm.d.ts +27 -0
- package/lib/group-component/components/EditForm/EditForm.js +404 -0
- package/lib/group-component/components/EditForm/index.d.ts +1 -0
- package/lib/group-component/components/EditForm/index.js +16 -0
- package/lib/group-component/components/InputControl/InputControl.d.ts +27 -0
- package/lib/group-component/components/InputControl/InputControl.js +127 -0
- package/lib/group-component/components/InputControl/index.d.ts +1 -0
- package/lib/group-component/components/InputControl/index.js +16 -0
- package/lib/group-component/components/async-select/index.d.ts +11 -0
- package/lib/group-component/components/async-select/index.js +47 -0
- package/lib/group-component/components/async-table-select/index.d.ts +11 -0
- package/lib/group-component/components/async-table-select/index.js +49 -0
- package/lib/group-component/components/checkbox-control/index.d.ts +13 -0
- package/lib/group-component/components/checkbox-control/index.js +48 -0
- package/lib/group-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/lib/group-component/components/checkbox-filter/CheckboxFilter.js +267 -0
- package/lib/group-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/lib/group-component/components/checkbox-filter/FilterSearch.js +44 -0
- package/lib/group-component/components/command/Command.d.ts +10 -0
- package/lib/group-component/components/command/Command.js +44 -0
- package/lib/group-component/components/number/index.d.ts +12 -0
- package/lib/group-component/components/number/index.js +50 -0
- package/lib/group-component/components/number-range/index.d.ts +13 -0
- package/lib/group-component/components/number-range/index.js +87 -0
- package/lib/group-component/features/operator.d.ts +24 -0
- package/lib/group-component/features/operator.js +67 -0
- package/lib/group-component/footer/TableFooter.d.ts +7 -0
- package/lib/group-component/footer/TableFooter.js +44 -0
- package/lib/group-component/footer/TableFooterCell.d.ts +7 -0
- package/lib/group-component/footer/TableFooterCell.js +75 -0
- package/lib/group-component/footer/TableFooterRow.d.ts +8 -0
- package/lib/group-component/footer/TableFooterRow.js +37 -0
- package/lib/group-component/header/TableHead.d.ts +15 -0
- package/lib/group-component/header/TableHead.js +107 -0
- package/lib/group-component/header/TableHeadCell.d.ts +15 -0
- package/lib/group-component/header/TableHeadCell.js +319 -0
- package/lib/group-component/header/TableHeadCell2.d.ts +17 -0
- package/lib/group-component/header/TableHeadCell2.js +330 -0
- package/lib/group-component/header/TableHeadGroupCell.d.ts +17 -0
- package/lib/group-component/header/TableHeadGroupCell.js +103 -0
- package/lib/group-component/header/TableHeadRow.d.ts +15 -0
- package/lib/group-component/header/TableHeadRow.js +59 -0
- package/lib/group-component/header/renderFilter.d.ts +20 -0
- package/lib/group-component/header/renderFilter.js +301 -0
- package/lib/group-component/hook/convert.d.ts +1 -0
- package/lib/group-component/hook/convert.js +34 -0
- package/lib/group-component/hook/useColumns.d.ts +28 -0
- package/lib/group-component/hook/useColumns.js +318 -0
- package/lib/group-component/hook/useFilterOperator.d.ts +7 -0
- package/lib/group-component/hook/useFilterOperator.js +40 -0
- package/lib/group-component/hook/utils.d.ts +220 -0
- package/lib/group-component/hook/utils.js +2468 -0
- package/lib/group-component/index.d.ts +2 -0
- package/lib/group-component/index.js +9 -0
- package/lib/group-component/style.d.ts +22 -0
- package/lib/group-component/style.js +55 -0
- package/lib/group-component/style.scss +1438 -0
- package/lib/group-component/table/Grid.d.ts +33 -0
- package/lib/group-component/table/Grid.js +443 -0
- package/lib/group-component/table/TableWrapper.d.ts +33 -0
- package/lib/group-component/table/TableWrapper.js +259 -0
- package/lib/group-component/useContext.d.ts +100 -0
- package/lib/group-component/useContext.js +27 -0
- package/lib/table-component/InternalTable.js +6 -1
- package/lib/table-component/TableContainer.js +4 -2
- package/lib/table-component/body/TableBodyCell.js +49 -40
- package/lib/table-component/body/TableBodyRow.js +4 -1
- package/lib/table-component/hook/utils.d.ts +1 -0
- package/lib/table-component/hook/utils.js +16 -7
- package/lib/table-component/style.js +1 -1
- package/lib/table-component/table/Grid.js +3 -0
- package/lib/table-component/useContext.d.ts +5 -0
- package/lib/table-virtuoso/InternalTable.js +2 -2
- package/lib/table-virtuoso/body/TableBodyCell.js +2 -7
- package/lib/table-virtuoso/body/TableBodyCellRowGroup.d.ts +14 -0
- package/lib/table-virtuoso/body/TableBodyCellRowGroup.js +203 -0
- package/lib/table-virtuoso/body/TableBodyRow.d.ts +1 -1
- package/lib/table-virtuoso/body/TableBodyRow.js +43 -1
- package/lib/table-virtuoso/hook/utils.d.ts +1 -0
- package/lib/table-virtuoso/hook/utils.js +32 -1
- package/lib/table-virtuoso/style.js +3 -1
- package/lib/table-virtuoso/table/Grid.js +2 -2
- package/lib/table-virtuoso/table/TableWrapper.d.ts +7 -1
- package/lib/table-virtuoso/table/TableWrapper.js +24 -5
- package/lib/table-virtuoso/useContext.d.ts +6 -3
- package/lib/table-virtuoso/useContext.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,2068 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React, { Fragment } from "react";
|
|
3
|
+
import { useCopyToClipboard } from 'usehooks-ts';
|
|
4
|
+
import { checkDecimalSeparator, checkThousandSeparator, detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween, getDefaultValue, getFormat, getRowIdsBetween, getSelectedCellMatrix, getTableHeight, isEditable, isFormattedNumber, newGuid, parseExcelClipboardText, sumSize,
|
|
5
|
+
// sumSize,
|
|
6
|
+
unFlattenData, updateArrayByKey, updateColumnWidthsRecursive, updateOrInsert } from "./hook/utils";
|
|
7
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
8
|
+
import { useForm } from 'react-hook-form';
|
|
9
|
+
import { Button, Modal, Typography, Dropdown } from "antd";
|
|
10
|
+
import Pagination from "rc-master-ui/es/pagination";
|
|
11
|
+
import { numericFormatter, removeNumericFormat } from "react-numeric-component";
|
|
12
|
+
import { TableContext } from "./useContext";
|
|
13
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
14
|
+
import { Toolbar } from "rc-master-ui";
|
|
15
|
+
import classNames from "classnames";
|
|
16
|
+
import { Collapse2, Expand2, Maximize, Minimize } from "becoxy-icons";
|
|
17
|
+
import { ColumnsChoose } from "./ColumnsChoose";
|
|
18
|
+
import TableWrapper from "./table/TableWrapper";
|
|
19
|
+
import withReactContent from "sweetalert2-react-content";
|
|
20
|
+
import Swal from "sweetalert2";
|
|
21
|
+
import { convertToObjTrue, findAllChildrenKeys2, flatColumns2, isObjEmpty } from "../table-component/hook/utils";
|
|
22
|
+
import { ColumnsGroup } from "./ColumnsGroup";
|
|
23
|
+
import { unGroupData } from "../table-virtuoso/hook/utils";
|
|
24
|
+
const MySwal = withReactContent(Swal);
|
|
25
|
+
const {
|
|
26
|
+
Paragraph,
|
|
27
|
+
Title
|
|
28
|
+
} = Typography;
|
|
29
|
+
const validateData = async (data, formSchema) => {
|
|
30
|
+
if (!formSchema) {
|
|
31
|
+
return [];
|
|
32
|
+
} else {
|
|
33
|
+
const errors = [];
|
|
34
|
+
for (let i = 0; i < data.length; i++) {
|
|
35
|
+
try {
|
|
36
|
+
await formSchema.validate(data[i], {
|
|
37
|
+
abortEarly: false
|
|
38
|
+
});
|
|
39
|
+
} catch (error) {
|
|
40
|
+
errors.push(error.inner.reduce((acc, err) => {
|
|
41
|
+
acc[err.path] = {
|
|
42
|
+
field: err.path,
|
|
43
|
+
index: i,
|
|
44
|
+
message: err.message,
|
|
45
|
+
type: err.type,
|
|
46
|
+
ref: {
|
|
47
|
+
name: err.path
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
...acc,
|
|
52
|
+
index: i,
|
|
53
|
+
id: data[i].rowId
|
|
54
|
+
};
|
|
55
|
+
}, {}));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return errors;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const TableContainerEdit = props => {
|
|
62
|
+
const {
|
|
63
|
+
t,
|
|
64
|
+
table,
|
|
65
|
+
title,
|
|
66
|
+
id,
|
|
67
|
+
prefix,
|
|
68
|
+
commandClick,
|
|
69
|
+
editAble,
|
|
70
|
+
rowEditable,
|
|
71
|
+
rowKey,
|
|
72
|
+
format,
|
|
73
|
+
dataSource,
|
|
74
|
+
originData,
|
|
75
|
+
expandable,
|
|
76
|
+
wrapSettings,
|
|
77
|
+
recordDoubleClick,
|
|
78
|
+
// triggerFilter,
|
|
79
|
+
selectionSettings,
|
|
80
|
+
isSelectionChange,
|
|
81
|
+
setIsSelectionChange,
|
|
82
|
+
// onContextMenu,
|
|
83
|
+
contextMenuItems,
|
|
84
|
+
setSorterChange,
|
|
85
|
+
setFilterChange,
|
|
86
|
+
onCellPaste,
|
|
87
|
+
// triggerPaste,
|
|
88
|
+
validate,
|
|
89
|
+
// triggerChangeData,
|
|
90
|
+
onCellChange,
|
|
91
|
+
onDataChange,
|
|
92
|
+
defaultValue,
|
|
93
|
+
toolbarItems,
|
|
94
|
+
mergedFilterKeys,
|
|
95
|
+
setMergedFilterKeys,
|
|
96
|
+
expanded,
|
|
97
|
+
setExpanded,
|
|
98
|
+
onBlur,
|
|
99
|
+
fullScreen,
|
|
100
|
+
pagination,
|
|
101
|
+
showToolbar,
|
|
102
|
+
actionTemplate,
|
|
103
|
+
showColumnChoose,
|
|
104
|
+
height,
|
|
105
|
+
minHeight,
|
|
106
|
+
summary,
|
|
107
|
+
locale,
|
|
108
|
+
groupColumns,
|
|
109
|
+
groupSetting,
|
|
110
|
+
columns,
|
|
111
|
+
propsColumns,
|
|
112
|
+
triggerChangeColumns,
|
|
113
|
+
columnHidden,
|
|
114
|
+
showEmptyText,
|
|
115
|
+
isFullScreen,
|
|
116
|
+
setIsFullScreen,
|
|
117
|
+
infiniteScroll,
|
|
118
|
+
windowSize,
|
|
119
|
+
next,
|
|
120
|
+
loading,
|
|
121
|
+
contextMenuOpen,
|
|
122
|
+
contextMenuClick,
|
|
123
|
+
contextMenuHidden,
|
|
124
|
+
commandSettings,
|
|
125
|
+
isDataTree,
|
|
126
|
+
onCellClick,
|
|
127
|
+
// setColumnSizing,
|
|
128
|
+
setColumns,
|
|
129
|
+
columnSizing,
|
|
130
|
+
columnSizingInfo,
|
|
131
|
+
rowClassName,
|
|
132
|
+
onRowStyles,
|
|
133
|
+
dataSourceFilter,
|
|
134
|
+
triggerGroupColumns
|
|
135
|
+
} = props;
|
|
136
|
+
const containerRef = React.useRef(null);
|
|
137
|
+
const bottomToolbarRef = React.useRef(null);
|
|
138
|
+
const topToolbarRef = React.useRef(null);
|
|
139
|
+
const childrenColumnName = 'children';
|
|
140
|
+
|
|
141
|
+
// const visibleColumns = table.getVisibleLeafColumns()
|
|
142
|
+
|
|
143
|
+
// //The virtualizers need to know the scrollable container element
|
|
144
|
+
const tableContainerRef = React.useRef(null);
|
|
145
|
+
const [, copy] = useCopyToClipboard();
|
|
146
|
+
|
|
147
|
+
// const columnSizingState = table.getState().columnSizing;
|
|
148
|
+
|
|
149
|
+
const itemsAdd = React.useMemo(() => {
|
|
150
|
+
return [{
|
|
151
|
+
key: '10',
|
|
152
|
+
label: `10 ${t ? t('rows') : 'rows'}`
|
|
153
|
+
}, {
|
|
154
|
+
key: '50',
|
|
155
|
+
label: `50 ${t ? t('rows') : 'rows'}`
|
|
156
|
+
}, {
|
|
157
|
+
key: '100',
|
|
158
|
+
label: `100 ${t ? t('rows') : 'rows'}`
|
|
159
|
+
}];
|
|
160
|
+
}, [t]);
|
|
161
|
+
const [dataErrors, setDataErrors] = React.useState([]);
|
|
162
|
+
React.useEffect(() => {
|
|
163
|
+
if (validate && dataSource && dataSource.length) {
|
|
164
|
+
validateData(dataSource, validate).then(error => {
|
|
165
|
+
setDataErrors([...error]);
|
|
166
|
+
// if (getErrors) {
|
|
167
|
+
// getErrors([...error])
|
|
168
|
+
// }
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}, [validate, dataSource]);
|
|
172
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
173
|
+
// const visibleColumns = table.getVisibleFlatColumns();
|
|
174
|
+
|
|
175
|
+
const fixedLeftColumns = table.getState().columnPinning.left ? visibleColumns.filter(vc => table.getState().columnPinning.left?.includes(vc.id)) : [];
|
|
176
|
+
const fixedRightColumns = table.getState().columnPinning.right ? visibleColumns.filter(vc => table.getState().columnPinning.right?.includes(vc.id)) : [];
|
|
177
|
+
|
|
178
|
+
//we are using a slightly different virtualization strategy for columns (compared to virtual rows) in order to support dynamic row heights
|
|
179
|
+
const columnVirtualizer = useVirtualizer({
|
|
180
|
+
count: visibleColumns.length,
|
|
181
|
+
estimateSize: index => visibleColumns[index].getSize(),
|
|
182
|
+
//estimate width of each column for accurate scrollbar dragging
|
|
183
|
+
getScrollElement: () => tableContainerRef.current,
|
|
184
|
+
horizontal: true,
|
|
185
|
+
// measureElement(element) {
|
|
186
|
+
|
|
187
|
+
// return element?.getBoundingClientRect().width;
|
|
188
|
+
// },
|
|
189
|
+
|
|
190
|
+
measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element?.getBoundingClientRect().height : undefined,
|
|
191
|
+
overscan: 0 //how many columns to render on each side off screen each way (adjust this for performance)
|
|
192
|
+
});
|
|
193
|
+
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
194
|
+
const cacheColumns = columnVirtualizer.measurementsCache;
|
|
195
|
+
const rightCols = table.getState().columnPinning.right?.length ? [...cacheColumns].slice(-(table.getState().columnPinning.right?.length ?? 0)) : [];
|
|
196
|
+
const leftCols = [...cacheColumns].slice(0, table.getState().columnPinning.left?.length ?? 0);
|
|
197
|
+
const rightWidth = sumSize(rightCols);
|
|
198
|
+
const leftWidth = sumSize(leftCols);
|
|
199
|
+
|
|
200
|
+
//different virtualization strategy for columns - instead of absolute and translateY, we add empty columns to the left and right
|
|
201
|
+
let virtualPaddingLeft;
|
|
202
|
+
let virtualPaddingRight;
|
|
203
|
+
const pdRight = columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0);
|
|
204
|
+
if (columnVirtualizer && virtualColumns?.length) {
|
|
205
|
+
virtualPaddingLeft = fixedLeftColumns && fixedLeftColumns.length > 0 ? (virtualColumns[0]?.start ?? 0) - leftWidth > 0 ? (virtualColumns[0]?.start ?? 0) - leftWidth : 0 : virtualColumns[0]?.start ?? 0;
|
|
206
|
+
|
|
207
|
+
// virtualPaddingLeft = leftCols.length === rss.length ? (virtualColumns[0]?.start ?? 0) : 0;
|
|
208
|
+
// columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0) - rightWidth > 0 ? columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0) - rightWidth : 0;
|
|
209
|
+
virtualPaddingRight = fixedRightColumns && fixedRightColumns.length > 0 ? pdRight - rightWidth > 0 ? pdRight - rightWidth : 0 : pdRight;
|
|
210
|
+
// virtualPaddingRight = columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0)
|
|
211
|
+
}
|
|
212
|
+
const [editingKey, setEditingKey] = React.useState('');
|
|
213
|
+
const [rangeState, setRangeState] = React.useState({
|
|
214
|
+
startRowIndex: undefined,
|
|
215
|
+
endRowIndex: undefined,
|
|
216
|
+
startColIndex: undefined,
|
|
217
|
+
endColIndex: undefined,
|
|
218
|
+
rowIds: [],
|
|
219
|
+
colIds: [],
|
|
220
|
+
colRange: [],
|
|
221
|
+
rowRange: []
|
|
222
|
+
});
|
|
223
|
+
const [rangePasteState, setRangePasteState] = React.useState({
|
|
224
|
+
startRowIndex: undefined,
|
|
225
|
+
endRowIndex: undefined,
|
|
226
|
+
startColIndex: undefined,
|
|
227
|
+
endColIndex: undefined,
|
|
228
|
+
rowIds: [],
|
|
229
|
+
colIds: [],
|
|
230
|
+
colRange: [],
|
|
231
|
+
rowRange: []
|
|
232
|
+
});
|
|
233
|
+
const [focusedCell, setFocusedCell] = React.useState(undefined);
|
|
234
|
+
const [startCell, setStartCell] = React.useState(undefined);
|
|
235
|
+
const [endCell, setEndCell] = React.useState(undefined);
|
|
236
|
+
const [startPasteCell, setStartPasteCell] = React.useState(undefined);
|
|
237
|
+
const [endPasteCell, setEndPasteCell] = React.useState(undefined);
|
|
238
|
+
const [isSelecting, setIsSelecting] = React.useState(false);
|
|
239
|
+
const [isPasting, setIsPasting] = React.useState(false);
|
|
240
|
+
// const [isFullScreen] = React.useState(false);
|
|
241
|
+
const [tableHeight, settableHeight] = React.useState(0);
|
|
242
|
+
|
|
243
|
+
// const [isAddNewRow, setIsAddNewRow] = React.useState(false)
|
|
244
|
+
|
|
245
|
+
const rowsFocus = React.useMemo(() => {
|
|
246
|
+
return startCell && endCell ? getRowIdsBetween(table, startCell.rowId, endCell.rowId) : [];
|
|
247
|
+
}, [endCell, startCell, table]);
|
|
248
|
+
const copySelectionToClipboard = React.useCallback(() => {
|
|
249
|
+
if (!startCell || !endCell) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// const allRows = table.getRowModel().rows;
|
|
254
|
+
const allRows = table.getRowModel().flatRows;
|
|
255
|
+
// const allColumns = table.getAllLeafColumns();
|
|
256
|
+
|
|
257
|
+
const rowIds = getRowIdsBetween(table, startCell.rowId, endCell.rowId);
|
|
258
|
+
const colIds = getColIdsBetween(table, startCell.colId, endCell.colId);
|
|
259
|
+
const dataToCopy = [];
|
|
260
|
+
rowIds.forEach(rowId => {
|
|
261
|
+
const row = allRows.find(r => r.id === rowId);
|
|
262
|
+
if (!row) return;
|
|
263
|
+
const rowData = [];
|
|
264
|
+
colIds.forEach(colId => {
|
|
265
|
+
const cellll = row.getVisibleCells().find(c => c.column.id === colId);
|
|
266
|
+
const value = cellll?.getValue();
|
|
267
|
+
rowData.push(value !== undefined ? String(value) : '');
|
|
268
|
+
});
|
|
269
|
+
dataToCopy.push(rowData);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Convert to TSV string
|
|
273
|
+
const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
|
|
274
|
+
|
|
275
|
+
// Copy to clipboard
|
|
276
|
+
// navigator.clipboard.writeText(tsv).then(() => {
|
|
277
|
+
// });
|
|
278
|
+
|
|
279
|
+
copy(tsv).then(() => {}).catch(() => {});
|
|
280
|
+
}, [startCell, endCell, table]);
|
|
281
|
+
const triggerChangeData = React.useCallback(newData => {
|
|
282
|
+
onDataChange?.(newData);
|
|
283
|
+
}, [onDataChange, dataSource]);
|
|
284
|
+
const triggerPaste = React.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
|
|
285
|
+
const handlePasteCallback = callbackData => {
|
|
286
|
+
const rsFilterData = updateOrInsert(flattenArray([...originData]), flattenArray([...callbackData]));
|
|
287
|
+
const rs = unFlattenData(rsFilterData);
|
|
288
|
+
triggerChangeData(rs);
|
|
289
|
+
};
|
|
290
|
+
if (onCellPaste && onCellPaste.onPasted) {
|
|
291
|
+
if (onCellPaste.onPasted.length > 1) {
|
|
292
|
+
// có callback
|
|
293
|
+
onCellPaste.onPasted({
|
|
294
|
+
pasteData: pastedRows,
|
|
295
|
+
copyRows,
|
|
296
|
+
type: 'onPaste',
|
|
297
|
+
data: originData,
|
|
298
|
+
pastedColumns: pastedColumnsArray
|
|
299
|
+
}, handlePasteCallback);
|
|
300
|
+
} else {
|
|
301
|
+
// không có callback
|
|
302
|
+
onCellPaste.onPasted({
|
|
303
|
+
pasteData: pastedRows,
|
|
304
|
+
type: 'onPaste',
|
|
305
|
+
copyRows,
|
|
306
|
+
data: originData,
|
|
307
|
+
pastedColumns: pastedColumnsArray
|
|
308
|
+
}, handlePasteCallback);
|
|
309
|
+
triggerChangeData(newData);
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
triggerChangeData(newData);
|
|
313
|
+
}
|
|
314
|
+
}, [onCellPaste, originData, triggerChangeData]);
|
|
315
|
+
const handlePasted = React.useCallback(pasteData => {
|
|
316
|
+
if (!startCell) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
320
|
+
|
|
321
|
+
// const allRows = table.getRowModel().rows;
|
|
322
|
+
const allRows = table.getRowModel().flatRows;
|
|
323
|
+
const allCols = table.getVisibleLeafColumns();
|
|
324
|
+
const startRowIdx = allRows.findIndex(r => r.id === startCell.rowId);
|
|
325
|
+
const startColIdx = allCols.findIndex(c => c.id === startCell.colId);
|
|
326
|
+
|
|
327
|
+
// const record: any = allRows[startRowIdx].original
|
|
328
|
+
|
|
329
|
+
const record = table.getRow(startCell.rowId).original;
|
|
330
|
+
const row = table.getRow(startCell.rowId);
|
|
331
|
+
if (!row.parentId) {
|
|
332
|
+
// Cập nhật data mới
|
|
333
|
+
const newData = flattenArray([...dataSource]);
|
|
334
|
+
|
|
335
|
+
// Lấy vị trí bắt đầu
|
|
336
|
+
|
|
337
|
+
// const startRow = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
338
|
+
const startRow = startRowIdx;
|
|
339
|
+
const startCol = startColIdx;
|
|
340
|
+
const pastedRows = [];
|
|
341
|
+
const pastedColumns = new Set();
|
|
342
|
+
rows.forEach((rowValues, rowIndex) => {
|
|
343
|
+
const targetRow = startRow + rowIndex;
|
|
344
|
+
|
|
345
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
346
|
+
if (targetRow >= newData.length) {
|
|
347
|
+
newData.push({
|
|
348
|
+
id: undefined,
|
|
349
|
+
rowId: newGuid()
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
rowValues.forEach((cellValue, colIndex) => {
|
|
353
|
+
const targetCol = startCol + colIndex;
|
|
354
|
+
if (targetCol >= allCols.length) {
|
|
355
|
+
// Không vượt quá số cột
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const columnTarget = allCols[targetCol];
|
|
359
|
+
const columnOri = columnTarget.columnDef.meta ?? {};
|
|
360
|
+
const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(newData[targetRow]) : columnOri.editEnable;
|
|
361
|
+
if (isEdit) {
|
|
362
|
+
const columnKey = allCols[targetCol].id;
|
|
363
|
+
|
|
364
|
+
// if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
|
|
365
|
+
if (columnOri.type === 'number') {
|
|
366
|
+
if (cellValue.trim() === '') {
|
|
367
|
+
newData[targetRow] = {
|
|
368
|
+
...newData[targetRow],
|
|
369
|
+
[columnKey]: null
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (isFormattedNumber(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
|
|
373
|
+
const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
|
|
374
|
+
const valuePasteFormat = detectSeparators(cellValue.trim());
|
|
375
|
+
const cellFormat = getFormat(colFormat, format);
|
|
376
|
+
const thousandSeparator = valuePasteFormat?.thousandSeparator;
|
|
377
|
+
const decimalSeparator = valuePasteFormat?.decimalSeparator;
|
|
378
|
+
const dec = cellFormat?.decimalScale;
|
|
379
|
+
const numericFormatProps = {
|
|
380
|
+
thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
|
|
381
|
+
decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
|
|
382
|
+
allowNegative: cellFormat?.allowNegative ?? true,
|
|
383
|
+
prefix: cellFormat?.prefix,
|
|
384
|
+
suffix: cellFormat?.suffix,
|
|
385
|
+
decimalScale: dec,
|
|
386
|
+
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
|
|
387
|
+
};
|
|
388
|
+
const val = removeNumericFormat(cellValue.trim(), undefined, numericFormatProps);
|
|
389
|
+
newData[targetRow] = {
|
|
390
|
+
...newData[targetRow],
|
|
391
|
+
[columnKey]: Number(val)
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
newData[targetRow] = {
|
|
396
|
+
...newData[targetRow],
|
|
397
|
+
[columnKey]: cellValue.trim()
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
pastedColumns.add(columnKey);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// Lưu dòng được paste
|
|
405
|
+
pastedRows.push(newData[targetRow]);
|
|
406
|
+
});
|
|
407
|
+
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
408
|
+
const rsFilterData = updateOrInsert(flattenArray([...originData]), newData);
|
|
409
|
+
const rs = unFlattenData(rsFilterData);
|
|
410
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, rs, []);
|
|
411
|
+
} else {
|
|
412
|
+
// const parent = findItemByKey(dataSource, rowKey as any, record.parentId)
|
|
413
|
+
const parent = row.getParentRow()?.original;
|
|
414
|
+
|
|
415
|
+
// Cập nhật childData mới
|
|
416
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
417
|
+
|
|
418
|
+
// Lấy vị trí bắt đầu
|
|
419
|
+
// const { row: startRow, col: startCol } = selectedCell;
|
|
420
|
+
const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
421
|
+
const startCol = startColIdx;
|
|
422
|
+
const pastedRows = [];
|
|
423
|
+
const pastedColumns = new Set();
|
|
424
|
+
rows.forEach((rowValues, rowIndex) => {
|
|
425
|
+
const targetRow = startRow + rowIndex;
|
|
426
|
+
|
|
427
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
428
|
+
if (targetRow >= childData.length) {
|
|
429
|
+
childData.push({
|
|
430
|
+
id: undefined,
|
|
431
|
+
rowId: newGuid(),
|
|
432
|
+
parentId: parent[rowKey ?? 'id']
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
rowValues.forEach((cellValue, colIndex) => {
|
|
436
|
+
const targetCol = startCol + colIndex;
|
|
437
|
+
if (targetCol >= allCols.length) {
|
|
438
|
+
// Không vượt quá số cột
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const columnTarget = allCols[targetCol];
|
|
442
|
+
|
|
443
|
+
// const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(childData[targetRow]) : columnTarget.editEnable
|
|
444
|
+
|
|
445
|
+
const columnOri = columnTarget.columnDef.meta ?? {};
|
|
446
|
+
const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
|
|
447
|
+
|
|
448
|
+
// if (isEdit) {
|
|
449
|
+
|
|
450
|
+
// const columnKey = allCols[targetCol].id
|
|
451
|
+
|
|
452
|
+
// childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
|
|
453
|
+
|
|
454
|
+
// pastedColumns.add(columnKey)
|
|
455
|
+
// }
|
|
456
|
+
|
|
457
|
+
if (isEdit) {
|
|
458
|
+
const columnKey = allCols[targetCol].id;
|
|
459
|
+
|
|
460
|
+
// if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
|
|
461
|
+
if (columnOri.type === 'number') {
|
|
462
|
+
if (cellValue.trim() === '') {
|
|
463
|
+
childData[targetRow] = {
|
|
464
|
+
...childData[targetRow],
|
|
465
|
+
[columnKey]: null
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
if (isFormattedNumber(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
|
|
469
|
+
const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
|
|
470
|
+
const valuePasteFormat = detectSeparators(cellValue.trim());
|
|
471
|
+
const cellFormat = getFormat(colFormat, format);
|
|
472
|
+
const thousandSeparator = valuePasteFormat?.thousandSeparator;
|
|
473
|
+
const decimalSeparator = valuePasteFormat?.decimalSeparator;
|
|
474
|
+
const dec = cellFormat?.decimalScale;
|
|
475
|
+
const numericFormatProps = {
|
|
476
|
+
thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
|
|
477
|
+
decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
|
|
478
|
+
allowNegative: cellFormat?.allowNegative ?? true,
|
|
479
|
+
prefix: cellFormat?.prefix,
|
|
480
|
+
suffix: cellFormat?.suffix,
|
|
481
|
+
decimalScale: dec,
|
|
482
|
+
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
|
|
483
|
+
};
|
|
484
|
+
const val = removeNumericFormat(cellValue.trim(), undefined, numericFormatProps);
|
|
485
|
+
childData[targetRow] = {
|
|
486
|
+
...childData[targetRow],
|
|
487
|
+
[columnKey]: Number(val)
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
childData[targetRow] = {
|
|
492
|
+
...childData[targetRow],
|
|
493
|
+
[columnKey]: cellValue.trim()
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
pastedColumns.add(columnKey);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// Lưu dòng được paste
|
|
501
|
+
pastedRows.push(childData[targetRow]);
|
|
502
|
+
});
|
|
503
|
+
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
504
|
+
const newRowData = {
|
|
505
|
+
...parent,
|
|
506
|
+
children: childData
|
|
507
|
+
}; // item đã được filter
|
|
508
|
+
|
|
509
|
+
const newDataSource = updateArrayByKey(originData, newRowData, rowKey);
|
|
510
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
|
|
511
|
+
}
|
|
512
|
+
}, [dataSource, format, onCellPaste?.maxRowsPaste, originData, rowKey, startCell, table, triggerPaste]);
|
|
513
|
+
const handlePastedGroup = React.useCallback(pasteData => {
|
|
514
|
+
if (!startCell) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
518
|
+
|
|
519
|
+
// const allRows = table.getRowModel().flatRows;
|
|
520
|
+
const allCols = table.getVisibleLeafColumns();
|
|
521
|
+
|
|
522
|
+
// const startRowIdx = allRows.findIndex(r => r.id === startCell.rowId);
|
|
523
|
+
const startColIdx = allCols.findIndex(c => c.id === startCell.colId);
|
|
524
|
+
|
|
525
|
+
// const record: any = allRows[startRowIdx].original
|
|
526
|
+
|
|
527
|
+
const record = table.getRow(startCell.rowId).original;
|
|
528
|
+
const row = table.getRow(startCell.rowId);
|
|
529
|
+
if (!row.parentId) {
|
|
530
|
+
|
|
531
|
+
// // Cập nhật data mới
|
|
532
|
+
// const newData = flattenArray([...dataSource])
|
|
533
|
+
|
|
534
|
+
// // Lấy vị trí bắt đầu
|
|
535
|
+
|
|
536
|
+
// // const startRow = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
537
|
+
// const startRow = startRowIdx
|
|
538
|
+
|
|
539
|
+
// const startCol = startColIdx
|
|
540
|
+
|
|
541
|
+
// const pastedRows: RecordType[] = []
|
|
542
|
+
// const pastedColumns = new Set()
|
|
543
|
+
|
|
544
|
+
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
545
|
+
// const targetRow = startRow + rowIndex
|
|
546
|
+
|
|
547
|
+
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
548
|
+
// if (targetRow >= newData.length) {
|
|
549
|
+
|
|
550
|
+
// newData.push({ id: undefined, rowId: newGuid() })
|
|
551
|
+
// }
|
|
552
|
+
|
|
553
|
+
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
554
|
+
|
|
555
|
+
// const targetCol = startCol + colIndex
|
|
556
|
+
|
|
557
|
+
// if (targetCol >= allCols.length) { // Không vượt quá số cột
|
|
558
|
+
// return
|
|
559
|
+
// }
|
|
560
|
+
|
|
561
|
+
// const columnTarget = allCols[targetCol]
|
|
562
|
+
|
|
563
|
+
// const columnOri: any = columnTarget.columnDef.meta ?? {}
|
|
564
|
+
|
|
565
|
+
// const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(newData[targetRow]) : columnOri.editEnable
|
|
566
|
+
|
|
567
|
+
// if (isEdit) {
|
|
568
|
+
|
|
569
|
+
// const columnKey = allCols[targetCol].id
|
|
570
|
+
|
|
571
|
+
// // if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
|
|
572
|
+
// if (columnOri.type === 'number') {
|
|
573
|
+
// if (cellValue.trim() === '') {
|
|
574
|
+
// newData[targetRow] = { ...newData[targetRow], [columnKey]: null }
|
|
575
|
+
// }
|
|
576
|
+
|
|
577
|
+
// if (isFormattedNumber(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
|
|
578
|
+
|
|
579
|
+
// const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format
|
|
580
|
+
|
|
581
|
+
// const valuePasteFormat = detectSeparators(cellValue.trim())
|
|
582
|
+
|
|
583
|
+
// const cellFormat = getFormat(colFormat, format)
|
|
584
|
+
// const thousandSeparator = valuePasteFormat?.thousandSeparator
|
|
585
|
+
// const decimalSeparator = valuePasteFormat?.decimalSeparator
|
|
586
|
+
// const dec = cellFormat?.decimalScale
|
|
587
|
+
|
|
588
|
+
// const numericFormatProps = {
|
|
589
|
+
// thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
|
|
590
|
+
// decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
|
|
591
|
+
// allowNegative: (cellFormat?.allowNegative) ?? true,
|
|
592
|
+
// prefix: cellFormat?.prefix,
|
|
593
|
+
// suffix: cellFormat?.suffix,
|
|
594
|
+
// decimalScale: dec,
|
|
595
|
+
// fixedDecimalScale: (cellFormat?.fixedDecimalScale) ?? false
|
|
596
|
+
// }
|
|
597
|
+
|
|
598
|
+
// const val = removeNumericFormat(cellValue.trim(), undefined, numericFormatProps)
|
|
599
|
+
|
|
600
|
+
// newData[targetRow] = { ...newData[targetRow], [columnKey]: Number(val) }
|
|
601
|
+
|
|
602
|
+
// }
|
|
603
|
+
|
|
604
|
+
// } else {
|
|
605
|
+
|
|
606
|
+
// newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() }
|
|
607
|
+
|
|
608
|
+
// }
|
|
609
|
+
|
|
610
|
+
// pastedColumns.add(columnKey)
|
|
611
|
+
|
|
612
|
+
// }
|
|
613
|
+
|
|
614
|
+
// }
|
|
615
|
+
// )
|
|
616
|
+
|
|
617
|
+
// // Lưu dòng được paste
|
|
618
|
+
// pastedRows.push(newData[targetRow])
|
|
619
|
+
|
|
620
|
+
// })
|
|
621
|
+
|
|
622
|
+
// const pastedColumnsArray = Array.from(pastedColumns) ?? []
|
|
623
|
+
|
|
624
|
+
// const rsFilterData = updateOrInsert(flattenArray([...originData]), newData)
|
|
625
|
+
// const rsFilterData1 = updateOrInsert(flattenArray([...dataSource]), newData)
|
|
626
|
+
|
|
627
|
+
// const rs = unFlattenData(rsFilterData)
|
|
628
|
+
|
|
629
|
+
// const dta = unGroupData(rs, originData)
|
|
630
|
+
|
|
631
|
+
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], rs, [])
|
|
632
|
+
} else {
|
|
633
|
+
// const parent = findItemByKey(dataSource, rowKey as any, record.parentId)
|
|
634
|
+
const parent = row.getParentRow()?.original;
|
|
635
|
+
|
|
636
|
+
// Cập nhật childData mới
|
|
637
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
638
|
+
|
|
639
|
+
// Lấy vị trí bắt đầu
|
|
640
|
+
// const { row: startRow, col: startCol } = selectedCell;
|
|
641
|
+
const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
642
|
+
const startCol = startColIdx;
|
|
643
|
+
const pastedRows = [];
|
|
644
|
+
const pastedColumns = new Set();
|
|
645
|
+
rows.forEach((rowValues, rowIndex) => {
|
|
646
|
+
const targetRow = startRow + rowIndex;
|
|
647
|
+
|
|
648
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
649
|
+
if (targetRow >= childData.length) {
|
|
650
|
+
childData.push({
|
|
651
|
+
id: undefined,
|
|
652
|
+
rowId: newGuid(),
|
|
653
|
+
parentId: parent[rowKey ?? 'id']
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
rowValues.forEach((cellValue, colIndex) => {
|
|
657
|
+
const targetCol = startCol + colIndex;
|
|
658
|
+
if (targetCol >= allCols.length) {
|
|
659
|
+
// Không vượt quá số cột
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const columnTarget = allCols[targetCol];
|
|
663
|
+
|
|
664
|
+
// const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(childData[targetRow]) : columnTarget.editEnable
|
|
665
|
+
|
|
666
|
+
const columnOri = columnTarget.columnDef.meta ?? {};
|
|
667
|
+
const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
|
|
668
|
+
|
|
669
|
+
// if (isEdit) {
|
|
670
|
+
|
|
671
|
+
// const columnKey = allCols[targetCol].id
|
|
672
|
+
|
|
673
|
+
// childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
|
|
674
|
+
|
|
675
|
+
// pastedColumns.add(columnKey)
|
|
676
|
+
// }
|
|
677
|
+
|
|
678
|
+
if (isEdit) {
|
|
679
|
+
const columnKey = allCols[targetCol].id;
|
|
680
|
+
|
|
681
|
+
// if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
|
|
682
|
+
if (columnOri.type === 'number') {
|
|
683
|
+
if (cellValue.trim() === '') {
|
|
684
|
+
childData[targetRow] = {
|
|
685
|
+
...childData[targetRow],
|
|
686
|
+
[columnKey]: null
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
if (isFormattedNumber(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
|
|
690
|
+
const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
|
|
691
|
+
const valuePasteFormat = detectSeparators(cellValue.trim());
|
|
692
|
+
const cellFormat = getFormat(colFormat, format);
|
|
693
|
+
const thousandSeparator = valuePasteFormat?.thousandSeparator;
|
|
694
|
+
const decimalSeparator = valuePasteFormat?.decimalSeparator;
|
|
695
|
+
const dec = cellFormat?.decimalScale;
|
|
696
|
+
const numericFormatProps = {
|
|
697
|
+
thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
|
|
698
|
+
decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
|
|
699
|
+
allowNegative: cellFormat?.allowNegative ?? true,
|
|
700
|
+
prefix: cellFormat?.prefix,
|
|
701
|
+
suffix: cellFormat?.suffix,
|
|
702
|
+
decimalScale: dec,
|
|
703
|
+
fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
|
|
704
|
+
};
|
|
705
|
+
const val = removeNumericFormat(cellValue.trim(), undefined, numericFormatProps);
|
|
706
|
+
childData[targetRow] = {
|
|
707
|
+
...childData[targetRow],
|
|
708
|
+
[columnKey]: Number(val)
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
} else {
|
|
712
|
+
childData[targetRow] = {
|
|
713
|
+
...childData[targetRow],
|
|
714
|
+
[columnKey]: cellValue.trim()
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
pastedColumns.add(columnKey);
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
// Lưu dòng được paste
|
|
722
|
+
pastedRows.push(childData[targetRow]);
|
|
723
|
+
});
|
|
724
|
+
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
725
|
+
const newRowData = {
|
|
726
|
+
...parent,
|
|
727
|
+
children: childData
|
|
728
|
+
}; // item đã được filter
|
|
729
|
+
|
|
730
|
+
// const newDataSource = updateArrayByKey(originData, newRowData, rowKey as string)
|
|
731
|
+
const newDataSource = updateArrayByKey(dataSource, newRowData, rowKey);
|
|
732
|
+
const dta = unGroupData(newDataSource, originData);
|
|
733
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, dta, []);
|
|
734
|
+
}
|
|
735
|
+
}, [dataSource, format, onCellPaste?.maxRowsPaste, originData, rowKey, startCell, table, triggerPaste]);
|
|
736
|
+
const handlePasteToTable = React.useCallback(pasteData => {
|
|
737
|
+
if (!startCell) return;
|
|
738
|
+
|
|
739
|
+
// const pastedRows = pasted.trim().split('\n').map(row => row.split('\t'));
|
|
740
|
+
|
|
741
|
+
// const clipboardText = e.clipboardData?.getData('text/plain') ?? '';
|
|
742
|
+
|
|
743
|
+
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
744
|
+
// const rowsPasted = pasteData.split("\n").filter((row: any) => row !== '').map((row: any) =>
|
|
745
|
+
// row.replace(/\r/g, "").split("\t")
|
|
746
|
+
|
|
747
|
+
// )
|
|
748
|
+
|
|
749
|
+
// const rowsPasted = parseExcelText(pasteData)
|
|
750
|
+
const rowsPasted = parseExcelClipboardText(pasteData);
|
|
751
|
+
if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
|
|
752
|
+
// bật popup thông báo
|
|
753
|
+
|
|
754
|
+
Modal.confirm({
|
|
755
|
+
content: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Paragraph, {
|
|
756
|
+
style: {
|
|
757
|
+
marginBottom: '.25rem',
|
|
758
|
+
fontSize: 14
|
|
759
|
+
}
|
|
760
|
+
}, "D\u1EEF li\u1EC7u sao ch\xE9p v\u01B0\u1EE3t qu\xE1 s\u1ED1 d\xF2ng cho ph\xE9p (", onCellPaste?.maxRowsPaste ?? 200, " d\xF2ng).Ph\u1EA7n m\u1EC1n s\u1EBD ch\u1EC9 l\u1EA5y (", onCellPaste?.maxRowsPaste ?? 200, " d\xF2ng \u0111\u1EA7u ti\xEAn."), /*#__PURE__*/React.createElement(Title, {
|
|
761
|
+
level: 5,
|
|
762
|
+
style: {
|
|
763
|
+
marginTop: '.75rem'
|
|
764
|
+
}
|
|
765
|
+
}, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
|
|
766
|
+
centered: true,
|
|
767
|
+
className: 'be-popup-container',
|
|
768
|
+
onOk: () => {
|
|
769
|
+
if (groupColumns && groupColumns.length > 0) {
|
|
770
|
+
handlePastedGroup(rowsPasted);
|
|
771
|
+
} else {
|
|
772
|
+
handlePasted(rowsPasted);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
// footer: (_, { OkBtn, CancelBtn }) => (
|
|
776
|
+
// <>
|
|
777
|
+
// <OkBtn />
|
|
778
|
+
// <CancelBtn />
|
|
779
|
+
// </>
|
|
780
|
+
// ),
|
|
781
|
+
});
|
|
782
|
+
} else {
|
|
783
|
+
if (groupColumns && groupColumns.length > 0) {
|
|
784
|
+
handlePastedGroup(rowsPasted);
|
|
785
|
+
} else {
|
|
786
|
+
handlePasted(rowsPasted);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}, [handlePasted, onCellPaste?.maxRowsPaste, startCell, handlePastedGroup, groupColumns]);
|
|
790
|
+
React.useEffect(() => {
|
|
791
|
+
const handleKeyDown = e => {
|
|
792
|
+
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
|
|
793
|
+
e.preventDefault();
|
|
794
|
+
copySelectionToClipboard();
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
798
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
799
|
+
}, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
|
|
800
|
+
React.useEffect(() => {
|
|
801
|
+
const handlePaste = e => {
|
|
802
|
+
if (startCell && !editingKey) {
|
|
803
|
+
e.preventDefault(); // Chặn hành vi mặc định
|
|
804
|
+
const clipboardText = e.clipboardData?.getData('text/plain') ?? '';
|
|
805
|
+
handlePasteToTable(clipboardText);
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
window.addEventListener('paste', handlePaste);
|
|
809
|
+
return () => window.removeEventListener('paste', handlePaste);
|
|
810
|
+
}, [startCell, endCell, table, handlePasteToTable, editingKey]);
|
|
811
|
+
React.useEffect(() => {
|
|
812
|
+
const handleClickOutside = event => {
|
|
813
|
+
const element = event.target;
|
|
814
|
+
const container = document.querySelector(".be-popup-container");
|
|
815
|
+
const containerContextMenu = document.querySelector(".popup-context-menu");
|
|
816
|
+
const tableBody = document.querySelector(`#${id} .ui-rc-grid-tbody`);
|
|
817
|
+
const itemContainer = document.querySelector(`#${id} .ui-rc-toolbar-selection-overflow-item`);
|
|
818
|
+
const itemHeader = document.querySelector(`#${id} .ui-rc-table-thead`);
|
|
819
|
+
const isInsideContainer = element.closest(".be-popup-container") && container;
|
|
820
|
+
const isInsideContainerContext = containerContextMenu && element.closest(".popup-context-menu");
|
|
821
|
+
const isInsideToolbar = element.closest(`.ui-rc-toolbar-selection-overflow-item`) && itemContainer;
|
|
822
|
+
const isInsideHeader = itemHeader && itemHeader.contains(event.target);
|
|
823
|
+
if (isInsideContainer || isInsideToolbar || isInsideHeader || isInsideContainerContext || element.id === id) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
if (containerRef.current && tableBody && !tableBody.contains(event.target)) {
|
|
827
|
+
if (editingKey) {
|
|
828
|
+
onBlur?.(dataSource);
|
|
829
|
+
}
|
|
830
|
+
setTimeout(() => {
|
|
831
|
+
setEditingKey('');
|
|
832
|
+
// editingKey.current = ''
|
|
833
|
+
});
|
|
834
|
+
setEndCell(undefined);
|
|
835
|
+
setStartCell(undefined);
|
|
836
|
+
setRangeState(undefined);
|
|
837
|
+
setFocusedCell(undefined);
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
// document.addEventListener('click', handleClickOutside)
|
|
842
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
843
|
+
// document.addEventListener('touchstart', handleClickOutside)
|
|
844
|
+
|
|
845
|
+
return () => {
|
|
846
|
+
// document.removeEventListener('click', handleClickOutside)
|
|
847
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
848
|
+
// document.removeEventListener('touchstart', handleClickOutside)
|
|
849
|
+
};
|
|
850
|
+
}, [dataSource, editingKey, id, onBlur]);
|
|
851
|
+
const columnSizingState = table.getState().columnSizing;
|
|
852
|
+
React.useEffect(() => {
|
|
853
|
+
requestAnimationFrame(() => {
|
|
854
|
+
columnVirtualizer.measure();
|
|
855
|
+
});
|
|
856
|
+
}, [columnSizingState, columnVirtualizer]);
|
|
857
|
+
React.useEffect(() => {
|
|
858
|
+
if (!tableContainerRef.current) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
if (columnSizingInfo.isResizingColumn === false) {
|
|
862
|
+
const aa = updateColumnWidthsRecursive(propsColumns, columnSizing);
|
|
863
|
+
setColumns(aa);
|
|
864
|
+
}
|
|
865
|
+
}, [columnSizingInfo]);
|
|
866
|
+
React.useEffect(() => {
|
|
867
|
+
// const totalHeight = minHeight ?? height
|
|
868
|
+
const totalHeight = getTableHeight(height, minHeight);
|
|
869
|
+
if (totalHeight) {
|
|
870
|
+
const topHeight = topToolbarRef.current ? topToolbarRef.current.offsetHeight : 0;
|
|
871
|
+
const bottomHeight = bottomToolbarRef.current ? bottomToolbarRef.current.offsetHeight : 0;
|
|
872
|
+
settableHeight(totalHeight - topHeight - bottomHeight);
|
|
873
|
+
}
|
|
874
|
+
}, [id, height, editAble, minHeight, toolbarItems]);
|
|
875
|
+
const {
|
|
876
|
+
control,
|
|
877
|
+
handleSubmit,
|
|
878
|
+
setValue,
|
|
879
|
+
// trigger,
|
|
880
|
+
getValues,
|
|
881
|
+
reset,
|
|
882
|
+
formState: {
|
|
883
|
+
errors
|
|
884
|
+
}
|
|
885
|
+
} = useForm({
|
|
886
|
+
mode: 'onChange',
|
|
887
|
+
resolver: validate ? yupResolver(validate) : undefined
|
|
888
|
+
});
|
|
889
|
+
const handleAddMulti = React.useCallback((item, n, newId) => {
|
|
890
|
+
if (item.onClick) {
|
|
891
|
+
item.onClick({
|
|
892
|
+
toolbar: item
|
|
893
|
+
});
|
|
894
|
+
} else {
|
|
895
|
+
const defaultRowValue = getDefaultValue(defaultValue);
|
|
896
|
+
const newRows = Array.from({
|
|
897
|
+
length: n
|
|
898
|
+
}).map(() => defaultRowValue ? {
|
|
899
|
+
...defaultRowValue,
|
|
900
|
+
id: undefined,
|
|
901
|
+
rowId: n === 1 && newId ? newId : newGuid()
|
|
902
|
+
} : {
|
|
903
|
+
id: undefined,
|
|
904
|
+
rowId: n === 1 && newId ? newId : newGuid()
|
|
905
|
+
});
|
|
906
|
+
const kkk = getAllRowKey(newRows) ?? [];
|
|
907
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
908
|
+
setMergedFilterKeys?.(rs);
|
|
909
|
+
const newData = dataSource.concat(newRows);
|
|
910
|
+
triggerChangeData?.(newData);
|
|
911
|
+
}
|
|
912
|
+
}, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
|
|
913
|
+
const onSubmit = formData => {
|
|
914
|
+
try {
|
|
915
|
+
// const record = (await form.validateFields()) as RecordType;
|
|
916
|
+
const row = {
|
|
917
|
+
...formData
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
// const newData = [...dataSource]
|
|
921
|
+
const newData = [...originData];
|
|
922
|
+
|
|
923
|
+
// @ts-ignore
|
|
924
|
+
const index = flattenData(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
|
|
925
|
+
const rs = updateArrayByKey(newData, row, rowKey);
|
|
926
|
+
if (index > -1) {
|
|
927
|
+
triggerChangeData?.(rs);
|
|
928
|
+
}
|
|
929
|
+
} catch (errInfo) {
|
|
930
|
+
console.log('Validate Failed:', errInfo);
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
const onSubmit2 = (formData, newOriginData) => {
|
|
934
|
+
try {
|
|
935
|
+
// const record = (await form.validateFields()) as RecordType;
|
|
936
|
+
const row = {
|
|
937
|
+
...formData
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
// const newData = [...dataSource]
|
|
941
|
+
const newData = [...newOriginData];
|
|
942
|
+
|
|
943
|
+
// @ts-ignore
|
|
944
|
+
const index = flattenData(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
|
|
945
|
+
const rs = updateArrayByKey(newData, row, rowKey);
|
|
946
|
+
if (index > -1) {
|
|
947
|
+
triggerChangeData?.(rs);
|
|
948
|
+
}
|
|
949
|
+
} catch (errInfo) {
|
|
950
|
+
console.log('Validate Failed:', errInfo);
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
const handleCellChange = args => {
|
|
954
|
+
const {
|
|
955
|
+
record,
|
|
956
|
+
type: changeType,
|
|
957
|
+
newState,
|
|
958
|
+
prevState,
|
|
959
|
+
option,
|
|
960
|
+
field,
|
|
961
|
+
indexCol,
|
|
962
|
+
indexRow,
|
|
963
|
+
key
|
|
964
|
+
} = args;
|
|
965
|
+
if (changeType === 'blur') {
|
|
966
|
+
const handleChangeCallback = callbackData => {
|
|
967
|
+
const callbackRecord = callbackData;
|
|
968
|
+
Object.entries(callbackRecord).forEach(([name, value]) => {
|
|
969
|
+
setValue(name, value);
|
|
970
|
+
});
|
|
971
|
+
onSubmit(callbackRecord);
|
|
972
|
+
};
|
|
973
|
+
if (onCellChange) {
|
|
974
|
+
if (onCellChange.length > 1) {
|
|
975
|
+
onCellChange({
|
|
976
|
+
field,
|
|
977
|
+
indexCol,
|
|
978
|
+
type: 'onChange',
|
|
979
|
+
value: newState,
|
|
980
|
+
option,
|
|
981
|
+
indexRow,
|
|
982
|
+
rowData: record,
|
|
983
|
+
rowId: key,
|
|
984
|
+
// rowsData: [...dataSource],
|
|
985
|
+
rowsData: [...originData],
|
|
986
|
+
sumValue: []
|
|
987
|
+
}, handleChangeCallback);
|
|
988
|
+
} else {
|
|
989
|
+
onCellChange({
|
|
990
|
+
field,
|
|
991
|
+
indexCol,
|
|
992
|
+
type: 'onChange',
|
|
993
|
+
option,
|
|
994
|
+
value: newState,
|
|
995
|
+
indexRow,
|
|
996
|
+
rowData: record,
|
|
997
|
+
rowId: key,
|
|
998
|
+
// rowsData: [...dataSource],
|
|
999
|
+
rowsData: [...originData],
|
|
1000
|
+
sumValue: []
|
|
1001
|
+
}, handleChangeCallback);
|
|
1002
|
+
onSubmit(record);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
if (prevState && newState && prevState !== newState && changeType === 'enter') {
|
|
1007
|
+
onSubmit(record);
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
const handleCellChangeAndAddRow = args => {
|
|
1011
|
+
const {
|
|
1012
|
+
record,
|
|
1013
|
+
type: changeType,
|
|
1014
|
+
newState,
|
|
1015
|
+
option,
|
|
1016
|
+
field,
|
|
1017
|
+
indexCol,
|
|
1018
|
+
indexRow,
|
|
1019
|
+
key
|
|
1020
|
+
} = args;
|
|
1021
|
+
|
|
1022
|
+
// add new row
|
|
1023
|
+
|
|
1024
|
+
const defaultRowValue = getDefaultValue(defaultValue);
|
|
1025
|
+
const newRowId = newGuid();
|
|
1026
|
+
const newRows = Array.from({
|
|
1027
|
+
length: 1
|
|
1028
|
+
}).map(() => defaultRowValue ? {
|
|
1029
|
+
...defaultRowValue,
|
|
1030
|
+
id: undefined,
|
|
1031
|
+
rowId: newRowId
|
|
1032
|
+
} : {
|
|
1033
|
+
id: undefined,
|
|
1034
|
+
rowId: newRowId
|
|
1035
|
+
});
|
|
1036
|
+
const kkk = getAllRowKey(newRows) ?? [];
|
|
1037
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
1038
|
+
setMergedFilterKeys?.(rs);
|
|
1039
|
+
const newData = originData.concat(newRows);
|
|
1040
|
+
setFocusedCell?.({
|
|
1041
|
+
rowId: newRowId,
|
|
1042
|
+
colId: field
|
|
1043
|
+
});
|
|
1044
|
+
setStartCell?.({
|
|
1045
|
+
rowId: newRowId,
|
|
1046
|
+
colId: field
|
|
1047
|
+
});
|
|
1048
|
+
setEndCell?.({
|
|
1049
|
+
rowId: newRowId,
|
|
1050
|
+
colId: field
|
|
1051
|
+
});
|
|
1052
|
+
setTimeout(() => {
|
|
1053
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
1054
|
+
rowId: newRowId,
|
|
1055
|
+
colId: field
|
|
1056
|
+
}, {
|
|
1057
|
+
rowId: newRowId,
|
|
1058
|
+
colId: field
|
|
1059
|
+
}));
|
|
1060
|
+
});
|
|
1061
|
+
setTimeout(() => {
|
|
1062
|
+
const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
|
|
1063
|
+
const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
|
|
1064
|
+
if (cellFocus) {
|
|
1065
|
+
cellFocus.scrollIntoView({
|
|
1066
|
+
behavior: "smooth",
|
|
1067
|
+
block: "start"
|
|
1068
|
+
});
|
|
1069
|
+
cellFocus.focus();
|
|
1070
|
+
}
|
|
1071
|
+
}, 100);
|
|
1072
|
+
if (changeType === 'blur') {
|
|
1073
|
+
const handleChangeCallback = callbackData => {
|
|
1074
|
+
const callbackRecord = callbackData;
|
|
1075
|
+
onSubmit2(callbackRecord, [...newData]);
|
|
1076
|
+
};
|
|
1077
|
+
if (onCellChange) {
|
|
1078
|
+
if (onCellChange.length > 1) {
|
|
1079
|
+
onCellChange({
|
|
1080
|
+
field,
|
|
1081
|
+
indexCol,
|
|
1082
|
+
type: 'onChange',
|
|
1083
|
+
value: newState,
|
|
1084
|
+
option,
|
|
1085
|
+
indexRow,
|
|
1086
|
+
rowData: record,
|
|
1087
|
+
rowId: key,
|
|
1088
|
+
rowsData: [...newData],
|
|
1089
|
+
sumValue: []
|
|
1090
|
+
}, handleChangeCallback);
|
|
1091
|
+
} else {
|
|
1092
|
+
onCellChange({
|
|
1093
|
+
field,
|
|
1094
|
+
indexCol,
|
|
1095
|
+
type: 'onChange',
|
|
1096
|
+
option,
|
|
1097
|
+
value: newState,
|
|
1098
|
+
indexRow,
|
|
1099
|
+
rowData: record,
|
|
1100
|
+
rowId: key,
|
|
1101
|
+
rowsData: [...newData],
|
|
1102
|
+
sumValue: []
|
|
1103
|
+
}, handleChangeCallback);
|
|
1104
|
+
onSubmit2(record, [...newData]);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// if (prevState && newState && prevState !== newState && changeType === 'enter') {
|
|
1110
|
+
|
|
1111
|
+
// onSubmit(record)
|
|
1112
|
+
|
|
1113
|
+
// }
|
|
1114
|
+
};
|
|
1115
|
+
const handleDuplicate = React.useCallback(() => {
|
|
1116
|
+
// không tính tree
|
|
1117
|
+
|
|
1118
|
+
// Cập nhật data mới
|
|
1119
|
+
const newData = flattenArray([...dataSource]);
|
|
1120
|
+
|
|
1121
|
+
// const duplicatedItems = rowsFocus.map(index => ({ ...newData[index], rowId: newGuid(), id: undefined, isDuplicate: true }))
|
|
1122
|
+
|
|
1123
|
+
const duplicatedItem = table.getRowModel().flatRows.find(it => it.id === focusedCell?.rowId);
|
|
1124
|
+
|
|
1125
|
+
// setStartCell(focusedCell)
|
|
1126
|
+
// setEndCell(focusedCell)
|
|
1127
|
+
|
|
1128
|
+
// setRangeState(getSelectedCellMatrix(table, focusedCell, focusedCell))
|
|
1129
|
+
|
|
1130
|
+
const duplicatedItems = [{
|
|
1131
|
+
...duplicatedItem?.original,
|
|
1132
|
+
rowId: newGuid(),
|
|
1133
|
+
id: undefined,
|
|
1134
|
+
isDuplicate: true
|
|
1135
|
+
}];
|
|
1136
|
+
|
|
1137
|
+
// Vị trí chèn là ngay sau phần tử lớn nhất trong rowsFocus
|
|
1138
|
+
|
|
1139
|
+
// const insertAfter = Math.max(...rowsFocus)
|
|
1140
|
+
const insertAfter = newData.findIndex(it => it[rowKey] === focusedCell?.rowId);
|
|
1141
|
+
const rsFilter = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
|
|
1142
|
+
|
|
1143
|
+
// const rs = updateOrInsertInOrder(originData, rsFilter)
|
|
1144
|
+
const rs = updateOrInsert(originData, rsFilter);
|
|
1145
|
+
// const rs2 = mergeWithFilter(originData, rsFilter)
|
|
1146
|
+
|
|
1147
|
+
triggerChangeData?.(rs);
|
|
1148
|
+
}, [dataSource, focusedCell, originData, rowKey, table, triggerChangeData]);
|
|
1149
|
+
|
|
1150
|
+
// thêm n dòng bên trên
|
|
1151
|
+
const handleInsertBefore = React.useCallback((item, n) => {
|
|
1152
|
+
const defaultRowValue = getDefaultValue(defaultValue);
|
|
1153
|
+
setStartCell(focusedCell);
|
|
1154
|
+
setEndCell(focusedCell);
|
|
1155
|
+
setRangeState(getSelectedCellMatrix(table, focusedCell, focusedCell));
|
|
1156
|
+
|
|
1157
|
+
// const record: any = table.getRowModel().rows.find((it) => it.id === rowsFocus[rowsFocus.length - 1])?.original
|
|
1158
|
+
const record = table.getRowModel().flatRows.find(it => it.id === rowsFocus[rowsFocus.length - 1])?.original;
|
|
1159
|
+
if (item.onClick) {
|
|
1160
|
+
item.onClick({
|
|
1161
|
+
toolbar: item
|
|
1162
|
+
});
|
|
1163
|
+
} else {
|
|
1164
|
+
if (!record?.parentId) {
|
|
1165
|
+
// Cập nhật data mới
|
|
1166
|
+
|
|
1167
|
+
const newData = [...originData];
|
|
1168
|
+
const newRows = Array.from({
|
|
1169
|
+
length: n
|
|
1170
|
+
}).map(() => defaultRowValue ? {
|
|
1171
|
+
...defaultRowValue,
|
|
1172
|
+
id: undefined,
|
|
1173
|
+
rowId: newGuid()
|
|
1174
|
+
} : {
|
|
1175
|
+
id: undefined,
|
|
1176
|
+
rowId: newGuid()
|
|
1177
|
+
});
|
|
1178
|
+
const kkk = getAllRowKey(newRows) ?? [];
|
|
1179
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
1180
|
+
setMergedFilterKeys?.(rs);
|
|
1181
|
+
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
1182
|
+
newData.splice(index, 0, ...newRows);
|
|
1183
|
+
triggerChangeData?.(newData);
|
|
1184
|
+
} else {
|
|
1185
|
+
const newData = [...originData];
|
|
1186
|
+
const parent = findItemByKey(newData, rowKey, record.parentId);
|
|
1187
|
+
const newRows = Array.from({
|
|
1188
|
+
length: n
|
|
1189
|
+
}).map(() => defaultRowValue ? {
|
|
1190
|
+
...defaultRowValue,
|
|
1191
|
+
id: undefined,
|
|
1192
|
+
rowId: newGuid(),
|
|
1193
|
+
parentId: parent.rowId
|
|
1194
|
+
} : {
|
|
1195
|
+
id: undefined,
|
|
1196
|
+
rowId: newGuid(),
|
|
1197
|
+
parentId: parent.rowId
|
|
1198
|
+
});
|
|
1199
|
+
|
|
1200
|
+
// Cập nhật childData mới
|
|
1201
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
1202
|
+
const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
1203
|
+
childData.splice(index, 0, ...newRows);
|
|
1204
|
+
const newRowData = {
|
|
1205
|
+
...parent,
|
|
1206
|
+
children: childData
|
|
1207
|
+
};
|
|
1208
|
+
const newDataSource = updateArrayByKey(newData, newRowData, rowKey);
|
|
1209
|
+
triggerChangeData?.(newDataSource);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}, [defaultValue, focusedCell, mergedFilterKeys, originData, rowKey, rowsFocus, setMergedFilterKeys, table, triggerChangeData]);
|
|
1213
|
+
|
|
1214
|
+
//thêm 1 dòng bên dưới
|
|
1215
|
+
const handleInsertAfter = React.useCallback((item, n) => {
|
|
1216
|
+
const defaultRowValue = getDefaultValue(defaultValue);
|
|
1217
|
+
|
|
1218
|
+
// const insertAfter = Math.max(...rowsFocus)
|
|
1219
|
+
|
|
1220
|
+
// const record: RecordType = flattenData(childrenColumnName, dataSource)[insertAfter]
|
|
1221
|
+
|
|
1222
|
+
// const record: any = table.getRowModel().rows.find((it) => it.id === focusedCell?.rowId)?.original
|
|
1223
|
+
const record = table.getRowModel().flatRows.find(it => it.id === focusedCell?.rowId)?.original;
|
|
1224
|
+
if (item.onClick) {
|
|
1225
|
+
item.onClick({
|
|
1226
|
+
toolbar: item
|
|
1227
|
+
});
|
|
1228
|
+
} else {
|
|
1229
|
+
if (!record?.parentId) {
|
|
1230
|
+
// Cập nhật data mới
|
|
1231
|
+
const newData = [...originData];
|
|
1232
|
+
const newRows = Array.from({
|
|
1233
|
+
length: n
|
|
1234
|
+
}).map(() => defaultRowValue ? {
|
|
1235
|
+
...defaultRowValue,
|
|
1236
|
+
id: undefined,
|
|
1237
|
+
rowId: newGuid()
|
|
1238
|
+
} : {
|
|
1239
|
+
id: undefined,
|
|
1240
|
+
rowId: newGuid()
|
|
1241
|
+
});
|
|
1242
|
+
const kkk = getAllRowKey(newRows) ?? [];
|
|
1243
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
1244
|
+
setMergedFilterKeys?.(rs);
|
|
1245
|
+
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
1246
|
+
newData.splice(index + 1, 0, ...newRows);
|
|
1247
|
+
triggerChangeData?.(newData);
|
|
1248
|
+
} else {
|
|
1249
|
+
const newData = [...originData];
|
|
1250
|
+
const parent = findItemByKey(newData, rowKey, record.parentId);
|
|
1251
|
+
const newRows = Array.from({
|
|
1252
|
+
length: n
|
|
1253
|
+
}).map(() => defaultRowValue ? {
|
|
1254
|
+
...defaultRowValue,
|
|
1255
|
+
id: undefined,
|
|
1256
|
+
rowId: newGuid(),
|
|
1257
|
+
parentId: parent.rowId
|
|
1258
|
+
} : {
|
|
1259
|
+
id: undefined,
|
|
1260
|
+
rowId: newGuid(),
|
|
1261
|
+
parentId: parent.rowId
|
|
1262
|
+
});
|
|
1263
|
+
const kkk = getAllRowKey(newRows) ?? [];
|
|
1264
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
1265
|
+
setMergedFilterKeys?.(rs);
|
|
1266
|
+
|
|
1267
|
+
// Cập nhật childData mới
|
|
1268
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
1269
|
+
const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
1270
|
+
childData.splice(index + 1, 0, ...newRows);
|
|
1271
|
+
const newRowData = {
|
|
1272
|
+
...parent,
|
|
1273
|
+
children: childData
|
|
1274
|
+
};
|
|
1275
|
+
const newDataSource = updateArrayByKey(newData, newRowData, rowKey);
|
|
1276
|
+
triggerChangeData?.(newDataSource);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
}, [defaultValue, table, focusedCell?.rowId, originData, mergedFilterKeys, setMergedFilterKeys, triggerChangeData, rowKey]);
|
|
1280
|
+
const handleInsertChild = React.useCallback(item => {
|
|
1281
|
+
const defaultRowValue = getDefaultValue(defaultValue);
|
|
1282
|
+
const rowId = newGuid();
|
|
1283
|
+
const record = table.getRowModel().rows.find(it => it.id === focusedCell?.rowId)?.original;
|
|
1284
|
+
if (item.onClick) {
|
|
1285
|
+
item.onClick({
|
|
1286
|
+
toolbar: item
|
|
1287
|
+
});
|
|
1288
|
+
} else {
|
|
1289
|
+
// const newData = [...dataSource]
|
|
1290
|
+
const newData = [...originData];
|
|
1291
|
+
let newElement;
|
|
1292
|
+
if (!record?.children || record?.children && record.children.length === 0) {
|
|
1293
|
+
newElement = {
|
|
1294
|
+
...record,
|
|
1295
|
+
children: [{
|
|
1296
|
+
...defaultRowValue,
|
|
1297
|
+
parentId: record?.rowId,
|
|
1298
|
+
rowId
|
|
1299
|
+
}]
|
|
1300
|
+
};
|
|
1301
|
+
} else {
|
|
1302
|
+
newElement = {
|
|
1303
|
+
...record,
|
|
1304
|
+
children: [...record.children, {
|
|
1305
|
+
...defaultRowValue,
|
|
1306
|
+
parentId: record.rowId,
|
|
1307
|
+
rowId
|
|
1308
|
+
}]
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1311
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, rowId] : [rowId];
|
|
1312
|
+
setMergedFilterKeys?.(rs);
|
|
1313
|
+
const newDataSource = updateArrayByKey(newData, newElement, rowKey);
|
|
1314
|
+
triggerChangeData?.(newDataSource);
|
|
1315
|
+
}
|
|
1316
|
+
setTimeout(() => {
|
|
1317
|
+
const row = table.getRowModel().rows.find(it => it.id === focusedCell?.rowId);
|
|
1318
|
+
if (row) {
|
|
1319
|
+
setExpanded(old => ({
|
|
1320
|
+
...old,
|
|
1321
|
+
[row.id]: true
|
|
1322
|
+
}));
|
|
1323
|
+
}
|
|
1324
|
+
}, 10);
|
|
1325
|
+
|
|
1326
|
+
// const hasKey = mergedExpandedKeys.has(key)
|
|
1327
|
+
// if (!hasKey) {
|
|
1328
|
+
// const newExpandedKeys = [...mergedExpandedKeys, key]
|
|
1329
|
+
// setInnerExpandedKeys(newExpandedKeys)
|
|
1330
|
+
// }
|
|
1331
|
+
}, [defaultValue, focusedCell?.rowId, mergedFilterKeys, originData, rowKey, setExpanded, setMergedFilterKeys, table, triggerChangeData]);
|
|
1332
|
+
const handleDeleteRows = React.useCallback(item => {
|
|
1333
|
+
if (item.onClick) {
|
|
1334
|
+
item.onClick({
|
|
1335
|
+
toolbar: item
|
|
1336
|
+
});
|
|
1337
|
+
} else {
|
|
1338
|
+
const filterData = flattenArray([...originData]);
|
|
1339
|
+
const rs = filterData.filter(it => !rowsFocus.includes(it[rowKey]));
|
|
1340
|
+
const newDaa = unFlattenData(rs);
|
|
1341
|
+
if (commandSettings && commandSettings.confirmDialog) {
|
|
1342
|
+
MySwal.fire({
|
|
1343
|
+
title: t ? t('Confirm') : 'Confirm',
|
|
1344
|
+
text: t ? t('Do you want to delete item?') : 'Do you want to delete item?',
|
|
1345
|
+
// icon: 'warning',
|
|
1346
|
+
allowOutsideClick: false,
|
|
1347
|
+
showCancelButton: true,
|
|
1348
|
+
confirmButtonText: t ? t('Delete') : 'Delete',
|
|
1349
|
+
cancelButtonText: t ? t('Cancel') : 'Cancel',
|
|
1350
|
+
customClass: {
|
|
1351
|
+
confirmButton: 'be-button btn-primary',
|
|
1352
|
+
cancelButton: 'be-button btn-danger ms-1'
|
|
1353
|
+
},
|
|
1354
|
+
buttonsStyling: false
|
|
1355
|
+
}).then(async result => {
|
|
1356
|
+
if (result.value) {
|
|
1357
|
+
triggerChangeData?.([...newDaa]);
|
|
1358
|
+
} else if (result.dismiss === MySwal.DismissReason.cancel) {}
|
|
1359
|
+
});
|
|
1360
|
+
} else {
|
|
1361
|
+
// không hiện dialog
|
|
1362
|
+
triggerChangeData?.([...newDaa]);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
}, [commandSettings, originData, rowKey, rowsFocus, t, triggerChangeData]);
|
|
1366
|
+
const handleDeleteAll = React.useCallback(item => {
|
|
1367
|
+
if (item.onClick) {
|
|
1368
|
+
item.onClick({
|
|
1369
|
+
toolbar: item
|
|
1370
|
+
});
|
|
1371
|
+
} else {
|
|
1372
|
+
if (commandSettings && commandSettings.confirmDialog) {
|
|
1373
|
+
MySwal.fire({
|
|
1374
|
+
title: t ? t('Confirm') : 'Confirm',
|
|
1375
|
+
text: t ? t('Do you want to delete item?') : 'Do you want to delete item?',
|
|
1376
|
+
// icon: 'warning',
|
|
1377
|
+
allowOutsideClick: false,
|
|
1378
|
+
showCancelButton: true,
|
|
1379
|
+
confirmButtonText: t ? t('Delete') : 'Delete',
|
|
1380
|
+
cancelButtonText: t ? t('Cancel') : 'Cancel',
|
|
1381
|
+
customClass: {
|
|
1382
|
+
confirmButton: 'be-button btn-primary',
|
|
1383
|
+
cancelButton: 'be-button btn-danger ms-1'
|
|
1384
|
+
},
|
|
1385
|
+
buttonsStyling: false
|
|
1386
|
+
}).then(async result => {
|
|
1387
|
+
if (result.value) {
|
|
1388
|
+
triggerChangeData?.([]);
|
|
1389
|
+
} else if (result.dismiss === MySwal.DismissReason.cancel) {}
|
|
1390
|
+
});
|
|
1391
|
+
} else {
|
|
1392
|
+
triggerChangeData?.([]);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}, [commandSettings, t, triggerChangeData]);
|
|
1396
|
+
const handleDeleteContent = () => {
|
|
1397
|
+
if (startCell && endCell) {
|
|
1398
|
+
const tmpData = flattenArray([...dataSource]);
|
|
1399
|
+
const rs = tmpData.map((row, index) => {
|
|
1400
|
+
if (!rangeState?.rowRange.includes(row.rowId)) {
|
|
1401
|
+
return row;
|
|
1402
|
+
}
|
|
1403
|
+
const updatedRow = {
|
|
1404
|
+
...row
|
|
1405
|
+
};
|
|
1406
|
+
for (const colId of rangeState.colRange) {
|
|
1407
|
+
const column = table.getVisibleFlatColumns().find(it => it.id === colId)?.columnDef.meta;
|
|
1408
|
+
const columnIndex = table.getVisibleFlatColumns().findIndex(it => it.id === colId);
|
|
1409
|
+
if (isEditable(column, row)) {
|
|
1410
|
+
updatedRow[colId] = '';
|
|
1411
|
+
handleCellChange({
|
|
1412
|
+
key: row[rowKey],
|
|
1413
|
+
field: column.field ?? column.dataIndex,
|
|
1414
|
+
record: updatedRow,
|
|
1415
|
+
prevState: row[column.field],
|
|
1416
|
+
newState: '',
|
|
1417
|
+
option: '',
|
|
1418
|
+
indexCol: columnIndex,
|
|
1419
|
+
indexRow: index,
|
|
1420
|
+
type: 'blur'
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
return updatedRow;
|
|
1425
|
+
});
|
|
1426
|
+
const newData = unFlattenData(rs);
|
|
1427
|
+
triggerChangeData?.([...newData]);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
const toolbarItemsBottom = React.useMemo(() => {
|
|
1431
|
+
if (!rowsFocus || rowsFocus.length === 0) {
|
|
1432
|
+
return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER' && it.key !== 'DELETE_ROWS' && it.key !== 'INSERT_CHILDREN').map(item => {
|
|
1433
|
+
if (item.key === 'ADD') {
|
|
1434
|
+
return {
|
|
1435
|
+
...item,
|
|
1436
|
+
template: () => {
|
|
1437
|
+
return /*#__PURE__*/React.createElement(Fragment, null, item.key === 'ADD' && /*#__PURE__*/React.createElement("div", {
|
|
1438
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1439
|
+
}, /*#__PURE__*/React.createElement(Dropdown.Button, {
|
|
1440
|
+
overlayClassName: 'be-popup-container',
|
|
1441
|
+
trigger: ['click'],
|
|
1442
|
+
style: {
|
|
1443
|
+
color: '#28c76f',
|
|
1444
|
+
borderColor: '#28c76f'
|
|
1445
|
+
},
|
|
1446
|
+
className: 'toolbar-button toolbar-dropdown-button',
|
|
1447
|
+
menu: {
|
|
1448
|
+
items: itemsAdd,
|
|
1449
|
+
onClick: e => handleAddMulti(item, Number(e.key))
|
|
1450
|
+
}
|
|
1451
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1452
|
+
style: {
|
|
1453
|
+
color: '#28c76f'
|
|
1454
|
+
},
|
|
1455
|
+
onClick: () => handleAddMulti(item, 1)
|
|
1456
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
if (item.key === 'DELETE') {
|
|
1461
|
+
return {
|
|
1462
|
+
...item,
|
|
1463
|
+
template: () => {
|
|
1464
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1465
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1466
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
1467
|
+
style: {
|
|
1468
|
+
color: '#eb4619',
|
|
1469
|
+
borderColor: '#eb4619'
|
|
1470
|
+
},
|
|
1471
|
+
variant: 'outlined',
|
|
1472
|
+
onClick: () => handleDeleteAll(item),
|
|
1473
|
+
className: "d-flex toolbar-button"
|
|
1474
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Delete all item') : 'Delete all item'));
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
return {
|
|
1479
|
+
...item
|
|
1480
|
+
};
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false).map(item => {
|
|
1484
|
+
if (item.key === 'ADD') {
|
|
1485
|
+
return {
|
|
1486
|
+
...item,
|
|
1487
|
+
template: () => {
|
|
1488
|
+
return /*#__PURE__*/React.createElement(Fragment, null, item.key === 'ADD' && /*#__PURE__*/React.createElement("div", {
|
|
1489
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1490
|
+
}, /*#__PURE__*/React.createElement(Dropdown.Button, {
|
|
1491
|
+
overlayClassName: 'be-popup-container',
|
|
1492
|
+
style: {
|
|
1493
|
+
color: '#28c76f',
|
|
1494
|
+
borderColor: '#28c76f'
|
|
1495
|
+
},
|
|
1496
|
+
className: 'toolbar-button toolbar-dropdown-button',
|
|
1497
|
+
menu: {
|
|
1498
|
+
items: itemsAdd,
|
|
1499
|
+
onClick: e => handleAddMulti(item, Number(e.key))
|
|
1500
|
+
}
|
|
1501
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1502
|
+
style: {
|
|
1503
|
+
color: '#28c76f'
|
|
1504
|
+
},
|
|
1505
|
+
onClick: () => handleAddMulti(item, 1)
|
|
1506
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
if (item.key === 'DUPLICATE') {
|
|
1511
|
+
return {
|
|
1512
|
+
...item,
|
|
1513
|
+
template: () => {
|
|
1514
|
+
return /*#__PURE__*/React.createElement(Fragment, null, item.key === 'DUPLICATE' && item.visible !== false && rowsFocus.length > 0 && /*#__PURE__*/React.createElement("div", {
|
|
1515
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1516
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
1517
|
+
style: {
|
|
1518
|
+
color: '#28c76f',
|
|
1519
|
+
borderColor: '#28c76f'
|
|
1520
|
+
},
|
|
1521
|
+
variant: 'outlined',
|
|
1522
|
+
onClick: handleDuplicate,
|
|
1523
|
+
className: "d-flex toolbar-button"
|
|
1524
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Duplicate') : 'Duplicate')));
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
if (item.key === 'INSERT_BEFORE') {
|
|
1529
|
+
return {
|
|
1530
|
+
...item,
|
|
1531
|
+
template: () => {
|
|
1532
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
1533
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1534
|
+
}, /*#__PURE__*/React.createElement(Dropdown.Button, {
|
|
1535
|
+
overlayClassName: 'be-popup-container',
|
|
1536
|
+
style: {
|
|
1537
|
+
color: '#28c76f',
|
|
1538
|
+
borderColor: '#28c76f'
|
|
1539
|
+
},
|
|
1540
|
+
className: 'toolbar-button toolbar-dropdown-button',
|
|
1541
|
+
menu: {
|
|
1542
|
+
items: itemsAdd,
|
|
1543
|
+
onClick: e => handleInsertBefore(item, Number(e.key))
|
|
1544
|
+
}
|
|
1545
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1546
|
+
style: {
|
|
1547
|
+
color: '#28c76f'
|
|
1548
|
+
},
|
|
1549
|
+
onClick: () => handleInsertBefore(item, 1)
|
|
1550
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Insert item before') : 'Insert item before'))));
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
if (item.key === 'INSERT_AFTER') {
|
|
1555
|
+
return {
|
|
1556
|
+
...item,
|
|
1557
|
+
template: () => {
|
|
1558
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
1559
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1560
|
+
}, /*#__PURE__*/React.createElement(Dropdown.Button, {
|
|
1561
|
+
overlayClassName: 'be-popup-container',
|
|
1562
|
+
style: {
|
|
1563
|
+
color: '#28c76f',
|
|
1564
|
+
borderColor: '#28c76f'
|
|
1565
|
+
},
|
|
1566
|
+
className: 'toolbar-button toolbar-dropdown-button',
|
|
1567
|
+
menu: {
|
|
1568
|
+
items: itemsAdd,
|
|
1569
|
+
onClick: e => handleInsertAfter(item, Number(e.key))
|
|
1570
|
+
}
|
|
1571
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1572
|
+
style: {
|
|
1573
|
+
color: '#28c76f'
|
|
1574
|
+
},
|
|
1575
|
+
onClick: () => handleInsertAfter(item, 1)
|
|
1576
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Insert item after') : 'Insert item after'))));
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
if (item.key === 'INSERT_CHILDREN') {
|
|
1581
|
+
return {
|
|
1582
|
+
...item,
|
|
1583
|
+
template: () => {
|
|
1584
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
1585
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1586
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
1587
|
+
style: {
|
|
1588
|
+
color: '#28c76f',
|
|
1589
|
+
borderColor: '#28c76f'
|
|
1590
|
+
},
|
|
1591
|
+
variant: 'outlined',
|
|
1592
|
+
onClick: () => handleInsertChild(item),
|
|
1593
|
+
className: "d-flex toolbar-button"
|
|
1594
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Insert item children') : 'Insert item children')));
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
if (item.key === 'DELETE') {
|
|
1599
|
+
return {
|
|
1600
|
+
...item,
|
|
1601
|
+
template: () => {
|
|
1602
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1603
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1604
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
1605
|
+
style: {
|
|
1606
|
+
color: '#eb4619',
|
|
1607
|
+
borderColor: '#eb4619'
|
|
1608
|
+
},
|
|
1609
|
+
variant: 'outlined',
|
|
1610
|
+
onClick: handleDeleteAll,
|
|
1611
|
+
className: "d-flex toolbar-button"
|
|
1612
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Delete all item') : 'Delete all item'));
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
if (item.key === 'DELETE_ROWS') {
|
|
1617
|
+
return {
|
|
1618
|
+
...item,
|
|
1619
|
+
template: () => {
|
|
1620
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1621
|
+
className: classNames(`be-toolbar-item`, item?.className)
|
|
1622
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
1623
|
+
style: {
|
|
1624
|
+
color: '#eb4619',
|
|
1625
|
+
borderColor: '#eb4619'
|
|
1626
|
+
},
|
|
1627
|
+
variant: 'outlined',
|
|
1628
|
+
onClick: () => handleDeleteRows(item),
|
|
1629
|
+
className: "d-flex toolbar-button"
|
|
1630
|
+
}, t ? `${t('Delete')} ${rowsFocus.length} ${t('row')}` : `Delete ${rowsFocus.length} item`));
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
return {
|
|
1635
|
+
...item
|
|
1636
|
+
};
|
|
1637
|
+
});
|
|
1638
|
+
}, [handleAddMulti, handleDeleteAll, handleDeleteRows, handleDuplicate, handleInsertAfter, handleInsertBefore, handleInsertChild, itemsAdd, rowsFocus, t, toolbarItems]);
|
|
1639
|
+
const triggerCommandClick = args => {
|
|
1640
|
+
const {
|
|
1641
|
+
id: idCommand,
|
|
1642
|
+
rowId,
|
|
1643
|
+
rowData,
|
|
1644
|
+
index
|
|
1645
|
+
} = args;
|
|
1646
|
+
const tmpData = [...dataSource];
|
|
1647
|
+
if (idCommand === 'DELETE') {
|
|
1648
|
+
// bật modal confirm
|
|
1649
|
+
if (commandSettings && commandSettings.confirmDialog) {
|
|
1650
|
+
MySwal.fire({
|
|
1651
|
+
title: t ? t('Confirm') : 'Confirm',
|
|
1652
|
+
text: t ? t('Do you want to delete item?') : 'Do you want to delete item?',
|
|
1653
|
+
// icon: 'warning',
|
|
1654
|
+
allowOutsideClick: false,
|
|
1655
|
+
showCancelButton: true,
|
|
1656
|
+
confirmButtonText: t ? t('Delete') : 'Delete',
|
|
1657
|
+
cancelButtonText: t ? t('Cancel') : 'Cancel',
|
|
1658
|
+
customClass: {
|
|
1659
|
+
confirmButton: 'be-button btn-primary',
|
|
1660
|
+
cancelButton: 'be-button btn-danger ms-1'
|
|
1661
|
+
},
|
|
1662
|
+
buttonsStyling: false
|
|
1663
|
+
}).then(async result => {
|
|
1664
|
+
if (result.value) {
|
|
1665
|
+
if (!commandSettings || commandSettings && commandSettings.client !== false) {
|
|
1666
|
+
// client
|
|
1667
|
+
|
|
1668
|
+
// kiểm tra dòng hiện tại có parent
|
|
1669
|
+
|
|
1670
|
+
let newData = [];
|
|
1671
|
+
if (rowData?.parentId) {
|
|
1672
|
+
const parent = findItemByKey(tmpData, rowKey, rowData.parentId);
|
|
1673
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
1674
|
+
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
1675
|
+
childData.splice(Number(findIndex), 1);
|
|
1676
|
+
const newRowData = {
|
|
1677
|
+
...parent,
|
|
1678
|
+
children: childData
|
|
1679
|
+
};
|
|
1680
|
+
// const newDataSource = updateArrayByKey(tmpData, newRowData, rowKey as string)
|
|
1681
|
+
newData = updateArrayByKey(tmpData, newRowData, rowKey);
|
|
1682
|
+
} else {
|
|
1683
|
+
tmpData.splice(Number(index), 1);
|
|
1684
|
+
newData = [...tmpData];
|
|
1685
|
+
}
|
|
1686
|
+
if (commandClick) {
|
|
1687
|
+
commandClick({
|
|
1688
|
+
id: idCommand,
|
|
1689
|
+
rowId: rowData.rowId,
|
|
1690
|
+
rowData,
|
|
1691
|
+
index,
|
|
1692
|
+
rows: [...newData]
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
} else {
|
|
1696
|
+
// server ~~ không làm gì
|
|
1697
|
+
if (commandClick) {
|
|
1698
|
+
commandClick({
|
|
1699
|
+
id: idCommand,
|
|
1700
|
+
rowId: rowData.rowId,
|
|
1701
|
+
rowData,
|
|
1702
|
+
index,
|
|
1703
|
+
rows: [...originData]
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
} else if (result.dismiss === MySwal.DismissReason.cancel) {}
|
|
1708
|
+
});
|
|
1709
|
+
} else {
|
|
1710
|
+
// -------------------
|
|
1711
|
+
|
|
1712
|
+
if (!commandSettings || commandSettings && commandSettings.client !== false) {
|
|
1713
|
+
// client
|
|
1714
|
+
|
|
1715
|
+
let newData2 = [];
|
|
1716
|
+
if (rowData?.parentId) {
|
|
1717
|
+
const parent = findItemByKey(originData, rowKey, rowData.parentId);
|
|
1718
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
1719
|
+
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
1720
|
+
childData.splice(Number(findIndex), 1);
|
|
1721
|
+
const newRowData = {
|
|
1722
|
+
...parent,
|
|
1723
|
+
children: childData
|
|
1724
|
+
};
|
|
1725
|
+
newData2 = updateArrayByKey(tmpData, newRowData, rowKey);
|
|
1726
|
+
} else {
|
|
1727
|
+
tmpData.splice(Number(index), 1);
|
|
1728
|
+
newData2 = [...tmpData];
|
|
1729
|
+
}
|
|
1730
|
+
if (commandClick) {
|
|
1731
|
+
commandClick({
|
|
1732
|
+
id: idCommand,
|
|
1733
|
+
rowId,
|
|
1734
|
+
rowData,
|
|
1735
|
+
index,
|
|
1736
|
+
rows: [...newData2]
|
|
1737
|
+
});
|
|
1738
|
+
}
|
|
1739
|
+
} else {
|
|
1740
|
+
// server
|
|
1741
|
+
if (commandClick) {
|
|
1742
|
+
commandClick({
|
|
1743
|
+
id: idCommand,
|
|
1744
|
+
rowId,
|
|
1745
|
+
rowData,
|
|
1746
|
+
index,
|
|
1747
|
+
rows: [...originData]
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
} else {
|
|
1753
|
+
if (commandClick) {
|
|
1754
|
+
commandClick({
|
|
1755
|
+
...args,
|
|
1756
|
+
rows: originData
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
};
|
|
1761
|
+
const triggerContextMenuClick = args => {
|
|
1762
|
+
if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
|
|
1763
|
+
if (args.item.key === 'INSERT_BEFORE_ADV') {
|
|
1764
|
+
// mở Modal
|
|
1765
|
+
|
|
1766
|
+
// setOpenModalAddRow((prev) => (
|
|
1767
|
+
// {
|
|
1768
|
+
// ...prev,
|
|
1769
|
+
// open: true,
|
|
1770
|
+
// type: 'INSERT_BEFORE'
|
|
1771
|
+
// }
|
|
1772
|
+
// ))
|
|
1773
|
+
} else {
|
|
1774
|
+
handleInsertBefore(args.item, args.item.row);
|
|
1775
|
+
}
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
if (args.item?.parentKey && args.item.parentKey === 'INSERT_AFTER') {
|
|
1779
|
+
if (args.item.key === 'INSERT_AFTER_ADV') {
|
|
1780
|
+
|
|
1781
|
+
// setOpenModalAddRow((prev) => (
|
|
1782
|
+
// {
|
|
1783
|
+
// ...prev,
|
|
1784
|
+
// open: true,
|
|
1785
|
+
// type: 'INSERT_AFTER'
|
|
1786
|
+
// }
|
|
1787
|
+
// ))
|
|
1788
|
+
} else {
|
|
1789
|
+
handleInsertAfter(args.item, args.item.row);
|
|
1790
|
+
}
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1793
|
+
if (args.item.key === 'INSERT_CHILDREN') {
|
|
1794
|
+
handleInsertChild(args.item);
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
if (args.item.key === 'DELETE_ROWS') {
|
|
1798
|
+
handleDeleteRows(args.item);
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
if (args.item.key === 'DELETE_CONTENT') {
|
|
1802
|
+
handleDeleteContent();
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
contextMenuClick?.(args);
|
|
1806
|
+
};
|
|
1807
|
+
const handleCellClick = (rowNumber, record, column, rowId, cellValue) => {
|
|
1808
|
+
const cellClickCallback = newOptions => {
|
|
1809
|
+
if (newOptions) {
|
|
1810
|
+
const newElem = {
|
|
1811
|
+
...column,
|
|
1812
|
+
editSelectSettings: {
|
|
1813
|
+
...(column?.editSelectSettings ? {
|
|
1814
|
+
...column?.editSelectSettings
|
|
1815
|
+
} : {}),
|
|
1816
|
+
options: newOptions
|
|
1817
|
+
}
|
|
1818
|
+
};
|
|
1819
|
+
const rrr = updateArrayByKey([...propsColumns], newElem, 'field');
|
|
1820
|
+
triggerChangeColumns?.(rrr, [], "cellClick");
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
if (onCellClick) {
|
|
1824
|
+
onCellClick({
|
|
1825
|
+
index: rowNumber,
|
|
1826
|
+
rowId,
|
|
1827
|
+
cellValue,
|
|
1828
|
+
type: "Editing",
|
|
1829
|
+
field: column.field,
|
|
1830
|
+
rowData: record
|
|
1831
|
+
}, cellClickCallback);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
const handleOnGroup = value => {
|
|
1835
|
+
triggerGroupColumns?.(value);
|
|
1836
|
+
};
|
|
1837
|
+
const handleCollapseAllGroup = () => {
|
|
1838
|
+
setExpanded({});
|
|
1839
|
+
};
|
|
1840
|
+
const handleExpandAllGroup = () => {
|
|
1841
|
+
const allKeys = findAllChildrenKeys2(dataSource, rowKey, 'children');
|
|
1842
|
+
setExpanded(convertToObjTrue(allKeys));
|
|
1843
|
+
};
|
|
1844
|
+
const groupToolbar = () => {
|
|
1845
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1846
|
+
style: {
|
|
1847
|
+
display: 'flex',
|
|
1848
|
+
gap: '10px',
|
|
1849
|
+
marginRight: 10
|
|
1850
|
+
}
|
|
1851
|
+
}, groupSetting?.showGroupIcon !== false && /*#__PURE__*/React.createElement(ColumnsGroup, {
|
|
1852
|
+
t: t
|
|
1853
|
+
// defaultGroupColumns={['name']}
|
|
1854
|
+
,
|
|
1855
|
+
unClearableLevel: groupSetting?.unClearableLevel
|
|
1856
|
+
// unClearableLevel={2}
|
|
1857
|
+
,
|
|
1858
|
+
columns: propsColumns ? flatColumns2(propsColumns) : [],
|
|
1859
|
+
columnsGrouped: groupColumns,
|
|
1860
|
+
onSubmit: handleOnGroup
|
|
1861
|
+
}), /*#__PURE__*/React.createElement(React.Fragment, null, !isObjEmpty(expanded) ? /*#__PURE__*/React.createElement(Collapse2, {
|
|
1862
|
+
fontSize: 16,
|
|
1863
|
+
color: '#555555',
|
|
1864
|
+
onClick: handleCollapseAllGroup
|
|
1865
|
+
}) : /*#__PURE__*/React.createElement(Expand2, {
|
|
1866
|
+
fontSize: 16,
|
|
1867
|
+
color: '#555555',
|
|
1868
|
+
onClick: handleExpandAllGroup
|
|
1869
|
+
})));
|
|
1870
|
+
};
|
|
1871
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1872
|
+
ref: containerRef,
|
|
1873
|
+
id: id
|
|
1874
|
+
}, (showToolbar !== false || fullScreen !== false || showColumnChoose || title) && /*#__PURE__*/React.createElement("div", {
|
|
1875
|
+
ref: topToolbarRef,
|
|
1876
|
+
className: classNames(`${prefix}-grid-top-toolbar`, {})
|
|
1877
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1878
|
+
style: {
|
|
1879
|
+
textAlign: 'center'
|
|
1880
|
+
}
|
|
1881
|
+
}, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/React.createElement("div", {
|
|
1882
|
+
style: {
|
|
1883
|
+
display: 'flex',
|
|
1884
|
+
justifyContent: 'space-between',
|
|
1885
|
+
alignItems: 'center',
|
|
1886
|
+
gap: '.75rem'
|
|
1887
|
+
}
|
|
1888
|
+
}, groupToolbar(), /*#__PURE__*/React.createElement("div", {
|
|
1889
|
+
style: {
|
|
1890
|
+
flex: 1,
|
|
1891
|
+
overflow: 'hidden'
|
|
1892
|
+
}
|
|
1893
|
+
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
1894
|
+
items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
|
|
1895
|
+
mode: 'scroll'
|
|
1896
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
1897
|
+
style: {
|
|
1898
|
+
display: 'flex',
|
|
1899
|
+
justifyContent: 'space-between',
|
|
1900
|
+
alignItems: 'center',
|
|
1901
|
+
gap: '.75rem'
|
|
1902
|
+
}
|
|
1903
|
+
}, pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' && /*#__PURE__*/React.createElement(Pagination, _extends({
|
|
1904
|
+
showSizeChanger: true,
|
|
1905
|
+
responsive: true,
|
|
1906
|
+
size: 'small',
|
|
1907
|
+
rootClassName: 'top-pagination',
|
|
1908
|
+
showTotal: (total, range) =>
|
|
1909
|
+
// @ts-ignore
|
|
1910
|
+
`${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
|
|
1911
|
+
}, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, fullScreen !== false && (isFullScreen ? /*#__PURE__*/React.createElement(Minimize, {
|
|
1912
|
+
fontSize: 16,
|
|
1913
|
+
onClick: () => {
|
|
1914
|
+
setIsFullScreen(!isFullScreen);
|
|
1915
|
+
},
|
|
1916
|
+
"data-tooltip-id": `${id}-tooltip-content`,
|
|
1917
|
+
"data-tooltip-content": t ? t('Minimized') : 'Minimized'
|
|
1918
|
+
}) : /*#__PURE__*/React.createElement(Maximize, {
|
|
1919
|
+
fontSize: 16,
|
|
1920
|
+
onClick: () => {
|
|
1921
|
+
setIsFullScreen(!isFullScreen);
|
|
1922
|
+
},
|
|
1923
|
+
"data-tooltip-id": `${id}-tooltip-content`,
|
|
1924
|
+
"data-tooltip-content": t ? t('Full screen') : 'Full screen'
|
|
1925
|
+
})), showColumnChoose && /*#__PURE__*/React.createElement(ColumnsChoose, {
|
|
1926
|
+
columns: columns,
|
|
1927
|
+
originColumns: propsColumns,
|
|
1928
|
+
t: t,
|
|
1929
|
+
columnsGroup: groupColumns,
|
|
1930
|
+
triggerChangeColumns: triggerChangeColumns,
|
|
1931
|
+
columnHidden: columnHidden
|
|
1932
|
+
})))), /*#__PURE__*/React.createElement("form", {
|
|
1933
|
+
onSubmit: handleSubmit(onSubmit)
|
|
1934
|
+
}, /*#__PURE__*/React.createElement(TableContext.Provider, {
|
|
1935
|
+
value: {
|
|
1936
|
+
t,
|
|
1937
|
+
isDataTree,
|
|
1938
|
+
locale,
|
|
1939
|
+
prefix,
|
|
1940
|
+
id,
|
|
1941
|
+
rowKey,
|
|
1942
|
+
format,
|
|
1943
|
+
expandable,
|
|
1944
|
+
expanded,
|
|
1945
|
+
setExpanded,
|
|
1946
|
+
dataSource,
|
|
1947
|
+
originData,
|
|
1948
|
+
wrapSettings,
|
|
1949
|
+
recordDoubleClick,
|
|
1950
|
+
selectionSettings,
|
|
1951
|
+
isSelectionChange,
|
|
1952
|
+
setIsSelectionChange,
|
|
1953
|
+
// onContextMenu,
|
|
1954
|
+
setSorterChange,
|
|
1955
|
+
setFilterChange,
|
|
1956
|
+
rangeState,
|
|
1957
|
+
setRangeState,
|
|
1958
|
+
rangePasteState,
|
|
1959
|
+
setRangePasteState,
|
|
1960
|
+
focusedCell,
|
|
1961
|
+
setFocusedCell,
|
|
1962
|
+
startCell,
|
|
1963
|
+
editingKey,
|
|
1964
|
+
endCell,
|
|
1965
|
+
isSelecting,
|
|
1966
|
+
isPasting,
|
|
1967
|
+
startPasteCell,
|
|
1968
|
+
endPasteCell,
|
|
1969
|
+
setEditingKey,
|
|
1970
|
+
setEndCell,
|
|
1971
|
+
setIsSelecting,
|
|
1972
|
+
setStartCell,
|
|
1973
|
+
setIsPasting,
|
|
1974
|
+
setEndPasteCell,
|
|
1975
|
+
setStartPasteCell,
|
|
1976
|
+
//
|
|
1977
|
+
control,
|
|
1978
|
+
// trigger,
|
|
1979
|
+
errors,
|
|
1980
|
+
getValues,
|
|
1981
|
+
setValue,
|
|
1982
|
+
reset,
|
|
1983
|
+
handleCellChange,
|
|
1984
|
+
handleCellChangeAndAddRow,
|
|
1985
|
+
triggerPaste,
|
|
1986
|
+
handleDeleteContent,
|
|
1987
|
+
handleAddMulti,
|
|
1988
|
+
dataErrors,
|
|
1989
|
+
windowSize,
|
|
1990
|
+
handleCellClick,
|
|
1991
|
+
pagination,
|
|
1992
|
+
rowClassName,
|
|
1993
|
+
rowEditable,
|
|
1994
|
+
onRowStyles,
|
|
1995
|
+
dataSourceFilter,
|
|
1996
|
+
groupColumns
|
|
1997
|
+
}
|
|
1998
|
+
}, /*#__PURE__*/React.createElement(TableWrapper, {
|
|
1999
|
+
contextMenuItems: contextMenuItems,
|
|
2000
|
+
height: tableHeight,
|
|
2001
|
+
minHeight: minHeight,
|
|
2002
|
+
id: id,
|
|
2003
|
+
prefix: prefix,
|
|
2004
|
+
table: table,
|
|
2005
|
+
tableContainerRef: tableContainerRef,
|
|
2006
|
+
commandClick: triggerCommandClick,
|
|
2007
|
+
contextMenuClick: triggerContextMenuClick,
|
|
2008
|
+
contextMenuHidden: contextMenuHidden,
|
|
2009
|
+
contextMenuOpen: contextMenuOpen,
|
|
2010
|
+
editAble: editAble,
|
|
2011
|
+
showEmptyText: showEmptyText,
|
|
2012
|
+
summary: summary,
|
|
2013
|
+
dataSource: dataSource,
|
|
2014
|
+
infiniteScroll: infiniteScroll,
|
|
2015
|
+
next: next,
|
|
2016
|
+
loading: loading,
|
|
2017
|
+
columnVirtualizer: columnVirtualizer,
|
|
2018
|
+
virtualPaddingLeft: virtualPaddingLeft,
|
|
2019
|
+
virtualPaddingRight: virtualPaddingRight,
|
|
2020
|
+
fixedLeftColumns: fixedLeftColumns,
|
|
2021
|
+
fixedRightColumns: fixedRightColumns
|
|
2022
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
2023
|
+
ref: bottomToolbarRef
|
|
2024
|
+
}, toolbarItemsBottom && toolbarItemsBottom.length > 0 && /*#__PURE__*/React.createElement("div", {
|
|
2025
|
+
className: classNames('ui-rc-toolbar-bottom', {
|
|
2026
|
+
'ui-rc-toolbar-bottom_border-bottom': !pagination || infiniteScroll
|
|
2027
|
+
})
|
|
2028
|
+
// style={{ border: '0 1px 1px 1px solid #e0e0e0' }}
|
|
2029
|
+
// style={{
|
|
2030
|
+
// borderBottom: '1px solid #e0e0e0',
|
|
2031
|
+
// borderRight: '1px solid #e0e0e0',
|
|
2032
|
+
// borderLeft: '1px solid #e0e0e0'
|
|
2033
|
+
// }}
|
|
2034
|
+
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
2035
|
+
style: {
|
|
2036
|
+
width: '100%'
|
|
2037
|
+
},
|
|
2038
|
+
items: toolbarItemsBottom ?? [],
|
|
2039
|
+
mode: 'scroll',
|
|
2040
|
+
onClick: ({}) => {
|
|
2041
|
+
setEditingKey('');
|
|
2042
|
+
}
|
|
2043
|
+
})), pagination && !infiniteScroll && /*#__PURE__*/React.createElement(Pagination, _extends({}, pagination, {
|
|
2044
|
+
rootClassName: 'pagination-template',
|
|
2045
|
+
showSizeChanger: true,
|
|
2046
|
+
responsive: true,
|
|
2047
|
+
size: 'small',
|
|
2048
|
+
total: pagination.total,
|
|
2049
|
+
pageSize: pagination.onChange ? pagination?.pageSize : table.getState().pagination.pageSize,
|
|
2050
|
+
pageSizeOptions: [20, 50, 100, 1000, 10000],
|
|
2051
|
+
onChange: (page, pageSize) => {
|
|
2052
|
+
if (pagination.onChange) {
|
|
2053
|
+
pagination.onChange(page, pageSize);
|
|
2054
|
+
} else {
|
|
2055
|
+
table.setPageIndex(page - 1);
|
|
2056
|
+
table.setPageSize(pageSize);
|
|
2057
|
+
}
|
|
2058
|
+
},
|
|
2059
|
+
showTotal: (total, range) => `${numericFormatter((range[0] ?? 0).toString(), {
|
|
2060
|
+
thousandSeparator: '.'
|
|
2061
|
+
})}-${numericFormatter((range[1] ?? 0).toString(), {
|
|
2062
|
+
thousandSeparator: '.'
|
|
2063
|
+
})} / ${numericFormatter((total ?? 0).toString(), {
|
|
2064
|
+
thousandSeparator: '.'
|
|
2065
|
+
})} items`
|
|
2066
|
+
}))));
|
|
2067
|
+
};
|
|
2068
|
+
export default TableContainerEdit;
|