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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import React, { Fragment } from "react";
|
|
3
|
+
import { useCopyToClipboard } from 'usehooks-ts';
|
|
3
4
|
import { checkDecimalSeparator, checkThousandSeparator, detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween, getDefaultValue, getFormat, getRowIdsBetween, getSelectedCellMatrix, isEditable, isFormattedNumber, newGuid, parseExcelClipboardText, sumSize,
|
|
4
5
|
// sumSize,
|
|
5
6
|
unFlattenData, updateArrayByKey, updateColumnWidthsRecursive, updateOrInsert } from "./hook/utils";
|
|
@@ -134,6 +135,7 @@ const TableContainerEdit = props => {
|
|
|
134
135
|
|
|
135
136
|
// //The virtualizers need to know the scrollable container element
|
|
136
137
|
const tableContainerRef = React.useRef(null);
|
|
138
|
+
const [, copy] = useCopyToClipboard();
|
|
137
139
|
|
|
138
140
|
// const columnSizingState = table.getState().columnSizing;
|
|
139
141
|
|
|
@@ -385,7 +387,10 @@ const TableContainerEdit = props => {
|
|
|
385
387
|
const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
|
|
386
388
|
|
|
387
389
|
// Copy to clipboard
|
|
388
|
-
navigator.clipboard.writeText(tsv).then(() => {
|
|
390
|
+
// navigator.clipboard.writeText(tsv).then(() => {
|
|
391
|
+
// });
|
|
392
|
+
|
|
393
|
+
copy(tsv).then(() => {}).catch(() => {});
|
|
389
394
|
}, [startCell, endCell, table]);
|
|
390
395
|
const triggerChangeData = React.useCallback(newData => {
|
|
391
396
|
onDataChange?.(newData);
|
|
@@ -614,14 +619,14 @@ const TableContainerEdit = props => {
|
|
|
614
619
|
}, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
|
|
615
620
|
React.useEffect(() => {
|
|
616
621
|
const handleKeyDown = e => {
|
|
617
|
-
if (e.ctrlKey && e.key === 'c' && startCell && endCell) {
|
|
622
|
+
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
|
|
618
623
|
e.preventDefault();
|
|
619
624
|
copySelectionToClipboard();
|
|
620
625
|
}
|
|
621
626
|
};
|
|
622
627
|
window.addEventListener('keydown', handleKeyDown);
|
|
623
628
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
624
|
-
}, [startCell, endCell, table, copySelectionToClipboard]);
|
|
629
|
+
}, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
|
|
625
630
|
React.useEffect(() => {
|
|
626
631
|
const handlePaste = e => {
|
|
627
632
|
if (startCell && !editingKey) {
|
|
@@ -7,20 +7,7 @@ import Checkbox from "rc-master-ui/es/checkbox/Checkbox";
|
|
|
7
7
|
import classNames from "classnames";
|
|
8
8
|
import React from "react";
|
|
9
9
|
import { TableContext } from "../useContext";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// const { parrents, cell } = props
|
|
13
|
-
// return (
|
|
14
|
-
// <span className="ui-rc_cell-content">
|
|
15
|
-
// {parrents.map((pr) => {
|
|
16
|
-
// return `${pr.index + 1}.`;
|
|
17
|
-
// })}
|
|
18
|
-
|
|
19
|
-
// {cell.row.index + 1}
|
|
20
|
-
// </span>
|
|
21
|
-
// )
|
|
22
|
-
// }
|
|
23
|
-
|
|
10
|
+
import { toggleRowSelection } from "../hook/useColumns";
|
|
24
11
|
const renderCellIndex = props => {
|
|
25
12
|
const {
|
|
26
13
|
parrents,
|
|
@@ -93,6 +80,8 @@ const renderSelection = args => {
|
|
|
93
80
|
setIsSelectionChange,
|
|
94
81
|
isSelectionChange
|
|
95
82
|
} = args;
|
|
83
|
+
const checked = selectionSettings?.checkStrictly ? row.getIsSelected() : row.getIsSelected() || row.getIsAllSubRowsSelected();
|
|
84
|
+
const indeterminate = selectionSettings?.type == 'single' || selectionSettings?.checkStrictly ? false : row.getIsSomeSelected() && selectionSettings && selectionSettings.mode === 'checkbox' || row.getIsSomeSelected();
|
|
96
85
|
return /*#__PURE__*/React.createElement("div", {
|
|
97
86
|
style: {}
|
|
98
87
|
}, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/React.createElement("div", {
|
|
@@ -129,35 +118,16 @@ const renderSelection = args => {
|
|
|
129
118
|
})) : /*#__PURE__*/React.createElement("span", {
|
|
130
119
|
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
|
|
131
120
|
}))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Checkbox, {
|
|
132
|
-
checked:
|
|
133
|
-
indeterminate:
|
|
134
|
-
// indeterminate={row.getIsSomeSelected() }
|
|
135
|
-
,
|
|
121
|
+
checked: checked,
|
|
122
|
+
indeterminate: indeterminate,
|
|
136
123
|
onChange: e => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
type: 'rowSelected',
|
|
145
|
-
rowData: row.original,
|
|
146
|
-
rowsData: aaa ?? []
|
|
147
|
-
});
|
|
148
|
-
} else {
|
|
149
|
-
const {
|
|
150
|
-
rowsData
|
|
151
|
-
} = isSelectionChange ?? {};
|
|
152
|
-
const abc = rowsData && rowsData.length > 0 ? [...rowsData] : [];
|
|
153
|
-
abc.push(row);
|
|
154
|
-
setIsSelectionChange({
|
|
155
|
-
isChange: true,
|
|
156
|
-
type: 'rowSelected',
|
|
157
|
-
rowData: row.original,
|
|
158
|
-
rowsData: abc
|
|
159
|
-
});
|
|
160
|
-
}
|
|
124
|
+
toggleRowSelection({
|
|
125
|
+
e,
|
|
126
|
+
cell,
|
|
127
|
+
setIsSelectionChange,
|
|
128
|
+
isSelectionChange,
|
|
129
|
+
selectionSettings
|
|
130
|
+
});
|
|
161
131
|
},
|
|
162
132
|
disabled: !row.getCanSelect()
|
|
163
133
|
})));
|
|
@@ -416,11 +386,7 @@ const TableBodyCell = props => {
|
|
|
416
386
|
if (e.target.firstChild?.clientWidth < e.target.firstChild?.scrollWidth) {
|
|
417
387
|
setIsOpenTooltip(true);
|
|
418
388
|
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
// onMouseUp={() => { }}
|
|
422
|
-
,
|
|
423
|
-
|
|
389
|
+
},
|
|
424
390
|
onKeyDown: e => {
|
|
425
391
|
const flatRows = table.getRowModel().flatRows;
|
|
426
392
|
if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
|
|
@@ -485,45 +451,19 @@ const TableBodyCell = props => {
|
|
|
485
451
|
});
|
|
486
452
|
}
|
|
487
453
|
}
|
|
488
|
-
}
|
|
489
|
-
onDoubleClick: () => {},
|
|
490
|
-
onClick: e => {
|
|
491
|
-
if (selectionSettings?.checkboxOnly !== true && cell.row.getCanSelect()) {
|
|
492
|
-
const isInsideCell = e.target.closest(".ui-rc-grid-cell");
|
|
493
|
-
if (isInsideCell) {
|
|
494
|
-
cell.row.getToggleSelectedHandler()(e);
|
|
495
|
-
// setIsSelectionChange({
|
|
496
|
-
// isChange: true,
|
|
497
|
-
// type: 'rowSelected',
|
|
498
|
-
// rowData: cell.row.original,
|
|
499
|
-
// rowsData: []
|
|
500
|
-
// })
|
|
454
|
+
}
|
|
501
455
|
|
|
502
|
-
|
|
503
|
-
|
|
456
|
+
// onDoubleClick={() => { }}
|
|
457
|
+
,
|
|
504
458
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
const {
|
|
514
|
-
rowsData
|
|
515
|
-
} = isSelectionChange ?? {};
|
|
516
|
-
const abc = rowsData && rowsData.length > 0 ? [...rowsData] : [];
|
|
517
|
-
abc.push(cell.row);
|
|
518
|
-
setIsSelectionChange({
|
|
519
|
-
isChange: true,
|
|
520
|
-
type: 'rowSelected',
|
|
521
|
-
rowData: cell.row.original,
|
|
522
|
-
rowsData: abc
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
459
|
+
onClick: e => {
|
|
460
|
+
toggleRowSelection({
|
|
461
|
+
e,
|
|
462
|
+
cell,
|
|
463
|
+
setIsSelectionChange,
|
|
464
|
+
isSelectionChange,
|
|
465
|
+
selectionSettings
|
|
466
|
+
});
|
|
527
467
|
}
|
|
528
468
|
}, /*#__PURE__*/React.createElement("div", {
|
|
529
469
|
className: classNames('ui-rc_cell-content', {})
|
|
@@ -14,6 +14,7 @@ import React from "react";
|
|
|
14
14
|
import { TableContext } from "../useContext";
|
|
15
15
|
import EditableCell from "./EditableCell";
|
|
16
16
|
import { nonActionColumn } from "../hook/constant";
|
|
17
|
+
import { toggleRowSelection } from "../hook/useColumns";
|
|
17
18
|
// import { nonActionColumn } from "../hook/constant";
|
|
18
19
|
|
|
19
20
|
const renderCellIndex = props => {
|
|
@@ -100,7 +101,9 @@ const renderSelection = args => {
|
|
|
100
101
|
}
|
|
101
102
|
}, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
|
|
102
103
|
// onClick: row.getToggleExpandedHandler(),
|
|
103
|
-
onClick:
|
|
104
|
+
onClick: e => {
|
|
105
|
+
e.stopPropagation();
|
|
106
|
+
e.preventDefault();
|
|
104
107
|
const keys = Object.keys(expanded);
|
|
105
108
|
// @ts-ignore
|
|
106
109
|
const tmp = {
|
|
@@ -130,32 +133,48 @@ const renderSelection = args => {
|
|
|
130
133
|
checked: row.getIsSelected() || row.getIsAllSubRowsSelected(),
|
|
131
134
|
indeterminate: row.getIsSomeSelected() && selectionSettings && selectionSettings.mode === 'checkbox' && selectionSettings.type !== 'single'
|
|
132
135
|
// indeterminate={row.getIsSomeSelected() }
|
|
136
|
+
// onChange={(e) => {
|
|
137
|
+
|
|
138
|
+
// row.getToggleSelectedHandler()(e)
|
|
139
|
+
|
|
140
|
+
// if (row.getIsSelected()) { // nếu đã chọn
|
|
141
|
+
|
|
142
|
+
// const aaa = isSelectionChange?.rowsData.filter((it) => it.id !== row.id)
|
|
143
|
+
|
|
144
|
+
// setIsSelectionChange({
|
|
145
|
+
// isChange: true,
|
|
146
|
+
// type: 'rowSelected',
|
|
147
|
+
// rowData: row.original,
|
|
148
|
+
// rowsData: aaa ?? []
|
|
149
|
+
// })
|
|
150
|
+
|
|
151
|
+
// } else {
|
|
152
|
+
|
|
153
|
+
// const { rowsData } = isSelectionChange ?? {}
|
|
154
|
+
|
|
155
|
+
// const abc = rowsData && rowsData.length > 0 ? [...rowsData] : []
|
|
156
|
+
|
|
157
|
+
// abc.push(row)
|
|
158
|
+
|
|
159
|
+
// setIsSelectionChange({
|
|
160
|
+
// isChange: true,
|
|
161
|
+
// type: 'rowSelected',
|
|
162
|
+
// rowData: row.original,
|
|
163
|
+
// rowsData: abc
|
|
164
|
+
// })
|
|
165
|
+
// }
|
|
166
|
+
|
|
167
|
+
// }}
|
|
133
168
|
,
|
|
134
|
-
onChange: e => {
|
|
135
|
-
row.getToggleSelectedHandler()(e);
|
|
136
|
-
if (row.getIsSelected()) {
|
|
137
|
-
// nếu đã chọn
|
|
138
169
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
const {
|
|
148
|
-
rowsData
|
|
149
|
-
} = isSelectionChange ?? {};
|
|
150
|
-
const abc = rowsData && rowsData.length > 0 ? [...rowsData] : [];
|
|
151
|
-
abc.push(row);
|
|
152
|
-
setIsSelectionChange({
|
|
153
|
-
isChange: true,
|
|
154
|
-
type: 'rowSelected',
|
|
155
|
-
rowData: row.original,
|
|
156
|
-
rowsData: abc
|
|
157
|
-
});
|
|
158
|
-
}
|
|
170
|
+
onChange: e => {
|
|
171
|
+
toggleRowSelection({
|
|
172
|
+
e,
|
|
173
|
+
cell,
|
|
174
|
+
setIsSelectionChange,
|
|
175
|
+
isSelectionChange,
|
|
176
|
+
selectionSettings
|
|
177
|
+
});
|
|
159
178
|
},
|
|
160
179
|
disabled: !row.getCanSelect()
|
|
161
180
|
})));
|
|
@@ -823,7 +842,9 @@ const TableBodyCellEdit = props => {
|
|
|
823
842
|
}
|
|
824
843
|
}, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
|
|
825
844
|
// onClick: row.getToggleExpandedHandler(),
|
|
826
|
-
onClick:
|
|
845
|
+
onClick: e => {
|
|
846
|
+
e.stopPropagation();
|
|
847
|
+
e.preventDefault();
|
|
827
848
|
const keys = Object.keys(expanded);
|
|
828
849
|
// @ts-ignore
|
|
829
850
|
const tmp = {
|
|
@@ -900,40 +921,7 @@ const TableBodyCellEdit = props => {
|
|
|
900
921
|
// maxWidth: cell.column.getSize(),
|
|
901
922
|
...getCommonPinningStyles(cell.column)
|
|
902
923
|
}
|
|
903
|
-
}, cell.column.
|
|
904
|
-
className: "ui-rc-table-row-expand-trigger",
|
|
905
|
-
style: {
|
|
906
|
-
paddingLeft: `${cell.row.depth * 25}px`
|
|
907
|
-
}
|
|
908
|
-
}, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
|
|
909
|
-
// onClick: row.getToggleExpandedHandler(),
|
|
910
|
-
onClick: () => {
|
|
911
|
-
const keys = Object.keys(expanded);
|
|
912
|
-
// @ts-ignore
|
|
913
|
-
const tmp = {
|
|
914
|
-
...expanded
|
|
915
|
-
};
|
|
916
|
-
if (keys.includes(cell.row.id)) {
|
|
917
|
-
delete tmp[cell.row.id];
|
|
918
|
-
setExpanded(tmp);
|
|
919
|
-
} else {
|
|
920
|
-
setExpanded(old => ({
|
|
921
|
-
...old,
|
|
922
|
-
[cell.row.id]: true
|
|
923
|
-
}));
|
|
924
|
-
}
|
|
925
|
-
},
|
|
926
|
-
style: {
|
|
927
|
-
cursor: "pointer"
|
|
928
|
-
},
|
|
929
|
-
className: "ui-rc-table-row-expand"
|
|
930
|
-
}, cell.row.getIsExpanded() ? /*#__PURE__*/React.createElement("span", {
|
|
931
|
-
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded"
|
|
932
|
-
}) : /*#__PURE__*/React.createElement("span", {
|
|
933
|
-
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
|
|
934
|
-
})) : /*#__PURE__*/React.createElement("span", {
|
|
935
|
-
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
|
|
936
|
-
}))), cell.column.id === "selection_column" && renderSelection({
|
|
924
|
+
}, cell.column.id === "selection_column" && renderSelection({
|
|
937
925
|
cell,
|
|
938
926
|
table,
|
|
939
927
|
selectionSettings,
|
|
@@ -1029,27 +1017,8 @@ const TableBodyCellEdit = props => {
|
|
|
1029
1017
|
setEditingKey?.('');
|
|
1030
1018
|
reset?.();
|
|
1031
1019
|
});
|
|
1032
|
-
|
|
1033
|
-
// const currentEditColumn = table.getVisibleFlatColumns().find((it) => it.id === focusedCell?.colId)
|
|
1034
|
-
|
|
1035
|
-
// if ()
|
|
1036
|
-
|
|
1037
|
-
// handleChange()
|
|
1038
|
-
// setEditingKey?.('')
|
|
1039
|
-
// reset?.()
|
|
1040
1020
|
}
|
|
1041
|
-
|
|
1042
|
-
// reset?.()
|
|
1043
1021
|
}
|
|
1044
|
-
|
|
1045
|
-
// if (record[rowKey] !== editingKey) {
|
|
1046
|
-
|
|
1047
|
-
// setTimeout(() => {
|
|
1048
|
-
// // setEditingKey?.('')
|
|
1049
|
-
// reset?.()
|
|
1050
|
-
// })
|
|
1051
|
-
|
|
1052
|
-
// }
|
|
1053
1022
|
},
|
|
1054
1023
|
onMouseEnter: () => handleMouseEnter(cell.row.id, cell.column.id),
|
|
1055
1024
|
onMouseUp: e => handleMouseUp(e),
|
|
@@ -1113,10 +1082,6 @@ const TableBodyCellEdit = props => {
|
|
|
1113
1082
|
handleChange();
|
|
1114
1083
|
setEditingKey?.('');
|
|
1115
1084
|
reset?.();
|
|
1116
|
-
|
|
1117
|
-
// setTimeout(() => {
|
|
1118
|
-
|
|
1119
|
-
// })
|
|
1120
1085
|
}
|
|
1121
1086
|
}
|
|
1122
1087
|
}
|
|
@@ -1146,7 +1111,9 @@ const TableBodyCellEdit = props => {
|
|
|
1146
1111
|
}
|
|
1147
1112
|
}, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
|
|
1148
1113
|
// onClick: row.getToggleExpandedHandler(),
|
|
1149
|
-
onClick:
|
|
1114
|
+
onClick: e => {
|
|
1115
|
+
e.stopPropagation();
|
|
1116
|
+
e.preventDefault();
|
|
1150
1117
|
const keys = Object.keys(expanded);
|
|
1151
1118
|
// @ts-ignore
|
|
1152
1119
|
const tmp = {
|
|
@@ -9,7 +9,7 @@ import { ArrowDown, ArrowUp, FilterFill, SortCancel } from 'becoxy-icons';
|
|
|
9
9
|
import classNames from 'classnames';
|
|
10
10
|
import { Checkbox, Dropdown, Select } from 'rc-master-ui';
|
|
11
11
|
import { booleanOperator, nonActionColumn, numberOperator, stringOperator, translateOption } from "../hook/constant";
|
|
12
|
-
import { excludeItems, extendsObject, getCommonPinningStyles, getDefaultOperator, getTypeFilter } from "../hook/utils";
|
|
12
|
+
import { excludeItems, extendsObject, getCommonPinningStyles, getDefaultOperator, getTypeFilter, removeDuplicatesByKey } from "../hook/utils";
|
|
13
13
|
import { TableContext } from "../useContext";
|
|
14
14
|
import { renderFilter } from "./renderFilter";
|
|
15
15
|
import ReactDOMServer from 'react-dom/server';
|
|
@@ -267,10 +267,10 @@ const TableHeadCell2 = props => {
|
|
|
267
267
|
indeterminate: table.getIsSomePageRowsSelected(),
|
|
268
268
|
onChange: e => {
|
|
269
269
|
table.getToggleAllRowsSelectedHandler()(e);
|
|
270
|
-
const
|
|
270
|
+
const prevSelected = isSelectionChange?.rowsData ?? [];
|
|
271
|
+
const allRowsInPage = table.getRowModel().flatRows;
|
|
271
272
|
if (table.getIsAllRowsSelected()) {
|
|
272
|
-
const
|
|
273
|
-
const cc = excludeItems(aa, dd);
|
|
273
|
+
const cc = excludeItems(prevSelected, allRowsInPage);
|
|
274
274
|
setIsSelectionChange({
|
|
275
275
|
isChange: true,
|
|
276
276
|
type: 'all',
|
|
@@ -278,14 +278,13 @@ const TableHeadCell2 = props => {
|
|
|
278
278
|
rowsData: cc
|
|
279
279
|
});
|
|
280
280
|
} else {
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
const abc = [...aa, ...bb];
|
|
281
|
+
const abc = [...prevSelected, ...allRowsInPage];
|
|
282
|
+
const newSeletedRows = removeDuplicatesByKey(abc, 'id');
|
|
284
283
|
setIsSelectionChange({
|
|
285
284
|
isChange: true,
|
|
286
285
|
type: 'all',
|
|
287
286
|
rowData: {},
|
|
288
|
-
rowsData:
|
|
287
|
+
rowsData: newSeletedRows
|
|
289
288
|
});
|
|
290
289
|
}
|
|
291
290
|
}
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { Fragment } from 'react';
|
|
2
2
|
import ControlCheckbox from "../components/ControlCheckbox";
|
|
3
|
-
import { checkDecimalSeparator, checkThousandSeparator, getFormat, isColor, isEmpty, sortByType } from "./utils";
|
|
3
|
+
import { checkDecimalSeparator, checkThousandSeparator, countUnselectedChildren, excludeItems, getAllChildren, getFormat, isColor, isEmpty, sortByType, toggleRowAndChildren } from "./utils";
|
|
4
4
|
import { numericFormatter } from 'react-numeric-component';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import moment from 'moment';
|
|
@@ -170,4 +170,115 @@ export function convertToTanStackColumns({
|
|
|
170
170
|
}
|
|
171
171
|
return newCol;
|
|
172
172
|
});
|
|
173
|
-
}
|
|
173
|
+
}
|
|
174
|
+
export const toggleRowSelection = props => {
|
|
175
|
+
const {
|
|
176
|
+
selectionSettings,
|
|
177
|
+
cell,
|
|
178
|
+
isSelectionChange,
|
|
179
|
+
e,
|
|
180
|
+
setIsSelectionChange
|
|
181
|
+
} = props;
|
|
182
|
+
const {
|
|
183
|
+
row
|
|
184
|
+
} = cell;
|
|
185
|
+
const {
|
|
186
|
+
rowsData
|
|
187
|
+
} = isSelectionChange ?? {};
|
|
188
|
+
const prevSelected = rowsData && rowsData.length > 0 ? [...rowsData] : [];
|
|
189
|
+
if (selectionSettings?.checkStrictly || selectionSettings?.type === 'single') {
|
|
190
|
+
row.getToggleSelectedHandler()(e);
|
|
191
|
+
if (row.getIsSelected()) {
|
|
192
|
+
// đã chọn
|
|
193
|
+
|
|
194
|
+
// xóa row ra list selected
|
|
195
|
+
const newRowsSelected = prevSelected.filter(it => it.id !== row.id);
|
|
196
|
+
setIsSelectionChange({
|
|
197
|
+
isChange: true,
|
|
198
|
+
type: 'rowSelected',
|
|
199
|
+
rowData: row.original,
|
|
200
|
+
rowsData: newRowsSelected ?? []
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
203
|
+
// chưa selected
|
|
204
|
+
|
|
205
|
+
const checkedRows = [...prevSelected, row];
|
|
206
|
+
setIsSelectionChange({
|
|
207
|
+
isChange: true,
|
|
208
|
+
type: 'rowSelected',
|
|
209
|
+
rowData: row.original,
|
|
210
|
+
rowsData: checkedRows
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (row.subRows && row.subRows.length > 0) {
|
|
216
|
+
const allChild = getAllChildren(row);
|
|
217
|
+
toggleRowAndChildren(row, !row.getIsSelected());
|
|
218
|
+
if (row.getIsSelected()) {
|
|
219
|
+
// đã chọn
|
|
220
|
+
|
|
221
|
+
// const aaa = isSelectionChange?.rowsData.filter((it) => it.id !== row.id)
|
|
222
|
+
|
|
223
|
+
const newRowsSelected = excludeItems(prevSelected, [...allChild, row]);
|
|
224
|
+
setIsSelectionChange({
|
|
225
|
+
isChange: true,
|
|
226
|
+
type: 'rowSelected',
|
|
227
|
+
rowData: row.original,
|
|
228
|
+
rowsData: newRowsSelected ?? []
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
// chưa selected
|
|
232
|
+
|
|
233
|
+
let checkedRows = [];
|
|
234
|
+
if (row.subRows && row.subRows.length > 0) {
|
|
235
|
+
checkedRows = [...prevSelected, row, ...allChild];
|
|
236
|
+
} else {
|
|
237
|
+
checkedRows = [...prevSelected, row];
|
|
238
|
+
}
|
|
239
|
+
setIsSelectionChange({
|
|
240
|
+
isChange: true,
|
|
241
|
+
type: 'rowSelected',
|
|
242
|
+
rowData: row.original,
|
|
243
|
+
rowsData: checkedRows
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
row.getToggleSelectedHandler()(e);
|
|
248
|
+
if (row.getIsSelected()) {
|
|
249
|
+
// đã chọn
|
|
250
|
+
|
|
251
|
+
// xóa row ra list selected
|
|
252
|
+
const newRowsSelected = prevSelected.filter(it => it.id !== row.id);
|
|
253
|
+
setIsSelectionChange({
|
|
254
|
+
isChange: true,
|
|
255
|
+
type: 'rowSelected',
|
|
256
|
+
rowData: row.original,
|
|
257
|
+
rowsData: newRowsSelected ?? []
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
// chưa selected
|
|
261
|
+
|
|
262
|
+
let checkedRows = [];
|
|
263
|
+
const rowParent = row.getParentRow();
|
|
264
|
+
|
|
265
|
+
// console.log(countUnselectedChildren(row))
|
|
266
|
+
|
|
267
|
+
// nếu có cha và cha chưa được chọn và tất cả con đã chọn => thêm row cha vào
|
|
268
|
+
if (rowParent && !rowParent.getIsSelected() && countUnselectedChildren(row) === 1) {
|
|
269
|
+
rowParent.toggleSelected(!rowParent.getIsSelected());
|
|
270
|
+
checkedRows = [...prevSelected, row, rowParent];
|
|
271
|
+
} else {
|
|
272
|
+
// chỉ thêm vào row hiện tại
|
|
273
|
+
|
|
274
|
+
checkedRows = [...prevSelected, row];
|
|
275
|
+
}
|
|
276
|
+
setIsSelectionChange({
|
|
277
|
+
isChange: true,
|
|
278
|
+
type: 'rowSelected',
|
|
279
|
+
rowData: row.original,
|
|
280
|
+
rowsData: checkedRows
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
@@ -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[];
|
|
@@ -2171,4 +2171,44 @@ export function excludeItems(arrayA, arrayB) {
|
|
|
2171
2171
|
|
|
2172
2172
|
// Lọc A, chỉ giữ lại phần tử không có trong B
|
|
2173
2173
|
return arrayA.filter(item => !idsInB.has(item.id));
|
|
2174
|
+
}
|
|
2175
|
+
export function getAllChildren(row) {
|
|
2176
|
+
const children = row.subRows ?? [];
|
|
2177
|
+
return children.reduce((acc, child) => {
|
|
2178
|
+
return acc.concat(child, getAllChildren(child));
|
|
2179
|
+
}, []);
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
// export function toggleSelectAllChildren(row: any) {
|
|
2183
|
+
// const children = row.subRows ?? [];
|
|
2184
|
+
|
|
2185
|
+
// return children.reduce((acc: any, child: any) => {
|
|
2186
|
+
// return acc.concat(child, getAllChildren(child));
|
|
2187
|
+
// }, []);
|
|
2188
|
+
// }
|
|
2189
|
+
|
|
2190
|
+
export function toggleRowAndChildren(row, isSelected) {
|
|
2191
|
+
// Toggle chính row hiện tại
|
|
2192
|
+
row.toggleSelected(isSelected);
|
|
2193
|
+
|
|
2194
|
+
// Nếu có subRows thì gọi đệ quy
|
|
2195
|
+
if (row.subRows && row.subRows.length > 0) {
|
|
2196
|
+
row.subRows.forEach(subRow => toggleRowAndChildren(subRow, isSelected));
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
export function countUnselectedChildren(row) {
|
|
2200
|
+
const parent = row.getParentRow();
|
|
2201
|
+
if (!parent) return 0; // Không có cha thì return 0
|
|
2202
|
+
|
|
2203
|
+
const unselectedCount = parent.subRows.filter(child => !child.getIsSelected()).length;
|
|
2204
|
+
return unselectedCount;
|
|
2205
|
+
}
|
|
2206
|
+
export function removeDuplicatesByKey(arr, key = 'id') {
|
|
2207
|
+
const map = new Map();
|
|
2208
|
+
for (const item of arr) {
|
|
2209
|
+
if (!map.has(item[key])) {
|
|
2210
|
+
map.set(item[key], item);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
return Array.from(map.values());
|
|
2174
2214
|
}
|
|
@@ -190,7 +190,7 @@ const Grid = props => {
|
|
|
190
190
|
// ...prev,
|
|
191
191
|
// isChange: false
|
|
192
192
|
// }))
|
|
193
|
-
setRowSelection(convertToObjTrue(mergedSelectedKeys))
|
|
193
|
+
// setRowSelection(convertToObjTrue(mergedSelectedKeys))
|
|
194
194
|
}
|
|
195
195
|
}, [mergedSelectedKeys]);
|
|
196
196
|
React.useEffect(() => {
|
|
@@ -204,6 +204,7 @@ const Grid = props => {
|
|
|
204
204
|
|
|
205
205
|
// const ssss = dataTable.filter(it => ids.includes(it.id)) // lấy rowsData của trang hiện tại
|
|
206
206
|
const ssss = filterByIds(ids, isSelectionChange.rowsData ?? []); // lấy rowsData của trang hiện tại
|
|
207
|
+
// const ssss = (isSelectionChange.rowsData ?? []) as any[] // lấy rowsData của trang hiện tại
|
|
207
208
|
|
|
208
209
|
const rs = ssss.map(it => it.original);
|
|
209
210
|
// const rs = allRows.map(it => it.original)
|
|
@@ -476,6 +476,7 @@ export type SelectionSettings<T = AnyObject> = {
|
|
|
476
476
|
mode?: 'checkbox' | 'radio';
|
|
477
477
|
type?: 'single' | 'multiple';
|
|
478
478
|
checkboxOnly?: boolean;
|
|
479
|
+
checkStrictly?: boolean;
|
|
479
480
|
columnWidth?: number;
|
|
480
481
|
hideSelectAll?: boolean;
|
|
481
482
|
selectedRowKeys?: Key[];
|