es-grid-template 1.8.29 → 1.8.31
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/TableContainerEdit.js +8 -3
- package/es/table-component/body/TableBodyCell.js +24 -84
- package/es/table-component/body/TableBodyCellEdit.js +51 -84
- package/es/table-component/header/TableHeadCell2.js +7 -8
- package/es/table-component/hook/useColumns.d.ts +21 -2
- package/es/table-component/hook/useColumns.js +113 -2
- package/es/table-component/hook/utils.d.ts +5 -1
- package/es/table-component/hook/utils.js +40 -0
- package/es/table-component/table/Grid.js +2 -1
- package/es/table-component/type.d.ts +1 -0
- package/lib/table-component/TableContainerEdit.js +8 -3
- package/lib/table-component/body/TableBodyCell.js +24 -84
- package/lib/table-component/body/TableBodyCellEdit.js +51 -84
- package/lib/table-component/header/TableHeadCell2.js +6 -7
- package/lib/table-component/hook/useColumns.d.ts +21 -2
- package/lib/table-component/hook/useColumns.js +114 -2
- package/lib/table-component/hook/utils.d.ts +5 -1
- package/lib/table-component/hook/utils.js +50 -3
- package/lib/table-component/table/Grid.js +2 -1
- package/lib/table-component/type.d.ts +1 -0
- package/package.json +2 -1
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _usehooksTs = require("usehooks-ts");
|
|
10
11
|
var _utils = require("./hook/utils");
|
|
11
12
|
var _reactVirtual = require("@tanstack/react-virtual");
|
|
12
13
|
var _reactHookForm = require("react-hook-form");
|
|
@@ -141,6 +142,7 @@ const TableContainerEdit = props => {
|
|
|
141
142
|
|
|
142
143
|
// //The virtualizers need to know the scrollable container element
|
|
143
144
|
const tableContainerRef = _react.default.useRef(null);
|
|
145
|
+
const [, copy] = (0, _usehooksTs.useCopyToClipboard)();
|
|
144
146
|
|
|
145
147
|
// const columnSizingState = table.getState().columnSizing;
|
|
146
148
|
|
|
@@ -392,7 +394,10 @@ const TableContainerEdit = props => {
|
|
|
392
394
|
const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
|
|
393
395
|
|
|
394
396
|
// Copy to clipboard
|
|
395
|
-
navigator.clipboard.writeText(tsv).then(() => {
|
|
397
|
+
// navigator.clipboard.writeText(tsv).then(() => {
|
|
398
|
+
// });
|
|
399
|
+
|
|
400
|
+
copy(tsv).then(() => {}).catch(() => {});
|
|
396
401
|
}, [startCell, endCell, table]);
|
|
397
402
|
const triggerChangeData = _react.default.useCallback(newData => {
|
|
398
403
|
onDataChange?.(newData);
|
|
@@ -621,14 +626,14 @@ const TableContainerEdit = props => {
|
|
|
621
626
|
}, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
|
|
622
627
|
_react.default.useEffect(() => {
|
|
623
628
|
const handleKeyDown = e => {
|
|
624
|
-
if (e.ctrlKey && e.key === 'c' && startCell && endCell) {
|
|
629
|
+
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
|
|
625
630
|
e.preventDefault();
|
|
626
631
|
copySelectionToClipboard();
|
|
627
632
|
}
|
|
628
633
|
};
|
|
629
634
|
window.addEventListener('keydown', handleKeyDown);
|
|
630
635
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
631
|
-
}, [startCell, endCell, table, copySelectionToClipboard]);
|
|
636
|
+
}, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
|
|
632
637
|
_react.default.useEffect(() => {
|
|
633
638
|
const handlePaste = e => {
|
|
634
639
|
if (startCell && !editingKey) {
|
|
@@ -14,20 +14,7 @@ var _Checkbox = _interopRequireDefault(require("rc-master-ui/lib/checkbox/Checkb
|
|
|
14
14
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
15
|
var _react = _interopRequireDefault(require("react"));
|
|
16
16
|
var _useContext = require("../useContext");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// const { parrents, cell } = props
|
|
20
|
-
// return (
|
|
21
|
-
// <span className="ui-rc_cell-content">
|
|
22
|
-
// {parrents.map((pr) => {
|
|
23
|
-
// return `${pr.index + 1}.`;
|
|
24
|
-
// })}
|
|
25
|
-
|
|
26
|
-
// {cell.row.index + 1}
|
|
27
|
-
// </span>
|
|
28
|
-
// )
|
|
29
|
-
// }
|
|
30
|
-
|
|
17
|
+
var _useColumns = require("../hook/useColumns");
|
|
31
18
|
const renderCellIndex = props => {
|
|
32
19
|
const {
|
|
33
20
|
parrents,
|
|
@@ -100,6 +87,8 @@ const renderSelection = args => {
|
|
|
100
87
|
setIsSelectionChange,
|
|
101
88
|
isSelectionChange
|
|
102
89
|
} = args;
|
|
90
|
+
const checked = selectionSettings?.checkStrictly ? row.getIsSelected() : row.getIsSelected() || row.getIsAllSubRowsSelected();
|
|
91
|
+
const indeterminate = selectionSettings?.type == 'single' || selectionSettings?.checkStrictly ? false : row.getIsSomeSelected() && selectionSettings && selectionSettings.mode === 'checkbox' || row.getIsSomeSelected();
|
|
103
92
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
104
93
|
style: {}
|
|
105
94
|
}, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -136,35 +125,16 @@ const renderSelection = args => {
|
|
|
136
125
|
})) : /*#__PURE__*/_react.default.createElement("span", {
|
|
137
126
|
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
|
|
138
127
|
}))), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_Checkbox.default, {
|
|
139
|
-
checked:
|
|
140
|
-
indeterminate:
|
|
141
|
-
// indeterminate={row.getIsSomeSelected() }
|
|
142
|
-
,
|
|
128
|
+
checked: checked,
|
|
129
|
+
indeterminate: indeterminate,
|
|
143
130
|
onChange: e => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
type: 'rowSelected',
|
|
152
|
-
rowData: row.original,
|
|
153
|
-
rowsData: aaa ?? []
|
|
154
|
-
});
|
|
155
|
-
} else {
|
|
156
|
-
const {
|
|
157
|
-
rowsData
|
|
158
|
-
} = isSelectionChange ?? {};
|
|
159
|
-
const abc = rowsData && rowsData.length > 0 ? [...rowsData] : [];
|
|
160
|
-
abc.push(row);
|
|
161
|
-
setIsSelectionChange({
|
|
162
|
-
isChange: true,
|
|
163
|
-
type: 'rowSelected',
|
|
164
|
-
rowData: row.original,
|
|
165
|
-
rowsData: abc
|
|
166
|
-
});
|
|
167
|
-
}
|
|
131
|
+
(0, _useColumns.toggleRowSelection)({
|
|
132
|
+
e,
|
|
133
|
+
cell,
|
|
134
|
+
setIsSelectionChange,
|
|
135
|
+
isSelectionChange,
|
|
136
|
+
selectionSettings
|
|
137
|
+
});
|
|
168
138
|
},
|
|
169
139
|
disabled: !row.getCanSelect()
|
|
170
140
|
})));
|
|
@@ -423,11 +393,7 @@ const TableBodyCell = props => {
|
|
|
423
393
|
if (e.target.firstChild?.clientWidth < e.target.firstChild?.scrollWidth) {
|
|
424
394
|
setIsOpenTooltip(true);
|
|
425
395
|
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// onMouseUp={() => { }}
|
|
429
|
-
,
|
|
430
|
-
|
|
396
|
+
},
|
|
431
397
|
onKeyDown: e => {
|
|
432
398
|
const flatRows = table.getRowModel().flatRows;
|
|
433
399
|
if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
|
|
@@ -492,45 +458,19 @@ const TableBodyCell = props => {
|
|
|
492
458
|
});
|
|
493
459
|
}
|
|
494
460
|
}
|
|
495
|
-
}
|
|
496
|
-
onDoubleClick: () => {},
|
|
497
|
-
onClick: e => {
|
|
498
|
-
if (selectionSettings?.checkboxOnly !== true && cell.row.getCanSelect()) {
|
|
499
|
-
const isInsideCell = e.target.closest(".ui-rc-grid-cell");
|
|
500
|
-
if (isInsideCell) {
|
|
501
|
-
cell.row.getToggleSelectedHandler()(e);
|
|
502
|
-
// setIsSelectionChange({
|
|
503
|
-
// isChange: true,
|
|
504
|
-
// type: 'rowSelected',
|
|
505
|
-
// rowData: cell.row.original,
|
|
506
|
-
// rowsData: []
|
|
507
|
-
// })
|
|
461
|
+
}
|
|
508
462
|
|
|
509
|
-
|
|
510
|
-
|
|
463
|
+
// onDoubleClick={() => { }}
|
|
464
|
+
,
|
|
511
465
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const {
|
|
521
|
-
rowsData
|
|
522
|
-
} = isSelectionChange ?? {};
|
|
523
|
-
const abc = rowsData && rowsData.length > 0 ? [...rowsData] : [];
|
|
524
|
-
abc.push(cell.row);
|
|
525
|
-
setIsSelectionChange({
|
|
526
|
-
isChange: true,
|
|
527
|
-
type: 'rowSelected',
|
|
528
|
-
rowData: cell.row.original,
|
|
529
|
-
rowsData: abc
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
466
|
+
onClick: e => {
|
|
467
|
+
(0, _useColumns.toggleRowSelection)({
|
|
468
|
+
e,
|
|
469
|
+
cell,
|
|
470
|
+
setIsSelectionChange,
|
|
471
|
+
isSelectionChange,
|
|
472
|
+
selectionSettings
|
|
473
|
+
});
|
|
534
474
|
}
|
|
535
475
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
536
476
|
className: (0, _classnames.default)('ui-rc_cell-content', {})
|
|
@@ -16,6 +16,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
16
16
|
var _useContext = require("../useContext");
|
|
17
17
|
var _EditableCell = _interopRequireDefault(require("./EditableCell"));
|
|
18
18
|
var _constant = require("../hook/constant");
|
|
19
|
+
var _useColumns = require("../hook/useColumns");
|
|
19
20
|
// import { nonActionColumn } from "../hook/constant";
|
|
20
21
|
|
|
21
22
|
// import type { Dispatch, SetStateAction } from "react";
|
|
@@ -106,7 +107,9 @@ const renderSelection = args => {
|
|
|
106
107
|
}
|
|
107
108
|
}, /*#__PURE__*/_react.default.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/_react.default.createElement("button", {
|
|
108
109
|
// onClick: row.getToggleExpandedHandler(),
|
|
109
|
-
onClick:
|
|
110
|
+
onClick: e => {
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
e.preventDefault();
|
|
110
113
|
const keys = Object.keys(expanded);
|
|
111
114
|
// @ts-ignore
|
|
112
115
|
const tmp = {
|
|
@@ -136,32 +139,48 @@ const renderSelection = args => {
|
|
|
136
139
|
checked: row.getIsSelected() || row.getIsAllSubRowsSelected(),
|
|
137
140
|
indeterminate: row.getIsSomeSelected() && selectionSettings && selectionSettings.mode === 'checkbox' && selectionSettings.type !== 'single'
|
|
138
141
|
// indeterminate={row.getIsSomeSelected() }
|
|
142
|
+
// onChange={(e) => {
|
|
143
|
+
|
|
144
|
+
// row.getToggleSelectedHandler()(e)
|
|
145
|
+
|
|
146
|
+
// if (row.getIsSelected()) { // nếu đã chọn
|
|
147
|
+
|
|
148
|
+
// const aaa = isSelectionChange?.rowsData.filter((it) => it.id !== row.id)
|
|
149
|
+
|
|
150
|
+
// setIsSelectionChange({
|
|
151
|
+
// isChange: true,
|
|
152
|
+
// type: 'rowSelected',
|
|
153
|
+
// rowData: row.original,
|
|
154
|
+
// rowsData: aaa ?? []
|
|
155
|
+
// })
|
|
156
|
+
|
|
157
|
+
// } else {
|
|
158
|
+
|
|
159
|
+
// const { rowsData } = isSelectionChange ?? {}
|
|
160
|
+
|
|
161
|
+
// const abc = rowsData && rowsData.length > 0 ? [...rowsData] : []
|
|
162
|
+
|
|
163
|
+
// abc.push(row)
|
|
164
|
+
|
|
165
|
+
// setIsSelectionChange({
|
|
166
|
+
// isChange: true,
|
|
167
|
+
// type: 'rowSelected',
|
|
168
|
+
// rowData: row.original,
|
|
169
|
+
// rowsData: abc
|
|
170
|
+
// })
|
|
171
|
+
// }
|
|
172
|
+
|
|
173
|
+
// }}
|
|
139
174
|
,
|
|
140
|
-
onChange: e => {
|
|
141
|
-
row.getToggleSelectedHandler()(e);
|
|
142
|
-
if (row.getIsSelected()) {
|
|
143
|
-
// nếu đã chọn
|
|
144
175
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
const {
|
|
154
|
-
rowsData
|
|
155
|
-
} = isSelectionChange ?? {};
|
|
156
|
-
const abc = rowsData && rowsData.length > 0 ? [...rowsData] : [];
|
|
157
|
-
abc.push(row);
|
|
158
|
-
setIsSelectionChange({
|
|
159
|
-
isChange: true,
|
|
160
|
-
type: 'rowSelected',
|
|
161
|
-
rowData: row.original,
|
|
162
|
-
rowsData: abc
|
|
163
|
-
});
|
|
164
|
-
}
|
|
176
|
+
onChange: e => {
|
|
177
|
+
(0, _useColumns.toggleRowSelection)({
|
|
178
|
+
e,
|
|
179
|
+
cell,
|
|
180
|
+
setIsSelectionChange,
|
|
181
|
+
isSelectionChange,
|
|
182
|
+
selectionSettings
|
|
183
|
+
});
|
|
165
184
|
},
|
|
166
185
|
disabled: !row.getCanSelect()
|
|
167
186
|
})));
|
|
@@ -829,7 +848,9 @@ const TableBodyCellEdit = props => {
|
|
|
829
848
|
}
|
|
830
849
|
}, /*#__PURE__*/_react.default.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/_react.default.createElement("button", {
|
|
831
850
|
// onClick: row.getToggleExpandedHandler(),
|
|
832
|
-
onClick:
|
|
851
|
+
onClick: e => {
|
|
852
|
+
e.stopPropagation();
|
|
853
|
+
e.preventDefault();
|
|
833
854
|
const keys = Object.keys(expanded);
|
|
834
855
|
// @ts-ignore
|
|
835
856
|
const tmp = {
|
|
@@ -906,40 +927,7 @@ const TableBodyCellEdit = props => {
|
|
|
906
927
|
// maxWidth: cell.column.getSize(),
|
|
907
928
|
...(0, _utils.getCommonPinningStyles)(cell.column)
|
|
908
929
|
}
|
|
909
|
-
}, cell.column.
|
|
910
|
-
className: "ui-rc-table-row-expand-trigger",
|
|
911
|
-
style: {
|
|
912
|
-
paddingLeft: `${cell.row.depth * 25}px`
|
|
913
|
-
}
|
|
914
|
-
}, /*#__PURE__*/_react.default.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/_react.default.createElement("button", {
|
|
915
|
-
// onClick: row.getToggleExpandedHandler(),
|
|
916
|
-
onClick: () => {
|
|
917
|
-
const keys = Object.keys(expanded);
|
|
918
|
-
// @ts-ignore
|
|
919
|
-
const tmp = {
|
|
920
|
-
...expanded
|
|
921
|
-
};
|
|
922
|
-
if (keys.includes(cell.row.id)) {
|
|
923
|
-
delete tmp[cell.row.id];
|
|
924
|
-
setExpanded(tmp);
|
|
925
|
-
} else {
|
|
926
|
-
setExpanded(old => ({
|
|
927
|
-
...old,
|
|
928
|
-
[cell.row.id]: true
|
|
929
|
-
}));
|
|
930
|
-
}
|
|
931
|
-
},
|
|
932
|
-
style: {
|
|
933
|
-
cursor: "pointer"
|
|
934
|
-
},
|
|
935
|
-
className: "ui-rc-table-row-expand"
|
|
936
|
-
}, cell.row.getIsExpanded() ? /*#__PURE__*/_react.default.createElement("span", {
|
|
937
|
-
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded"
|
|
938
|
-
}) : /*#__PURE__*/_react.default.createElement("span", {
|
|
939
|
-
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
|
|
940
|
-
})) : /*#__PURE__*/_react.default.createElement("span", {
|
|
941
|
-
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
|
|
942
|
-
}))), cell.column.id === "selection_column" && renderSelection({
|
|
930
|
+
}, cell.column.id === "selection_column" && renderSelection({
|
|
943
931
|
cell,
|
|
944
932
|
table,
|
|
945
933
|
selectionSettings,
|
|
@@ -1035,27 +1023,8 @@ const TableBodyCellEdit = props => {
|
|
|
1035
1023
|
setEditingKey?.('');
|
|
1036
1024
|
reset?.();
|
|
1037
1025
|
});
|
|
1038
|
-
|
|
1039
|
-
// const currentEditColumn = table.getVisibleFlatColumns().find((it) => it.id === focusedCell?.colId)
|
|
1040
|
-
|
|
1041
|
-
// if ()
|
|
1042
|
-
|
|
1043
|
-
// handleChange()
|
|
1044
|
-
// setEditingKey?.('')
|
|
1045
|
-
// reset?.()
|
|
1046
1026
|
}
|
|
1047
|
-
|
|
1048
|
-
// reset?.()
|
|
1049
1027
|
}
|
|
1050
|
-
|
|
1051
|
-
// if (record[rowKey] !== editingKey) {
|
|
1052
|
-
|
|
1053
|
-
// setTimeout(() => {
|
|
1054
|
-
// // setEditingKey?.('')
|
|
1055
|
-
// reset?.()
|
|
1056
|
-
// })
|
|
1057
|
-
|
|
1058
|
-
// }
|
|
1059
1028
|
},
|
|
1060
1029
|
onMouseEnter: () => handleMouseEnter(cell.row.id, cell.column.id),
|
|
1061
1030
|
onMouseUp: e => handleMouseUp(e),
|
|
@@ -1119,10 +1088,6 @@ const TableBodyCellEdit = props => {
|
|
|
1119
1088
|
handleChange();
|
|
1120
1089
|
setEditingKey?.('');
|
|
1121
1090
|
reset?.();
|
|
1122
|
-
|
|
1123
|
-
// setTimeout(() => {
|
|
1124
|
-
|
|
1125
|
-
// })
|
|
1126
1091
|
}
|
|
1127
1092
|
}
|
|
1128
1093
|
}
|
|
@@ -1152,7 +1117,9 @@ const TableBodyCellEdit = props => {
|
|
|
1152
1117
|
}
|
|
1153
1118
|
}, /*#__PURE__*/_react.default.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/_react.default.createElement("button", {
|
|
1154
1119
|
// onClick: row.getToggleExpandedHandler(),
|
|
1155
|
-
onClick:
|
|
1120
|
+
onClick: e => {
|
|
1121
|
+
e.stopPropagation();
|
|
1122
|
+
e.preventDefault();
|
|
1156
1123
|
const keys = Object.keys(expanded);
|
|
1157
1124
|
// @ts-ignore
|
|
1158
1125
|
const tmp = {
|
|
@@ -276,10 +276,10 @@ const TableHeadCell2 = props => {
|
|
|
276
276
|
indeterminate: table.getIsSomePageRowsSelected(),
|
|
277
277
|
onChange: e => {
|
|
278
278
|
table.getToggleAllRowsSelectedHandler()(e);
|
|
279
|
-
const
|
|
279
|
+
const prevSelected = isSelectionChange?.rowsData ?? [];
|
|
280
|
+
const allRowsInPage = table.getRowModel().flatRows;
|
|
280
281
|
if (table.getIsAllRowsSelected()) {
|
|
281
|
-
const
|
|
282
|
-
const cc = (0, _utils.excludeItems)(aa, dd);
|
|
282
|
+
const cc = (0, _utils.excludeItems)(prevSelected, allRowsInPage);
|
|
283
283
|
setIsSelectionChange({
|
|
284
284
|
isChange: true,
|
|
285
285
|
type: 'all',
|
|
@@ -287,14 +287,13 @@ const TableHeadCell2 = props => {
|
|
|
287
287
|
rowsData: cc
|
|
288
288
|
});
|
|
289
289
|
} else {
|
|
290
|
-
|
|
291
|
-
const
|
|
292
|
-
const abc = [...aa, ...bb];
|
|
290
|
+
const abc = [...prevSelected, ...allRowsInPage];
|
|
291
|
+
const newSeletedRows = (0, _utils.removeDuplicatesByKey)(abc, 'id');
|
|
293
292
|
setIsSelectionChange({
|
|
294
293
|
isChange: true,
|
|
295
294
|
type: 'all',
|
|
296
295
|
rowData: {},
|
|
297
|
-
rowsData:
|
|
296
|
+
rowsData: newSeletedRows
|
|
298
297
|
});
|
|
299
298
|
}
|
|
300
299
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Dispatch, SetStateAction } from "react";
|
|
2
|
+
import type { ColumnsTable, ColumnTable, IFormat, SelectionSettings } from '../type';
|
|
3
|
+
import type { Cell, ColumnDef } from '@tanstack/react-table';
|
|
3
4
|
export declare const renderValueCell: <T>(column: ColumnTable<T>, value: any, record: T, rowIndex: number, colIndex: number, format?: IFormat, editAble?: boolean) => any;
|
|
4
5
|
export declare function convertToTanStackColumns<T>({ t, columns, format, editAble }: {
|
|
5
6
|
t?: any;
|
|
@@ -7,3 +8,21 @@ export declare function convertToTanStackColumns<T>({ t, columns, format, editAb
|
|
|
7
8
|
format?: IFormat;
|
|
8
9
|
editAble?: boolean;
|
|
9
10
|
}): ColumnDef<T, any>[];
|
|
11
|
+
export type ToggleRow<T> = {
|
|
12
|
+
e: any;
|
|
13
|
+
cell: Cell<T, unknown>;
|
|
14
|
+
selectionSettings?: SelectionSettings;
|
|
15
|
+
isSelectionChange?: {
|
|
16
|
+
isChange: boolean;
|
|
17
|
+
type: string;
|
|
18
|
+
rowData: T;
|
|
19
|
+
rowsData: T[];
|
|
20
|
+
};
|
|
21
|
+
setIsSelectionChange: Dispatch<SetStateAction<{
|
|
22
|
+
isChange: boolean;
|
|
23
|
+
type: string;
|
|
24
|
+
rowData: T;
|
|
25
|
+
rowsData: T[];
|
|
26
|
+
}>>;
|
|
27
|
+
};
|
|
28
|
+
export declare const toggleRowSelection: <T>(props: ToggleRow<T>) => void;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.convertToTanStackColumns = convertToTanStackColumns;
|
|
8
|
-
exports.renderValueCell = void 0;
|
|
8
|
+
exports.toggleRowSelection = exports.renderValueCell = void 0;
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _ControlCheckbox = _interopRequireDefault(require("../components/ControlCheckbox"));
|
|
11
11
|
var _utils = require("./utils");
|
|
@@ -181,4 +181,116 @@ function convertToTanStackColumns({
|
|
|
181
181
|
}
|
|
182
182
|
return newCol;
|
|
183
183
|
});
|
|
184
|
-
}
|
|
184
|
+
}
|
|
185
|
+
const toggleRowSelection = props => {
|
|
186
|
+
const {
|
|
187
|
+
selectionSettings,
|
|
188
|
+
cell,
|
|
189
|
+
isSelectionChange,
|
|
190
|
+
e,
|
|
191
|
+
setIsSelectionChange
|
|
192
|
+
} = props;
|
|
193
|
+
const {
|
|
194
|
+
row
|
|
195
|
+
} = cell;
|
|
196
|
+
const {
|
|
197
|
+
rowsData
|
|
198
|
+
} = isSelectionChange ?? {};
|
|
199
|
+
const prevSelected = rowsData && rowsData.length > 0 ? [...rowsData] : [];
|
|
200
|
+
if (selectionSettings?.checkStrictly || selectionSettings?.type === 'single') {
|
|
201
|
+
row.getToggleSelectedHandler()(e);
|
|
202
|
+
if (row.getIsSelected()) {
|
|
203
|
+
// đã chọn
|
|
204
|
+
|
|
205
|
+
// xóa row ra list selected
|
|
206
|
+
const newRowsSelected = prevSelected.filter(it => it.id !== row.id);
|
|
207
|
+
setIsSelectionChange({
|
|
208
|
+
isChange: true,
|
|
209
|
+
type: 'rowSelected',
|
|
210
|
+
rowData: row.original,
|
|
211
|
+
rowsData: newRowsSelected ?? []
|
|
212
|
+
});
|
|
213
|
+
} else {
|
|
214
|
+
// chưa selected
|
|
215
|
+
|
|
216
|
+
const checkedRows = [...prevSelected, row];
|
|
217
|
+
setIsSelectionChange({
|
|
218
|
+
isChange: true,
|
|
219
|
+
type: 'rowSelected',
|
|
220
|
+
rowData: row.original,
|
|
221
|
+
rowsData: checkedRows
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (row.subRows && row.subRows.length > 0) {
|
|
227
|
+
const allChild = (0, _utils.getAllChildren)(row);
|
|
228
|
+
(0, _utils.toggleRowAndChildren)(row, !row.getIsSelected());
|
|
229
|
+
if (row.getIsSelected()) {
|
|
230
|
+
// đã chọn
|
|
231
|
+
|
|
232
|
+
// const aaa = isSelectionChange?.rowsData.filter((it) => it.id !== row.id)
|
|
233
|
+
|
|
234
|
+
const newRowsSelected = (0, _utils.excludeItems)(prevSelected, [...allChild, row]);
|
|
235
|
+
setIsSelectionChange({
|
|
236
|
+
isChange: true,
|
|
237
|
+
type: 'rowSelected',
|
|
238
|
+
rowData: row.original,
|
|
239
|
+
rowsData: newRowsSelected ?? []
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
// chưa selected
|
|
243
|
+
|
|
244
|
+
let checkedRows = [];
|
|
245
|
+
if (row.subRows && row.subRows.length > 0) {
|
|
246
|
+
checkedRows = [...prevSelected, row, ...allChild];
|
|
247
|
+
} else {
|
|
248
|
+
checkedRows = [...prevSelected, row];
|
|
249
|
+
}
|
|
250
|
+
setIsSelectionChange({
|
|
251
|
+
isChange: true,
|
|
252
|
+
type: 'rowSelected',
|
|
253
|
+
rowData: row.original,
|
|
254
|
+
rowsData: checkedRows
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
row.getToggleSelectedHandler()(e);
|
|
259
|
+
if (row.getIsSelected()) {
|
|
260
|
+
// đã chọn
|
|
261
|
+
|
|
262
|
+
// xóa row ra list selected
|
|
263
|
+
const newRowsSelected = prevSelected.filter(it => it.id !== row.id);
|
|
264
|
+
setIsSelectionChange({
|
|
265
|
+
isChange: true,
|
|
266
|
+
type: 'rowSelected',
|
|
267
|
+
rowData: row.original,
|
|
268
|
+
rowsData: newRowsSelected ?? []
|
|
269
|
+
});
|
|
270
|
+
} else {
|
|
271
|
+
// chưa selected
|
|
272
|
+
|
|
273
|
+
let checkedRows = [];
|
|
274
|
+
const rowParent = row.getParentRow();
|
|
275
|
+
|
|
276
|
+
// console.log(countUnselectedChildren(row))
|
|
277
|
+
|
|
278
|
+
// nếu có cha và cha chưa được chọn và tất cả con đã chọn => thêm row cha vào
|
|
279
|
+
if (rowParent && !rowParent.getIsSelected() && (0, _utils.countUnselectedChildren)(row) === 1) {
|
|
280
|
+
rowParent.toggleSelected(!rowParent.getIsSelected());
|
|
281
|
+
checkedRows = [...prevSelected, row, rowParent];
|
|
282
|
+
} else {
|
|
283
|
+
// chỉ thêm vào row hiện tại
|
|
284
|
+
|
|
285
|
+
checkedRows = [...prevSelected, row];
|
|
286
|
+
}
|
|
287
|
+
setIsSelectionChange({
|
|
288
|
+
isChange: true,
|
|
289
|
+
type: 'rowSelected',
|
|
290
|
+
rowData: row.original,
|
|
291
|
+
rowsData: checkedRows
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
exports.toggleRowSelection = toggleRowSelection;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Table } from "@tanstack/react-table";
|
|
1
|
+
import type { Row, Table } from "@tanstack/react-table";
|
|
2
2
|
import { type Column } from "@tanstack/react-table";
|
|
3
3
|
import type { VirtualItem } from "@tanstack/react-virtual";
|
|
4
4
|
import type { AnyObject, ColumnsTable, ColumnTable, EditType, FilterOperator, IColumnType, IFormat, RangeState, Sorter, TypeFilter } from "./../type";
|
|
@@ -148,3 +148,7 @@ export declare function parseClipboardEvent(e: ClipboardEvent | React.ClipboardE
|
|
|
148
148
|
export declare function arraysEqualIgnoreOrderFast(a: any[], b: any[]): boolean;
|
|
149
149
|
export declare function filterByIds(a: any[], b: any[]): any[];
|
|
150
150
|
export declare function excludeItems(arrayA: any[], arrayB: any[]): any[];
|
|
151
|
+
export declare function getAllChildren(row: any): any;
|
|
152
|
+
export declare function toggleRowAndChildren(row: Row<any>, isSelected?: boolean): void;
|
|
153
|
+
export declare function countUnselectedChildren(row: Row<any>): number;
|
|
154
|
+
export declare function removeDuplicatesByKey(arr: any[], key?: string): any[];
|
|
@@ -19,14 +19,18 @@ exports.convertArrayWithIndent = void 0;
|
|
|
19
19
|
exports.convertColumnsToTreeData = convertColumnsToTreeData;
|
|
20
20
|
exports.convertFilters = exports.convertDayjsToDate = exports.convertDateToDayjs = void 0;
|
|
21
21
|
exports.convertFormat = convertFormat;
|
|
22
|
-
exports.
|
|
22
|
+
exports.convertToObjTrue = exports.convertToObj = exports.convertLabelToTitle = void 0;
|
|
23
|
+
exports.countUnselectedChildren = countUnselectedChildren;
|
|
24
|
+
exports.detectSeparators = exports.customWeekStartEndFormat = void 0;
|
|
23
25
|
exports.excludeItems = excludeItems;
|
|
24
26
|
exports.extendsObject = void 0;
|
|
25
27
|
exports.filterByIds = filterByIds;
|
|
26
28
|
exports.filterDataByColumns = filterDataByColumns;
|
|
27
29
|
exports.findAllChildrenKeys2 = findAllChildrenKeys2;
|
|
28
30
|
exports.findFirst = findFirst;
|
|
29
|
-
exports.
|
|
31
|
+
exports.genPresets = exports.flattenData = exports.flattenArray = exports.flatColumns2 = exports.findItemByKey = void 0;
|
|
32
|
+
exports.getAllChildren = getAllChildren;
|
|
33
|
+
exports.getAllVisibleKeys1 = exports.getAllVisibleKeys = exports.getAllRowKey = void 0;
|
|
30
34
|
exports.getCellsByPosition = getCellsByPosition;
|
|
31
35
|
exports.getColIdsBetween = getColIdsBetween;
|
|
32
36
|
exports.getFormat = exports.getFixedFields = exports.getEditType = exports.getDiffent2Array = exports.getDefaultValue = exports.getDefaultOperator = exports.getDatepickerFormat = exports.getDateRangeFormat = exports.getCommonPinningStyles2 = exports.getCommonPinningStyles = void 0;
|
|
@@ -50,9 +54,12 @@ exports.parseClipboardEvent = parseClipboardEvent;
|
|
|
50
54
|
exports.parseExcelClipboard = parseExcelClipboard;
|
|
51
55
|
exports.parseExcelClipboardText = parseExcelClipboardText;
|
|
52
56
|
exports.parseExcelText = parseExcelText;
|
|
57
|
+
exports.removeDuplicatesByKey = removeDuplicatesByKey;
|
|
53
58
|
exports.sortByType = exports.shouldInclude = exports.removeVietnameseTones = void 0;
|
|
54
59
|
exports.sortData = sortData;
|
|
55
|
-
exports.
|
|
60
|
+
exports.sumSize = void 0;
|
|
61
|
+
exports.toggleRowAndChildren = toggleRowAndChildren;
|
|
62
|
+
exports.updateArrayByKey = exports.unFlattenData = void 0;
|
|
56
63
|
exports.updateColumnWidthsRecursive = updateColumnWidthsRecursive;
|
|
57
64
|
exports.updateColumns1 = void 0;
|
|
58
65
|
exports.updateOrInsert = updateOrInsert;
|
|
@@ -2287,4 +2294,44 @@ function excludeItems(arrayA, arrayB) {
|
|
|
2287
2294
|
|
|
2288
2295
|
// Lọc A, chỉ giữ lại phần tử không có trong B
|
|
2289
2296
|
return arrayA.filter(item => !idsInB.has(item.id));
|
|
2297
|
+
}
|
|
2298
|
+
function getAllChildren(row) {
|
|
2299
|
+
const children = row.subRows ?? [];
|
|
2300
|
+
return children.reduce((acc, child) => {
|
|
2301
|
+
return acc.concat(child, getAllChildren(child));
|
|
2302
|
+
}, []);
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
// export function toggleSelectAllChildren(row: any) {
|
|
2306
|
+
// const children = row.subRows ?? [];
|
|
2307
|
+
|
|
2308
|
+
// return children.reduce((acc: any, child: any) => {
|
|
2309
|
+
// return acc.concat(child, getAllChildren(child));
|
|
2310
|
+
// }, []);
|
|
2311
|
+
// }
|
|
2312
|
+
|
|
2313
|
+
function toggleRowAndChildren(row, isSelected) {
|
|
2314
|
+
// Toggle chính row hiện tại
|
|
2315
|
+
row.toggleSelected(isSelected);
|
|
2316
|
+
|
|
2317
|
+
// Nếu có subRows thì gọi đệ quy
|
|
2318
|
+
if (row.subRows && row.subRows.length > 0) {
|
|
2319
|
+
row.subRows.forEach(subRow => toggleRowAndChildren(subRow, isSelected));
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
function countUnselectedChildren(row) {
|
|
2323
|
+
const parent = row.getParentRow();
|
|
2324
|
+
if (!parent) return 0; // Không có cha thì return 0
|
|
2325
|
+
|
|
2326
|
+
const unselectedCount = parent.subRows.filter(child => !child.getIsSelected()).length;
|
|
2327
|
+
return unselectedCount;
|
|
2328
|
+
}
|
|
2329
|
+
function removeDuplicatesByKey(arr, key = 'id') {
|
|
2330
|
+
const map = new Map();
|
|
2331
|
+
for (const item of arr) {
|
|
2332
|
+
if (!map.has(item[key])) {
|
|
2333
|
+
map.set(item[key], item);
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
return Array.from(map.values());
|
|
2290
2337
|
}
|
|
@@ -192,7 +192,7 @@ const Grid = props => {
|
|
|
192
192
|
// ...prev,
|
|
193
193
|
// isChange: false
|
|
194
194
|
// }))
|
|
195
|
-
setRowSelection(
|
|
195
|
+
// setRowSelection(convertToObjTrue(mergedSelectedKeys))
|
|
196
196
|
}
|
|
197
197
|
}, [mergedSelectedKeys]);
|
|
198
198
|
_react.default.useEffect(() => {
|
|
@@ -206,6 +206,7 @@ const Grid = props => {
|
|
|
206
206
|
|
|
207
207
|
// const ssss = dataTable.filter(it => ids.includes(it.id)) // lấy rowsData của trang hiện tại
|
|
208
208
|
const ssss = (0, _utils.filterByIds)(ids, isSelectionChange.rowsData ?? []); // lấy rowsData của trang hiện tại
|
|
209
|
+
// const ssss = (isSelectionChange.rowsData ?? []) as any[] // lấy rowsData của trang hiện tại
|
|
209
210
|
|
|
210
211
|
const rs = ssss.map(it => it.original);
|
|
211
212
|
// const rs = allRows.map(it => it.original)
|