es-grid-template 1.7.24 → 1.7.25
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/table-component/ColumnsChoose.d.ts +6 -3
- package/es/table-component/ColumnsChoose.js +31 -382
- package/es/table-component/InternalTable.js +32 -19
- package/es/table-component/TableContainer.d.ts +11 -2
- package/es/table-component/TableContainer.js +131 -12
- package/es/table-component/TableContainerEdit.d.ts +10 -7
- package/es/table-component/TableContainerEdit.js +151 -61
- package/es/table-component/body/EditableCell.js +14 -11
- package/es/table-component/body/TableBody.js +1 -1
- package/es/table-component/body/TableBodyCell.d.ts +2 -0
- package/es/table-component/body/TableBodyCell.js +13 -3
- package/es/table-component/body/TableBodyCellEdit.d.ts +2 -1
- package/es/table-component/body/TableBodyCellEdit.js +150 -33
- package/es/table-component/body/TableBodyRow.js +9 -4
- package/es/table-component/components/ControlCheckbox.js +0 -3
- package/es/table-component/components/async-table-select/index.d.ts +1 -1
- package/es/table-component/components/async-table-select/index.js +1 -0
- package/es/table-component/components/command/Command.d.ts +1 -0
- package/es/table-component/components/command/Command.js +6 -1
- package/es/table-component/footer/TableFooterCell.js +45 -3
- package/es/table-component/footer/TableFooterRow.js +3 -1
- package/es/table-component/header/TableHeadCell.js +31 -12
- package/es/table-component/header/TableHeadRow.d.ts +1 -1
- package/es/table-component/header/TableHeadRow.js +10 -20
- package/es/table-component/hook/useColumns.d.ts +5 -7
- package/es/table-component/hook/useColumns.js +18 -58
- package/es/table-component/hook/utils.d.ts +12 -0
- package/es/table-component/hook/utils.js +144 -1
- package/es/table-component/style.scss +47 -1
- package/es/table-component/table/Grid.d.ts +3 -2
- package/es/table-component/table/Grid.js +22 -98
- package/es/table-component/type.d.ts +32 -1
- package/es/table-component/useContext.d.ts +5 -50
- package/es/table-component/useContext.js +3 -49
- package/lib/table-component/ColumnsChoose.d.ts +6 -3
- package/lib/table-component/ColumnsChoose.js +29 -381
- package/lib/table-component/InternalTable.js +30 -16
- package/lib/table-component/TableContainer.d.ts +11 -2
- package/lib/table-component/TableContainer.js +132 -12
- package/lib/table-component/TableContainerEdit.d.ts +10 -7
- package/lib/table-component/TableContainerEdit.js +150 -60
- package/lib/table-component/body/EditableCell.js +14 -11
- package/lib/table-component/body/TableBody.js +1 -1
- package/lib/table-component/body/TableBodyCell.d.ts +2 -0
- package/lib/table-component/body/TableBodyCell.js +13 -3
- package/lib/table-component/body/TableBodyCellEdit.d.ts +2 -1
- package/lib/table-component/body/TableBodyCellEdit.js +150 -33
- package/lib/table-component/body/TableBodyRow.js +9 -4
- package/lib/table-component/components/ControlCheckbox.js +0 -3
- package/lib/table-component/components/async-table-select/index.d.ts +1 -1
- package/lib/table-component/components/async-table-select/index.js +2 -0
- package/lib/table-component/components/command/Command.d.ts +1 -0
- package/lib/table-component/components/command/Command.js +6 -1
- package/lib/table-component/footer/TableFooterCell.js +46 -2
- package/lib/table-component/footer/TableFooterRow.js +3 -1
- package/lib/table-component/header/TableHeadCell.js +31 -12
- package/lib/table-component/header/TableHeadRow.d.ts +1 -1
- package/lib/table-component/header/TableHeadRow.js +10 -20
- package/lib/table-component/hook/useColumns.d.ts +5 -7
- package/lib/table-component/hook/useColumns.js +17 -57
- package/lib/table-component/hook/utils.d.ts +12 -0
- package/lib/table-component/hook/utils.js +160 -8
- package/lib/table-component/style.scss +47 -1
- package/lib/table-component/table/Grid.d.ts +3 -2
- package/lib/table-component/table/Grid.js +21 -98
- package/lib/table-component/type.d.ts +32 -1
- package/lib/table-component/useContext.d.ts +5 -50
- package/lib/table-component/useContext.js +4 -50
- package/package.json +2 -2
- package/es/table-component/table/GridEdit.d.ts +0 -23
- package/es/table-component/table/GridEdit.js +0 -282
- package/lib/table-component/table/GridEdit.d.ts +0 -23
- package/lib/table-component/table/GridEdit.js +0 -284
|
@@ -5,18 +5,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
8
9
|
var _react = _interopRequireDefault(require("react"));
|
|
9
10
|
var _TableHead = _interopRequireDefault(require("./header/TableHead"));
|
|
10
11
|
var _utils = require("./hook/utils");
|
|
11
12
|
var _reactVirtual = require("@tanstack/react-virtual");
|
|
12
13
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
-
var _TableBody = _interopRequireDefault(require("./body/TableBody"));
|
|
14
14
|
var _useContext = require("./useContext");
|
|
15
|
+
var _pagination = _interopRequireDefault(require("rc-master-ui/es/pagination"));
|
|
16
|
+
var _rcMasterUi = require("rc-master-ui");
|
|
17
|
+
var _becoxyIcons = require("becoxy-icons");
|
|
18
|
+
var _ColumnsChoose = require("./ColumnsChoose");
|
|
19
|
+
var _TableFooter = _interopRequireDefault(require("./footer/TableFooter"));
|
|
20
|
+
var _TableBody = _interopRequireDefault(require("./body/TableBody"));
|
|
21
|
+
var _reactNumericComponent = require("react-numeric-component");
|
|
15
22
|
// import type { Dispatch, SetStateAction } from "react";
|
|
16
23
|
|
|
24
|
+
// import TableBody from './body/TableBody'
|
|
25
|
+
|
|
17
26
|
const TableContainer = props => {
|
|
18
27
|
const {
|
|
19
|
-
|
|
28
|
+
t,
|
|
20
29
|
table,
|
|
21
30
|
id,
|
|
22
31
|
prefix,
|
|
@@ -36,10 +45,36 @@ const TableContainer = props => {
|
|
|
36
45
|
contextMenuItems,
|
|
37
46
|
setSorterChange,
|
|
38
47
|
setFilterChange,
|
|
39
|
-
|
|
48
|
+
height,
|
|
49
|
+
showToolbar,
|
|
50
|
+
toolbarItems,
|
|
51
|
+
actionTemplate,
|
|
52
|
+
pagination,
|
|
53
|
+
fullScreen,
|
|
54
|
+
showColumnChoose,
|
|
55
|
+
summary,
|
|
56
|
+
locale,
|
|
57
|
+
groupColumns,
|
|
58
|
+
columns,
|
|
59
|
+
propsColumns,
|
|
60
|
+
triggerChangeColumns,
|
|
61
|
+
columnHidden,
|
|
62
|
+
expanded,
|
|
63
|
+
setExpanded
|
|
40
64
|
} = props;
|
|
41
65
|
const tableContainerRef = _react.default.useRef(null);
|
|
66
|
+
const containerRef = _react.default.useRef(null);
|
|
67
|
+
const bottomToolbarRef = _react.default.useRef(null);
|
|
68
|
+
const topToolbarRef = _react.default.useRef(null);
|
|
42
69
|
const visibleColumns = table.getVisibleLeafColumns();
|
|
70
|
+
const [isFullScreen] = _react.default.useState(false);
|
|
71
|
+
const [tableHeight, settableHeight] = _react.default.useState(0);
|
|
72
|
+
_react.default.useEffect(() => {
|
|
73
|
+
const totalHeight = height;
|
|
74
|
+
if (totalHeight && topToolbarRef.current && bottomToolbarRef.current) {
|
|
75
|
+
settableHeight(totalHeight - topToolbarRef.current.offsetHeight - bottomToolbarRef.current.offsetHeight);
|
|
76
|
+
}
|
|
77
|
+
}, [id, height, editAble]);
|
|
43
78
|
const fixedLeftColumns = table.getState().columnPinning.left ? visibleColumns.filter(vc => table.getState().columnPinning.left?.includes(vc.id)) : [];
|
|
44
79
|
const fixedRightColumns = table.getState().columnPinning.right ? visibleColumns.filter(vc => table.getState().columnPinning.right?.includes(vc.id)) : [];
|
|
45
80
|
const columnVirtualizer = (0, _reactVirtual.useVirtualizer)({
|
|
@@ -50,15 +85,6 @@ const TableContainer = props => {
|
|
|
50
85
|
measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element?.getBoundingClientRect().height : undefined,
|
|
51
86
|
overscan: 3 //how many columns to render on each side off screen each way (adjust this for performance)
|
|
52
87
|
});
|
|
53
|
-
|
|
54
|
-
// const columnSizingState = table.getState().columnSizing
|
|
55
|
-
|
|
56
|
-
// React.useEffect(() => {
|
|
57
|
-
// requestAnimationFrame(() => {
|
|
58
|
-
// columnVirtualizer.measure()
|
|
59
|
-
// })
|
|
60
|
-
// }, [columnSizingState, columnVirtualizer])
|
|
61
|
-
|
|
62
88
|
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
63
89
|
const cacheColumns = columnVirtualizer.measurementsCache;
|
|
64
90
|
const rightCols = table.getState().columnPinning.right?.length ? [...cacheColumns].slice(-(table.getState().columnPinning.right?.length ?? 0)) : [];
|
|
@@ -75,6 +101,61 @@ const TableContainer = props => {
|
|
|
75
101
|
virtualPaddingRight = fixedRightColumns && fixedRightColumns.length > 0 ? pdRight - rightWidth > 0 ? pdRight - rightWidth : 0 : pdRight;
|
|
76
102
|
}
|
|
77
103
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
104
|
+
ref: containerRef,
|
|
105
|
+
id: id
|
|
106
|
+
}, (showToolbar !== false || fullScreen !== false) && /*#__PURE__*/_react.default.createElement("div", {
|
|
107
|
+
ref: topToolbarRef,
|
|
108
|
+
className: (0, _classnames.default)(`${prefix}-grid-top-toolbar`, {})
|
|
109
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
110
|
+
style: {
|
|
111
|
+
display: 'flex',
|
|
112
|
+
justifyContent: 'space-between',
|
|
113
|
+
alignItems: 'center',
|
|
114
|
+
gap: '.75rem'
|
|
115
|
+
}
|
|
116
|
+
}, toolbarItems && toolbarItems?.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
117
|
+
style: {
|
|
118
|
+
flex: 1,
|
|
119
|
+
overflow: 'hidden'
|
|
120
|
+
}
|
|
121
|
+
}, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Toolbar, {
|
|
122
|
+
items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
|
|
123
|
+
mode: 'scroll'
|
|
124
|
+
})), fullScreen !== false && (isFullScreen ? /*#__PURE__*/_react.default.createElement(_becoxyIcons.Minimize, {
|
|
125
|
+
fontSize: 16
|
|
126
|
+
// onClick={() => handleFullScreen?.()}
|
|
127
|
+
,
|
|
128
|
+
"data-tooltip-id": "tooltip-icon",
|
|
129
|
+
"data-tooltip-content": t ? t('Minimized') : 'Minimized'
|
|
130
|
+
}) : /*#__PURE__*/_react.default.createElement(_becoxyIcons.Maximize, {
|
|
131
|
+
fontSize: 16
|
|
132
|
+
// onClick={() => handleFullScreen?.()}
|
|
133
|
+
,
|
|
134
|
+
"data-tooltip-id": "tooltip-icon",
|
|
135
|
+
"data-tooltip-content": t ? t('Full screen') : 'Full screen'
|
|
136
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
137
|
+
style: {
|
|
138
|
+
display: 'flex',
|
|
139
|
+
justifyContent: 'space-between',
|
|
140
|
+
alignItems: 'center',
|
|
141
|
+
gap: '.75rem'
|
|
142
|
+
}
|
|
143
|
+
}, pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' && /*#__PURE__*/_react.default.createElement(_pagination.default, (0, _extends2.default)({
|
|
144
|
+
showSizeChanger: true,
|
|
145
|
+
responsive: true,
|
|
146
|
+
size: 'small',
|
|
147
|
+
rootClassName: 'top-pagination',
|
|
148
|
+
showTotal: (total, range) =>
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
`${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
|
|
151
|
+
}, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, showColumnChoose && /*#__PURE__*/_react.default.createElement(_ColumnsChoose.ColumnsChoose, {
|
|
152
|
+
columnHidden: columnHidden,
|
|
153
|
+
columns: columns,
|
|
154
|
+
originColumns: propsColumns,
|
|
155
|
+
t: t,
|
|
156
|
+
columnsGroup: groupColumns,
|
|
157
|
+
triggerChangeColumns: triggerChangeColumns
|
|
158
|
+
})))), /*#__PURE__*/_react.default.createElement("div", {
|
|
78
159
|
className: (0, _classnames.default)(`${prefix}-grid-container`, {
|
|
79
160
|
'ui-rc-table-ping-right': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) >= 0 && (tableContainerRef.current?.scrollLeft ?? 0) + (tableContainerRef.current?.clientWidth ?? 0) < (tableContainerRef.current?.scrollWidth ?? 0),
|
|
80
161
|
'ui-rc-table-ping-left': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) > 0
|
|
@@ -91,11 +172,14 @@ const TableContainer = props => {
|
|
|
91
172
|
}
|
|
92
173
|
}, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
|
|
93
174
|
value: {
|
|
175
|
+
locale,
|
|
94
176
|
prefix,
|
|
95
177
|
id,
|
|
96
178
|
rowKey,
|
|
97
179
|
format,
|
|
98
180
|
expandable,
|
|
181
|
+
expanded,
|
|
182
|
+
setExpanded,
|
|
99
183
|
dataSource,
|
|
100
184
|
originData,
|
|
101
185
|
// triggerFilter,
|
|
@@ -132,6 +216,42 @@ const TableContainer = props => {
|
|
|
132
216
|
commandClick: commandClick,
|
|
133
217
|
editAble: editAble,
|
|
134
218
|
contextMenuItems: contextMenuItems
|
|
219
|
+
}), summary && /*#__PURE__*/_react.default.createElement(_TableFooter.default
|
|
220
|
+
// tableContainerRef={tableContainerRef}
|
|
221
|
+
, {
|
|
222
|
+
columnVirtualizer: columnVirtualizer,
|
|
223
|
+
table: table,
|
|
224
|
+
virtualPaddingLeft: virtualPaddingLeft,
|
|
225
|
+
virtualPaddingRight: virtualPaddingRight,
|
|
226
|
+
fixedLeftColumns: fixedLeftColumns,
|
|
227
|
+
fixedRightColumns: fixedRightColumns
|
|
228
|
+
})))), /*#__PURE__*/_react.default.createElement("div", {
|
|
229
|
+
ref: bottomToolbarRef
|
|
230
|
+
}, pagination && /*#__PURE__*/_react.default.createElement(_pagination.default
|
|
231
|
+
// style={{padding: '0.75rem 1rem'}}
|
|
232
|
+
, (0, _extends2.default)({}, pagination, {
|
|
233
|
+
rootClassName: 'pagination-template',
|
|
234
|
+
showSizeChanger: true,
|
|
235
|
+
responsive: true,
|
|
236
|
+
size: 'small',
|
|
237
|
+
total: pagination.total,
|
|
238
|
+
pageSize: pagination.onChange ? pagination.pageSize : table.getState().pagination.pageSize,
|
|
239
|
+
showTotal: (total, range) => `${(0, _reactNumericComponent.numericFormatter)((range[0] ?? 0).toString(), {
|
|
240
|
+
thousandSeparator: '.'
|
|
241
|
+
})}-${(0, _reactNumericComponent.numericFormatter)((range[1] ?? 0).toString(), {
|
|
242
|
+
thousandSeparator: '.'
|
|
243
|
+
})} / ${(0, _reactNumericComponent.numericFormatter)((total ?? 0).toString(), {
|
|
244
|
+
thousandSeparator: '.'
|
|
245
|
+
})} items`,
|
|
246
|
+
pageSizeOptions: [20, 50, 100, 1000, 10000],
|
|
247
|
+
onChange: (page, pageSize) => {
|
|
248
|
+
if (pagination.onChange) {
|
|
249
|
+
pagination.onChange(page, pageSize);
|
|
250
|
+
} else {
|
|
251
|
+
table.setPageIndex(page - 1);
|
|
252
|
+
table.setPageSize(pageSize);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
135
255
|
}))));
|
|
136
256
|
};
|
|
137
257
|
var _default = exports.default = TableContainer;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Dispatch, SetStateAction } from "react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import type { Table } from "@tanstack/react-table";
|
|
4
|
-
import type { TableProps } from "./type";
|
|
3
|
+
import type { ColumnDef, Table } from "@tanstack/react-table";
|
|
4
|
+
import type { ColumnsTable, TableProps } from "./type";
|
|
5
5
|
type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
6
|
table: Table<T>;
|
|
7
7
|
prefix: string;
|
|
8
8
|
id: string;
|
|
9
9
|
rowKey: any;
|
|
10
10
|
originData: T[];
|
|
11
|
+
propsColumns: ColumnsTable;
|
|
11
12
|
setIsSelectionChange: Dispatch<SetStateAction<{
|
|
12
13
|
isChange: boolean;
|
|
13
14
|
type: string;
|
|
@@ -18,11 +19,13 @@ type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
|
18
19
|
onContextMenu?: (data: T) => (event: any) => void;
|
|
19
20
|
tableHeight?: number;
|
|
20
21
|
triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
mergedFilterKeys?: any;
|
|
23
|
+
setMergedFilterKeys?: any;
|
|
24
|
+
setExpanded?: any;
|
|
25
|
+
expanded?: any;
|
|
26
|
+
columns: ColumnDef<T>[];
|
|
27
|
+
triggerChangeColumns: any;
|
|
28
|
+
columnHidden: any;
|
|
26
29
|
};
|
|
27
30
|
declare const TableContainerEdit: <RecordType extends object>(props: TableContainerProps<RecordType>) => React.JSX.Element;
|
|
28
31
|
export default TableContainerEdit;
|
|
@@ -21,12 +21,45 @@ var _rcMasterUi = require("rc-master-ui");
|
|
|
21
21
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
22
22
|
var _becoxyIcons = require("becoxy-icons");
|
|
23
23
|
var _ColumnsChoose = require("./ColumnsChoose");
|
|
24
|
+
var _TableFooter = _interopRequireDefault(require("./footer/TableFooter"));
|
|
24
25
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
25
26
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
26
27
|
const {
|
|
27
28
|
Paragraph,
|
|
28
29
|
Title
|
|
29
30
|
} = _antd.Typography;
|
|
31
|
+
const validateData = async (data, formSchema) => {
|
|
32
|
+
if (!formSchema) {
|
|
33
|
+
return [];
|
|
34
|
+
} else {
|
|
35
|
+
const errors = [];
|
|
36
|
+
for (let i = 0; i < data.length; i++) {
|
|
37
|
+
try {
|
|
38
|
+
await formSchema.validate(data[i], {
|
|
39
|
+
abortEarly: false
|
|
40
|
+
});
|
|
41
|
+
} catch (error) {
|
|
42
|
+
errors.push(error.inner.reduce((acc, err) => {
|
|
43
|
+
acc[err.path] = {
|
|
44
|
+
field: err.path,
|
|
45
|
+
index: i,
|
|
46
|
+
message: err.message,
|
|
47
|
+
type: err.type,
|
|
48
|
+
ref: {
|
|
49
|
+
name: err.path
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
...acc,
|
|
54
|
+
index: i,
|
|
55
|
+
id: data[i].rowId
|
|
56
|
+
};
|
|
57
|
+
}, {}));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return errors;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
30
63
|
const TableContainerEdit = props => {
|
|
31
64
|
const {
|
|
32
65
|
t,
|
|
@@ -51,14 +84,16 @@ const TableContainerEdit = props => {
|
|
|
51
84
|
setFilterChange,
|
|
52
85
|
// tableHeight,
|
|
53
86
|
onCellPaste,
|
|
54
|
-
triggerPaste,
|
|
87
|
+
// triggerPaste,
|
|
55
88
|
validate,
|
|
56
|
-
triggerChangeData,
|
|
89
|
+
// triggerChangeData,
|
|
57
90
|
onCellChange,
|
|
91
|
+
onDataChange,
|
|
58
92
|
defaultValue,
|
|
59
93
|
toolbarItems,
|
|
60
94
|
mergedFilterKeys,
|
|
61
95
|
setMergedFilterKeys,
|
|
96
|
+
expanded,
|
|
62
97
|
setExpanded,
|
|
63
98
|
onBlur,
|
|
64
99
|
fullScreen,
|
|
@@ -66,7 +101,14 @@ const TableContainerEdit = props => {
|
|
|
66
101
|
showToolbar,
|
|
67
102
|
actionTemplate,
|
|
68
103
|
showColumnChoose,
|
|
69
|
-
height
|
|
104
|
+
height,
|
|
105
|
+
summary,
|
|
106
|
+
locale,
|
|
107
|
+
groupColumns,
|
|
108
|
+
columns,
|
|
109
|
+
propsColumns,
|
|
110
|
+
triggerChangeColumns,
|
|
111
|
+
columnHidden
|
|
70
112
|
} = props;
|
|
71
113
|
const containerRef = _react.default.useRef(null);
|
|
72
114
|
const bottomToolbarRef = _react.default.useRef(null);
|
|
@@ -94,7 +136,7 @@ const TableContainerEdit = props => {
|
|
|
94
136
|
// },
|
|
95
137
|
|
|
96
138
|
measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element?.getBoundingClientRect().height : undefined,
|
|
97
|
-
overscan:
|
|
139
|
+
overscan: 1 //how many columns to render on each side off screen each way (adjust this for performance)
|
|
98
140
|
});
|
|
99
141
|
const columnSizingState = table.getState().columnSizing;
|
|
100
142
|
const itemsAdd = _react.default.useMemo(() => {
|
|
@@ -109,11 +151,22 @@ const TableContainerEdit = props => {
|
|
|
109
151
|
label: `100 ${t ? t('rows') : 'rows'}`
|
|
110
152
|
}];
|
|
111
153
|
}, [t]);
|
|
154
|
+
const [dataErrors, setDataErrors] = _react.default.useState([]);
|
|
112
155
|
_react.default.useEffect(() => {
|
|
113
156
|
requestAnimationFrame(() => {
|
|
114
157
|
columnVirtualizer.measure();
|
|
115
158
|
});
|
|
116
159
|
}, [columnSizingState, columnVirtualizer]);
|
|
160
|
+
_react.default.useEffect(() => {
|
|
161
|
+
if (validate && dataSource && dataSource.length) {
|
|
162
|
+
validateData(dataSource, validate).then(error => {
|
|
163
|
+
setDataErrors([...error]);
|
|
164
|
+
// if (getErrors) {
|
|
165
|
+
// getErrors([...error])
|
|
166
|
+
// }
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}, [validate, dataSource]);
|
|
117
170
|
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
118
171
|
const cacheColumns = columnVirtualizer.measurementsCache;
|
|
119
172
|
const rightCols = table.getState().columnPinning.right?.length ? [...cacheColumns].slice(-(table.getState().columnPinning.right?.length ?? 0)) : [];
|
|
@@ -194,8 +247,41 @@ const TableContainerEdit = props => {
|
|
|
194
247
|
// Copy to clipboard
|
|
195
248
|
navigator.clipboard.writeText(tsv).then(() => {});
|
|
196
249
|
}, [startCell, endCell, table]);
|
|
250
|
+
const triggerChangeData = _react.default.useCallback(newData => {
|
|
251
|
+
onDataChange?.(newData);
|
|
252
|
+
}, [onDataChange]);
|
|
253
|
+
const triggerPaste = _react.default.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
|
|
254
|
+
const handlePasteCallback = callbackData => {
|
|
255
|
+
const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...dataSource]), callbackData);
|
|
256
|
+
const rs = (0, _utils.unFlattenData)(rsFilterData);
|
|
257
|
+
triggerChangeData(rs);
|
|
258
|
+
};
|
|
259
|
+
if (onCellPaste && onCellPaste.onPasted) {
|
|
260
|
+
if (onCellPaste.onPasted.length > 1) {
|
|
261
|
+
// có callback
|
|
262
|
+
onCellPaste.onPasted({
|
|
263
|
+
pasteData: pastedRows,
|
|
264
|
+
copyRows,
|
|
265
|
+
type: 'onPaste',
|
|
266
|
+
data: dataSource,
|
|
267
|
+
pastedColumns: pastedColumnsArray
|
|
268
|
+
}, handlePasteCallback);
|
|
269
|
+
} else {
|
|
270
|
+
// không có callback
|
|
271
|
+
onCellPaste.onPasted({
|
|
272
|
+
pasteData: pastedRows,
|
|
273
|
+
type: 'onPaste',
|
|
274
|
+
copyRows,
|
|
275
|
+
data: dataSource,
|
|
276
|
+
pastedColumns: pastedColumnsArray
|
|
277
|
+
}, handlePasteCallback);
|
|
278
|
+
triggerChangeData(newData);
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
triggerChangeData(newData);
|
|
282
|
+
}
|
|
283
|
+
}, [dataSource, onCellPaste, triggerChangeData]);
|
|
197
284
|
const handlePasted = _react.default.useCallback(pasteData => {
|
|
198
|
-
console.log('ooooooo');
|
|
199
285
|
if (!startCell) {
|
|
200
286
|
return;
|
|
201
287
|
}
|
|
@@ -280,7 +366,6 @@ const TableContainerEdit = props => {
|
|
|
280
366
|
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
281
367
|
const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...originData]), newData);
|
|
282
368
|
const rs = (0, _utils.unFlattenData)(rsFilterData);
|
|
283
|
-
console.log('2');
|
|
284
369
|
triggerPaste?.(pastedRows, pastedColumnsArray, rs, []);
|
|
285
370
|
} else {
|
|
286
371
|
// const parent = findItemByKey(dataSource, rowKey as any, record.parentId)
|
|
@@ -338,7 +423,6 @@ const TableContainerEdit = props => {
|
|
|
338
423
|
}; // item đã được filter
|
|
339
424
|
|
|
340
425
|
const newDataSource = (0, _utils.updateArrayByKey)(originData, newRowData, rowKey);
|
|
341
|
-
console.log('1');
|
|
342
426
|
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
|
|
343
427
|
}
|
|
344
428
|
}, [dataSource, format, onCellPaste?.maxRowsPaste, originData, rowKey, startCell, table, triggerPaste]);
|
|
@@ -383,38 +467,25 @@ const TableContainerEdit = props => {
|
|
|
383
467
|
}
|
|
384
468
|
}, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
|
|
385
469
|
_react.default.useEffect(() => {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
// }
|
|
395
|
-
// };
|
|
396
|
-
|
|
397
|
-
// window.addEventListener('keydown', handleKeyDown);
|
|
398
|
-
// return () => window.removeEventListener('keydown', handleKeyDown);
|
|
470
|
+
const handleKeyDown = e => {
|
|
471
|
+
if (e.ctrlKey && e.key === 'c' && startCell && endCell) {
|
|
472
|
+
e.preventDefault();
|
|
473
|
+
copySelectionToClipboard();
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
477
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
399
478
|
}, [startCell, endCell, table, copySelectionToClipboard]);
|
|
400
479
|
_react.default.useEffect(() => {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
// handlePasteToTable(clipboardText);
|
|
412
|
-
// }
|
|
413
|
-
|
|
414
|
-
// };
|
|
415
|
-
|
|
416
|
-
// window.addEventListener('paste', handlePaste);
|
|
417
|
-
// return () => window.removeEventListener('paste', handlePaste);
|
|
480
|
+
const handlePaste = e => {
|
|
481
|
+
if (startCell) {
|
|
482
|
+
e.preventDefault(); // Chặn hành vi mặc định
|
|
483
|
+
const clipboardText = e.clipboardData?.getData('text/plain') ?? '';
|
|
484
|
+
handlePasteToTable(clipboardText);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
window.addEventListener('paste', handlePaste);
|
|
488
|
+
return () => window.removeEventListener('paste', handlePaste);
|
|
418
489
|
}, [startCell, endCell, table, handlePasteToTable]);
|
|
419
490
|
_react.default.useEffect(() => {
|
|
420
491
|
const handleClickOutside = event => {
|
|
@@ -429,11 +500,9 @@ const TableContainerEdit = props => {
|
|
|
429
500
|
const isInsideToolbar = element.closest(`.ui-rc-toolbar-selection-overflow-item`) && itemContainer;
|
|
430
501
|
const isInsideHeader = itemHeader && itemHeader.contains(event.target);
|
|
431
502
|
if (isInsideContainer || isInsideToolbar || isInsideHeader || isInsideContainerContext) {
|
|
432
|
-
console.log('55555');
|
|
433
503
|
return;
|
|
434
504
|
}
|
|
435
505
|
if (containerRef.current && tableBody && !tableBody.contains(event.target)) {
|
|
436
|
-
console.log('55555');
|
|
437
506
|
if (editingKey) {
|
|
438
507
|
onBlur?.(dataSource);
|
|
439
508
|
}
|
|
@@ -462,14 +531,14 @@ const TableContainerEdit = props => {
|
|
|
462
531
|
if (totalHeight && topToolbarRef.current && bottomToolbarRef.current) {
|
|
463
532
|
settableHeight(totalHeight - topToolbarRef.current.offsetHeight - bottomToolbarRef.current.offsetHeight);
|
|
464
533
|
}
|
|
465
|
-
}, [id, height]);
|
|
534
|
+
}, [id, height, editAble]);
|
|
466
535
|
const {
|
|
467
536
|
control,
|
|
468
537
|
handleSubmit,
|
|
469
538
|
setValue,
|
|
470
539
|
// trigger,
|
|
471
540
|
getValues,
|
|
472
|
-
|
|
541
|
+
reset,
|
|
473
542
|
formState: {
|
|
474
543
|
errors
|
|
475
544
|
}
|
|
@@ -491,7 +560,7 @@ const TableContainerEdit = props => {
|
|
|
491
560
|
const index = (0, _utils.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
|
|
492
561
|
const rs = (0, _utils.updateArrayByKey)(newData, row, rowKey);
|
|
493
562
|
if (index > -1) {
|
|
494
|
-
triggerChangeData?.(rs
|
|
563
|
+
triggerChangeData?.(rs);
|
|
495
564
|
}
|
|
496
565
|
} catch (errInfo) {
|
|
497
566
|
console.log('Validate Failed:', errInfo);
|
|
@@ -575,7 +644,7 @@ const TableContainerEdit = props => {
|
|
|
575
644
|
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
576
645
|
setMergedFilterKeys?.(rs);
|
|
577
646
|
const newData = dataSource.concat(newRows);
|
|
578
|
-
triggerChangeData?.(newData
|
|
647
|
+
triggerChangeData?.(newData);
|
|
579
648
|
}
|
|
580
649
|
}, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
|
|
581
650
|
const handleDuplicate = _react.default.useCallback(() => {
|
|
@@ -607,7 +676,7 @@ const TableContainerEdit = props => {
|
|
|
607
676
|
const rs = (0, _utils.updateOrInsert)(originData, rsFilter);
|
|
608
677
|
// const rs2 = mergeWithFilter(originData, rsFilter)
|
|
609
678
|
|
|
610
|
-
triggerChangeData?.(rs
|
|
679
|
+
triggerChangeData?.(rs);
|
|
611
680
|
}, [dataSource, focusedCell, originData, rowKey, table, triggerChangeData]);
|
|
612
681
|
|
|
613
682
|
// thêm n dòng bên trên
|
|
@@ -640,7 +709,7 @@ const TableContainerEdit = props => {
|
|
|
640
709
|
setMergedFilterKeys?.(rs);
|
|
641
710
|
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
642
711
|
newData.splice(index, 0, ...newRows);
|
|
643
|
-
triggerChangeData?.(newData
|
|
712
|
+
triggerChangeData?.(newData);
|
|
644
713
|
} else {
|
|
645
714
|
const newData = [...originData];
|
|
646
715
|
const parent = (0, _utils.findItemByKey)(newData, rowKey, record.parentId);
|
|
@@ -666,7 +735,7 @@ const TableContainerEdit = props => {
|
|
|
666
735
|
children: childData
|
|
667
736
|
};
|
|
668
737
|
const newDataSource = (0, _utils.updateArrayByKey)(newData, newRowData, rowKey);
|
|
669
|
-
triggerChangeData?.(newDataSource
|
|
738
|
+
triggerChangeData?.(newDataSource);
|
|
670
739
|
}
|
|
671
740
|
}
|
|
672
741
|
}, [defaultValue, mergedFilterKeys, originData, rowKey, rowsFocus, setMergedFilterKeys, table, triggerChangeData]);
|
|
@@ -704,7 +773,7 @@ const TableContainerEdit = props => {
|
|
|
704
773
|
setMergedFilterKeys?.(rs);
|
|
705
774
|
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
706
775
|
newData.splice(index + 1, 0, ...newRows);
|
|
707
|
-
triggerChangeData?.(newData
|
|
776
|
+
triggerChangeData?.(newData);
|
|
708
777
|
} else {
|
|
709
778
|
const newData = [...originData];
|
|
710
779
|
const parent = (0, _utils.findItemByKey)(newData, rowKey, record.parentId);
|
|
@@ -733,7 +802,7 @@ const TableContainerEdit = props => {
|
|
|
733
802
|
children: childData
|
|
734
803
|
};
|
|
735
804
|
const newDataSource = (0, _utils.updateArrayByKey)(newData, newRowData, rowKey);
|
|
736
|
-
triggerChangeData?.(newDataSource
|
|
805
|
+
triggerChangeData?.(newDataSource);
|
|
737
806
|
}
|
|
738
807
|
}
|
|
739
808
|
}, [defaultValue, table, focusedCell?.rowId, originData, mergedFilterKeys, setMergedFilterKeys, triggerChangeData, rowKey]);
|
|
@@ -771,7 +840,7 @@ const TableContainerEdit = props => {
|
|
|
771
840
|
const rs = mergedFilterKeys ? [...mergedFilterKeys, rowId] : [rowId];
|
|
772
841
|
setMergedFilterKeys?.(rs);
|
|
773
842
|
const newDataSource = (0, _utils.updateArrayByKey)(newData, newElement, rowKey);
|
|
774
|
-
triggerChangeData?.(newDataSource
|
|
843
|
+
triggerChangeData?.(newDataSource);
|
|
775
844
|
}
|
|
776
845
|
setTimeout(() => {
|
|
777
846
|
const row = table.getRowModel().rows.find(it => it.id === focusedCell?.rowId);
|
|
@@ -798,11 +867,11 @@ const TableContainerEdit = props => {
|
|
|
798
867
|
const filterData = (0, _utils.flattenArray)([...originData]);
|
|
799
868
|
const rs = filterData.filter(it => !rowsFocus.includes(it[rowKey]));
|
|
800
869
|
const newDaa = (0, _utils.unFlattenData)(rs);
|
|
801
|
-
triggerChangeData?.([...newDaa]
|
|
870
|
+
triggerChangeData?.([...newDaa]);
|
|
802
871
|
}
|
|
803
872
|
}, [originData, rowKey, rowsFocus, triggerChangeData]);
|
|
804
873
|
const handleDeleteAll = _react.default.useCallback(() => {
|
|
805
|
-
triggerChangeData?.([]
|
|
874
|
+
triggerChangeData?.([]);
|
|
806
875
|
}, [triggerChangeData]);
|
|
807
876
|
const handleDeleteContent = _react.default.useCallback(() => {
|
|
808
877
|
if (startCell && endCell) {
|
|
@@ -823,7 +892,7 @@ const TableContainerEdit = props => {
|
|
|
823
892
|
return updatedRow;
|
|
824
893
|
});
|
|
825
894
|
const newData = (0, _utils.unFlattenData)(rs);
|
|
826
|
-
triggerChangeData?.([...newData]
|
|
895
|
+
triggerChangeData?.([...newData]);
|
|
827
896
|
}
|
|
828
897
|
}, [dataSource, endCell, rangeState, startCell, table, triggerChangeData]);
|
|
829
898
|
const toolbarItemsBottom = _react.default.useMemo(() => {
|
|
@@ -1038,7 +1107,7 @@ const TableContainerEdit = props => {
|
|
|
1038
1107
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
1039
1108
|
ref: containerRef,
|
|
1040
1109
|
id: id
|
|
1041
|
-
}, (showToolbar !== false || fullScreen !== false) && /*#__PURE__*/_react.default.createElement("div", {
|
|
1110
|
+
}, (showToolbar !== false || fullScreen !== false || showColumnChoose) && /*#__PURE__*/_react.default.createElement("div", {
|
|
1042
1111
|
ref: topToolbarRef,
|
|
1043
1112
|
className: (0, _classnames.default)(`${prefix}-grid-top-toolbar`, {})
|
|
1044
1113
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -1084,10 +1153,12 @@ const TableContainerEdit = props => {
|
|
|
1084
1153
|
// @ts-ignore
|
|
1085
1154
|
`${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
|
|
1086
1155
|
}, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, showColumnChoose && /*#__PURE__*/_react.default.createElement(_ColumnsChoose.ColumnsChoose, {
|
|
1087
|
-
columns:
|
|
1156
|
+
columns: columns,
|
|
1157
|
+
originColumns: propsColumns,
|
|
1088
1158
|
t: t,
|
|
1089
|
-
columnsGroup:
|
|
1090
|
-
|
|
1159
|
+
columnsGroup: groupColumns,
|
|
1160
|
+
triggerChangeColumns: triggerChangeColumns,
|
|
1161
|
+
columnHidden: columnHidden
|
|
1091
1162
|
})))), /*#__PURE__*/_react.default.createElement("form", {
|
|
1092
1163
|
onSubmit: handleSubmit(onSubmit)
|
|
1093
1164
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -1106,11 +1177,14 @@ const TableContainerEdit = props => {
|
|
|
1106
1177
|
}
|
|
1107
1178
|
}, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
|
|
1108
1179
|
value: {
|
|
1180
|
+
locale,
|
|
1109
1181
|
prefix,
|
|
1110
1182
|
id,
|
|
1111
1183
|
rowKey,
|
|
1112
1184
|
format,
|
|
1113
1185
|
expandable,
|
|
1186
|
+
expanded,
|
|
1187
|
+
setExpanded,
|
|
1114
1188
|
dataSource,
|
|
1115
1189
|
originData,
|
|
1116
1190
|
wrapSettings,
|
|
@@ -1146,10 +1220,12 @@ const TableContainerEdit = props => {
|
|
|
1146
1220
|
errors,
|
|
1147
1221
|
getValues,
|
|
1148
1222
|
setValue,
|
|
1223
|
+
reset,
|
|
1149
1224
|
handleCellChange,
|
|
1150
1225
|
triggerPaste,
|
|
1151
1226
|
handleDeleteContent,
|
|
1152
|
-
handleAddMulti
|
|
1227
|
+
handleAddMulti,
|
|
1228
|
+
dataErrors
|
|
1153
1229
|
}
|
|
1154
1230
|
}, /*#__PURE__*/_react.default.createElement("table", {
|
|
1155
1231
|
// className={`${prefix}-grid-container`}
|
|
@@ -1177,6 +1253,13 @@ const TableContainerEdit = props => {
|
|
|
1177
1253
|
commandClick: commandClick,
|
|
1178
1254
|
editAble: editAble,
|
|
1179
1255
|
contextMenuItems: contextMenuItems
|
|
1256
|
+
}), summary && /*#__PURE__*/_react.default.createElement(_TableFooter.default, {
|
|
1257
|
+
columnVirtualizer: columnVirtualizer,
|
|
1258
|
+
table: table,
|
|
1259
|
+
virtualPaddingLeft: virtualPaddingLeft,
|
|
1260
|
+
virtualPaddingRight: virtualPaddingRight,
|
|
1261
|
+
fixedLeftColumns: fixedLeftColumns,
|
|
1262
|
+
fixedRightColumns: fixedRightColumns
|
|
1180
1263
|
}))))), /*#__PURE__*/_react.default.createElement("div", {
|
|
1181
1264
|
ref: bottomToolbarRef
|
|
1182
1265
|
}, toolbarItemsBottom && toolbarItemsBottom.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -1199,7 +1282,7 @@ const TableContainerEdit = props => {
|
|
|
1199
1282
|
}
|
|
1200
1283
|
})), pagination && /*#__PURE__*/_react.default.createElement(_pagination.default
|
|
1201
1284
|
// style={{padding: '0.75rem 1rem'}}
|
|
1202
|
-
, {
|
|
1285
|
+
, (0, _extends2.default)({}, pagination, {
|
|
1203
1286
|
rootClassName: 'pagination-template',
|
|
1204
1287
|
showSizeChanger: true,
|
|
1205
1288
|
responsive: true,
|
|
@@ -1214,7 +1297,14 @@ const TableContainerEdit = props => {
|
|
|
1214
1297
|
table.setPageIndex(page - 1);
|
|
1215
1298
|
table.setPageSize(pageSize);
|
|
1216
1299
|
}
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1300
|
+
},
|
|
1301
|
+
showTotal: (total, range) => `${(0, _reactNumericComponent.numericFormatter)((range[0] ?? 0).toString(), {
|
|
1302
|
+
thousandSeparator: '.'
|
|
1303
|
+
})}-${(0, _reactNumericComponent.numericFormatter)((range[1] ?? 0).toString(), {
|
|
1304
|
+
thousandSeparator: '.'
|
|
1305
|
+
})} / ${(0, _reactNumericComponent.numericFormatter)((total ?? 0).toString(), {
|
|
1306
|
+
thousandSeparator: '.'
|
|
1307
|
+
})} items`
|
|
1308
|
+
}))));
|
|
1219
1309
|
};
|
|
1220
1310
|
var _default = exports.default = TableContainerEdit;
|