es-grid-template 1.4.4 → 1.4.6

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.
@@ -24,7 +24,7 @@ import Message from "../../Message/Message";
24
24
  import { Toolbar, ConfigProvider, InputNumber } from "rc-master-ui";
25
25
  import classnames from "classnames";
26
26
  import { Plus, Trash2 } from "becoxy-icons";
27
- import { faker } from "@faker-js/faker";
27
+ // import {faker} from "@faker-js/faker";
28
28
  import { SELECTION_COLUMN } from "../InternalTable";
29
29
  const {
30
30
  Paragraph,
@@ -178,16 +178,17 @@ const validateData = async (data, formSchema) => {
178
178
  };
179
179
  const GridEdit = props => {
180
180
  const {
181
- id: tableId,
181
+ id,
182
182
  tableRef,
183
183
  t,
184
184
  columns,
185
185
  dataSource,
186
186
  components,
187
187
  allowResizing,
188
- rowKey = 'rowId',
188
+ rowKey = 'id',
189
189
  selectionSettings,
190
190
  height,
191
+ scrollHeight,
191
192
  format,
192
193
  triggerChangeData,
193
194
  triggerChangeColumns,
@@ -229,20 +230,143 @@ const GridEdit = props => {
229
230
  const visibleCols = React.useMemo(() => {
230
231
  return flatColumns2(columns.filter(it => it.visible !== false));
231
232
  }, [columns]);
232
- const id = React.useMemo(() => {
233
- return tableId ?? faker.string.alpha(20);
234
- // return tableId ?? newGuid()
235
- }, [tableId]);
236
- const itemsAdd = [{
237
- key: '10',
238
- label: '10 rows'
239
- }, {
240
- key: '50',
241
- label: '50 rows'
242
- }, {
243
- key: '100',
244
- label: '100 rows'
245
- }];
233
+
234
+ // const id = React.useMemo(() => {
235
+ //
236
+ // return tableId ?? faker.string.alpha(20)
237
+ // // return tableId ?? newGuid()
238
+ //
239
+ // }, [tableId])
240
+
241
+ const itemsAdd = React.useMemo(() => {
242
+ return [{
243
+ key: '10',
244
+ label: `10 ${t ? t('rows') : 'rows'}`
245
+ }, {
246
+ key: '50',
247
+ label: `50 ${t ? t('rows') : 'rows'}`
248
+ }, {
249
+ key: '100',
250
+ label: `100 ${t ? t('rows') : 'rows'}`
251
+ }];
252
+ }, [t]);
253
+
254
+ // const defaultContext = React.useMemo(() => {
255
+ // return [
256
+ // {
257
+ // key: 'INSERT_BEFORE',
258
+ // label: 'Thêm dòng bên trên',
259
+ // icon: <Plus fontSize={14} />,
260
+ // children: [
261
+ // {
262
+ // parentKey: 'INSERT_BEFORE',
263
+ // key: 'INSERT_BEFORE_1',
264
+ // label: 'Thêm 1 dòng',
265
+ // row: 1
266
+ // },
267
+ // {
268
+ // parentKey: 'INSERT_BEFORE',
269
+ // key: 'INSERT_BEFORE_10',
270
+ // label: 'Thêm 10 dòng',
271
+ // row: 10
272
+ // },
273
+ // {
274
+ // parentKey: 'INSERT_BEFORE',
275
+ // key: 'INSERT_BEFORE_50',
276
+ // label: 'Thêm 50 dòng',
277
+ // row: 50
278
+ // },
279
+ // {
280
+ // parentKey: 'INSERT_BEFORE',
281
+ // key: 'INSERT_BEFORE_100',
282
+ // label: 'Thêm 100 dòng',
283
+ // row: 100
284
+ // },
285
+ // {
286
+ // parentKey: 'INSERT_BEFORE',
287
+ // key: 'INSERT_BEFORE_ADV',
288
+ // label: 'Tùy chỉnh'
289
+ // }
290
+ // ]
291
+ // },
292
+ // {
293
+ // key: 'INSERT_AFTER',
294
+ // label: 'Thêm dòng bên dưới',
295
+ // icon: <Plus fontSize={14} />,
296
+ // children: [
297
+ // {
298
+ // parentKey: 'INSERT_AFTER',
299
+ // key: 'INSERT_AFTER_1',
300
+ // label: 'Thêm 1 dòng',
301
+ // row: 1
302
+ // },
303
+ // {
304
+ // parentKey: 'INSERT_AFTER',
305
+ // key: 'INSERT_AFTER_10',
306
+ // label: 'Thêm 10 dòng',
307
+ // row: 10
308
+ // },
309
+ // {
310
+ // parentKey: 'INSERT_AFTER',
311
+ // key: 'INSERT_AFTER_50',
312
+ // label: 'Thêm 50 dòng',
313
+ // row: 50
314
+ // },
315
+ // {
316
+ // parentKey: 'INSERT_AFTER',
317
+ // key: 'INSERT_AFTER_100',
318
+ // label: 'Thêm 100 dòng',
319
+ // row: 100
320
+ // },
321
+ // {
322
+ // parentKey: 'INSERT_AFTER',
323
+ // key: 'INSERT_AFTER_ADV',
324
+ // label: 'Tùy chỉnh'
325
+ // }
326
+ // ]
327
+ // },
328
+ // {
329
+ // key: 'INSERT_CHILDREN',
330
+ // // label: 'Insert item children',
331
+ // label: 'Thêm cấp con',
332
+ // icon: <Plus fontSize={14} />
333
+ // // children: [
334
+ // // {
335
+ // // parentKey: 'INSERT_AFTER',
336
+ // // key: 'INSERT_AFTER_1',
337
+ // // label: 'Thêm 1 dòng',
338
+ // // row: 1
339
+ // // },
340
+ // // {
341
+ // // parentKey: 'INSERT_AFTER',
342
+ // // key: 'INSERT_AFTER_10',
343
+ // // label: 'Thêm 10 dòng',
344
+ // // row: 10
345
+ // // },
346
+ // // {
347
+ // // parentKey: 'INSERT_AFTER',
348
+ // // key: 'INSERT_AFTER_50',
349
+ // // label: 'Thêm 50 dòng',
350
+ // // row: 50
351
+ // // },
352
+ // // {
353
+ // // parentKey: 'INSERT_AFTER',
354
+ // // key: 'INSERT_AFTER_100',
355
+ // // label: 'Thêm 100 dòng',
356
+ // // row: 100
357
+ // // },
358
+ // // {
359
+ // // parentKey: 'INSERT_AFTER',
360
+ // // key: 'INSERT_AFTER_ADV',
361
+ // // label: 'Tùy chỉnh'
362
+ // // }
363
+ // // ]
364
+ // },
365
+ // { key: 'DELETE_CONTENT', label: 'Xóa nội dung', icon: <Trash2 fontSize={14} /> },
366
+ // { key: 'DELETE_ROWS', label: 'Xóa dòng', icon: <Trash2 fontSize={14} /> }
367
+ // ]
368
+ // }, [])
369
+
246
370
  const [form] = Form.useForm();
247
371
  const [editingKey, setEditingKey] = useState('');
248
372
  const [dataErrors, setDataErrors] = useState([]);
@@ -439,7 +563,7 @@ const GridEdit = props => {
439
563
  triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
440
564
  }
441
565
  }
442
- }, [dataSource, defaultValue, id, isFilter, rowKey, rowsFocus, triggerChangeData]);
566
+ }, [dataSource, defaultValue, isFilter, rowKey, rowsFocus, triggerChangeData]);
443
567
 
444
568
  //thêm 1 dòng bên dưới
445
569
  const handleInsertAfter = React.useCallback((item, n) => {
@@ -524,7 +648,7 @@ const GridEdit = props => {
524
648
  });
525
649
  } else {
526
650
  const newData = [...dataSource];
527
- let newElement = {};
651
+ let newElement;
528
652
  if (!record.children || record.children.length === 0) {
529
653
  newElement = {
530
654
  ...record,
@@ -575,7 +699,7 @@ const GridEdit = props => {
575
699
  });
576
700
  triggerChangeData?.([...newData], 'DELETE_ROWS');
577
701
  }
578
- }, [dataSource, id, rowsFocus, triggerChangeData]);
702
+ }, [dataSource, rowsFocus, triggerChangeData]);
579
703
  const handleDeleteAll = React.useCallback(() => {
580
704
  triggerChangeData?.([], 'INSERT_BEFORE');
581
705
  }, [triggerChangeData]);
@@ -910,10 +1034,7 @@ const GridEdit = props => {
910
1034
  }) => {
911
1035
  table[row - minRow][col - minCol] = value;
912
1036
  });
913
- let newRange = {
914
- combined: [],
915
- addedRows: []
916
- };
1037
+ let newRange;
917
1038
  if (rowPasteLast > rowSelectedFirst) {
918
1039
  // kéo xuóng
919
1040
  newRange = addRows8(table, getRowsPasteIndex(pastesArray).length);
@@ -993,278 +1114,550 @@ const GridEdit = props => {
993
1114
  }
994
1115
  pasteCells.current = new Set();
995
1116
  };
996
- const handlePointDoubleClick = e => {
997
- // e.preventDefault()
998
- e.stopPropagation();
999
- const colStart = getFirstSelectCell(selectedCells.current).col;
1000
- const colEnd = getLastSelectCell(selectedCells.current).col;
1001
- const startPasteRow = getLastSelectCell(selectedCells.current).row;
1002
- const newPasteCells = new Set();
1003
- for (let r = Math.min(startPasteRow, dataSource.length - 1) + 1; r <= Math.max(startPasteRow, dataSource.length - 1); r++) {
1004
- for (let c = Math.min(colStart, colStart); c <= Math.max(colStart, colEnd); c++) {
1005
- newPasteCells.add(`${r}-${c}`);
1006
- }
1007
- }
1008
- hideDraggingPoint(selectedCells.current, id);
1009
- triggerDragPaste(newPasteCells);
1010
- };
1011
- const handleMouseDown = (record, row, col, e) => {
1012
- if (e.button === 2) {
1013
- e.stopPropagation();
1014
- return;
1015
- }
1016
- if (editingKey && editingKey === record[rowKey]) {
1017
- return;
1018
- }
1019
- if (record[rowKey] !== editingKey && editingKey !== '') {
1020
- setEditingKey('');
1021
- }
1117
+ const handlePasted = (record, indexCol, rowNumber, pasteData) => {
1118
+ const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1119
+ if (!record?.parentId) {
1120
+ // Cập nhật data mới
1121
+ const newData = [...dataSource];
1022
1122
 
1023
- // isDragMouse.current = true
1024
- isMouseDown.current = true;
1025
- if (e.ctrlKey) {
1026
- isSelecting.current = true;
1027
- startCell.current = {
1028
- row,
1029
- col
1030
- };
1123
+ // const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
1031
1124
 
1032
- // const cell: any = new Set([`${row}-${col}`])
1125
+ // Lấy vị trí bắt đầu
1126
+ // const { row: startRow, col: startCol } = selectedCell;
1127
+ const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
1128
+ const startCol = indexCol;
1033
1129
 
1034
- // setCurrentCtrlCells(cell)
1035
- } else {
1036
- isSelecting.current = true;
1037
- startCell.current = {
1038
- row,
1039
- col
1040
- };
1041
- const target = e.target;
1042
- if (target.closest('.dragging-point')) {
1043
- e.stopPropagation();
1044
- e.preventDefault();
1045
- return; // Không xử lý gì cả
1046
- } else {
1047
- // setStartSelectedCell({row, col})
1130
+ // const flattData = flattenArray(newData);
1048
1131
 
1049
- startSelectedCells.current = {
1050
- row,
1051
- col
1052
- };
1132
+ const pastedRows = [];
1133
+ const pastedColumns = new Set();
1134
+ rows.forEach((rowValues, rowIndex) => {
1135
+ const targetRow = startRow + rowIndex;
1053
1136
 
1054
- // setSelectedCells(new Set([`${row}-${col}`]));
1137
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
1138
+ if (targetRow >= newData.length) {
1139
+ // @ts-ignore
1140
+ // newData.push({ id: newGuid()});
1141
+ newData.push({
1142
+ id: undefined,
1143
+ rowId: newGuid()
1144
+ });
1145
+ }
1146
+ rowValues.forEach((cellValue, colIndex) => {
1147
+ const targetCol = startCol + colIndex;
1148
+ if (targetCol >= visibleCols.length) {
1149
+ // Không vượt quá số cột
1150
+ return;
1151
+ }
1152
+ if (visibleCols[targetCol].editEnable) {
1153
+ // @ts-ignore
1154
+ const columnKey = visibleCols[targetCol].field;
1055
1155
 
1056
- const cells = new Set([`${row}-${col}`]);
1057
- if (selectedCells.current && selectedCells.current.size > 0) {
1058
- if (!isEqualSet(cells, rangeCells)) {
1059
- // onRemoveBgSelectedCell(rangeCells, id)
1060
- // onRemoveBorderSelectedCell(rangeCells, id)
1061
- hideDraggingPoint(rangeCells, id);
1062
- onRemoveBgCellIndex(selectedCells.current, id);
1156
+ // @ts-ignore
1157
+ newData[targetRow] = {
1158
+ ...newData[targetRow],
1159
+ [columnKey]: cellValue.trim()
1160
+ };
1161
+ pastedColumns.add(columnKey);
1063
1162
  }
1064
- }
1065
- if (rowsSelected.current && rowsSelected.current.size > 0) {
1066
- removeClassCellIndexSelected(rowsSelected.current, id);
1067
- }
1068
- if (!isEqualSet(cells, selectedCells.current)) {
1069
- onRemoveBgSelectedCell(selectedCells.current, id);
1070
- hideDraggingPoint(selectedCells.current, id);
1071
- selectedCells.current = cells;
1072
- // setRangeCells(cells)
1163
+ });
1073
1164
 
1074
- onAddBgCellIndex(cells, id);
1075
- onAddBorderSelectedCell(cells, id);
1076
- onAddBgSelectedCell(selectedCells.current, id, false);
1077
- showDraggingPoint(selectedCells.current, id);
1078
- }
1165
+ // Lưu dòng được paste
1166
+ pastedRows.push(newData[targetRow]);
1167
+ });
1168
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1169
+ triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1170
+ } else {
1171
+ // Cập nhật data mới
1172
+ const newData = [...dataSource];
1173
+ const parent = findItemByKey(newData, rowKey, record.parentId);
1079
1174
 
1080
- // setRowsSelected(new Set())
1081
- rowsSelected.current = new Set();
1082
- }
1083
- }
1084
- };
1085
- const handleMouseUp = e => {
1086
- isSelecting.current = false;
1087
- startCell.current = null;
1088
- isSelectingRow.current = false;
1089
- rowStart.current = null;
1090
- isDragMouse.current = false;
1091
- isMouseDown.current = false;
1092
- setIsPasteDragging(false);
1093
- if (e.ctrlKey) {
1175
+ // Cập nhật childData mới
1176
+ const childData = parent?.children ? [...parent.children] : [];
1094
1177
 
1095
- // setCtrlCells([...ctrlCells, currentCtrlCells])
1096
- }
1178
+ // Lấy vị trí bắt đầu
1179
+ // const { row: startRow, col: startCol } = selectedCell;
1180
+ const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
1181
+ const startCol = indexCol;
1182
+ const pastedRows = [];
1183
+ const pastedColumns = new Set();
1184
+ rows.forEach((rowValues, rowIndex) => {
1185
+ const targetRow = startRow + rowIndex;
1097
1186
 
1098
- // nếu ctrlCell length > 0 thì set selectCells
1187
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
1188
+ if (targetRow >= childData.length) {
1189
+ childData.push({
1190
+ id: undefined,
1191
+ rowId: newGuid(),
1192
+ parentId: parent[rowKey ?? 'id']
1193
+ });
1194
+ }
1195
+ rowValues.forEach((cellValue, colIndex) => {
1196
+ const targetCol = startCol + colIndex;
1197
+ if (targetCol >= visibleCols.length) {
1198
+ // Không vượt quá số cột
1199
+ return;
1200
+ }
1201
+ if (visibleCols[targetCol].editEnable) {
1202
+ // @ts-ignore
1203
+ const columnKey = visibleCols[targetCol].field;
1099
1204
 
1100
- if (pasteCells && pasteCells.current.size > 0) {
1101
- triggerDragPaste(pasteCells.current);
1102
- } else {
1103
- setRangeCells(selectedCells.current);
1104
- const target = e.target;
1105
- if (target.closest('.dragging-point')) {
1106
- e.stopPropagation();
1107
- e.preventDefault();
1108
- return; // Không xử lý gì cả
1109
- }
1110
- if (selectedCells.current && selectedCells.current.size > 1) {
1111
- hideDraggingPoint(selectedCells.current, id);
1112
- onAddBorderSelectedCell(selectedCells.current, id);
1205
+ // @ts-ignore
1206
+ childData[targetRow] = {
1207
+ ...childData[targetRow],
1208
+ [columnKey]: cellValue.trim()
1209
+ };
1210
+ pastedColumns.add(columnKey);
1211
+ }
1212
+ });
1113
1213
 
1114
- // showDraggingPoint(selectedCells.current, id)
1115
- }
1116
- showDraggingPoint(selectedCells.current, id);
1117
- // onAddBorderSelectedCell(selectedCells.current, id)
1214
+ // Lưu dòng được paste
1215
+ pastedRows.push(childData[targetRow]);
1216
+ });
1217
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1218
+ const newRowData = {
1219
+ ...parent,
1220
+ children: childData
1221
+ };
1222
+ const newDataSource = updateArrayByKey(newData, newRowData, rowKey);
1223
+ triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
1118
1224
  }
1119
1225
  };
1120
- const handleMouseEnter = (row, col, e) => {
1121
- if (!isSelecting.current || !startCell.current) {
1122
- return;
1123
- }
1124
- const {
1125
- row: startRow,
1126
- col: startCol
1127
- } = startCell.current;
1128
- if (e.ctrlKey) {
1129
- // const newCtrlCells = new Set();
1130
- // for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1131
- // for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1132
- // newCtrlCells.add(`${r}-${c}`)
1133
- // }
1134
- // }
1135
-
1136
- // setCurrentCtrlCells(newCtrlCells)
1137
-
1138
- return;
1139
- }
1140
- if (!isPasteDragging) {
1141
- // chọn vùng copy
1142
-
1143
- // setSelectIsDragging(true)
1144
-
1145
- setIsPasteDragging(false);
1146
- // isPasteDragging.current = false
1147
-
1148
- const newSelectedCells = new Set();
1149
- for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1150
- for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1151
- newSelectedCells.add(`${r}-${c}`);
1152
- }
1153
- }
1226
+ const handlePaste = (record, indexCol, rowNumber, e) => {
1227
+ // const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
1228
+ const pasteData = e.clipboardData.getData("text/plain");
1154
1229
 
1155
- // setSelectedCells(newSelectedCells)
1230
+ // Chuyển đổi dữ liệu từ clipboard thành mảng
1231
+ const rowsPasted = pasteData.split("\n").map(row =>
1232
+ // const rows = pasteData.split("\n").map((row: any) =>
1233
+ row.replace(/\r/g, "").split("\t"));
1234
+ if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
1235
+ // bật popup thông báo
1156
1236
 
1157
- if (selectedCells.current && selectedCells.current.size > 0) {
1158
- onRemoveBgSelectedCell(selectedCells.current, id);
1159
- }
1160
- selectedCells.current = newSelectedCells;
1161
- onAddBgSelectedCell(newSelectedCells, id);
1162
- } else {
1163
- // chọn vùng paste
1164
-
1165
- // setSelectIsDragging(false)
1166
-
1167
- // setIsPasteDragging(true) ////////
1168
-
1169
- const newSelectedCells = new Set();
1170
- for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1171
- for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1172
- newSelectedCells.add(`${r}-${c}`);
1173
- }
1174
- }
1175
- const colStart = getFirstSelectCell(selectedCells.current).col;
1176
- const colEnd = getLastSelectCell(selectedCells.current).col;
1177
- const rowSelectedEnd = getLastSelectCell(selectedCells.current).row;
1178
- if (row >= rowSelectedEnd) {
1179
- // kéo xuống dưới
1180
-
1181
- const newPasteCells = new Set();
1182
- for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
1183
- for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1184
- newPasteCells.add(`${r}-${c}`);
1185
- }
1186
- }
1187
-
1188
- // setPasteCells(newPasteCells)
1189
-
1190
- if (pasteCells.current && pasteCells.current.size > 0) {
1191
- removeClassBorderPasteCell(pasteCells.current, 'down', id);
1192
- }
1193
- pasteCells.current = newPasteCells;
1194
- addClassBorderPasteCell(newPasteCells, 'down', id);
1195
- }
1196
- if (row < rowSelectedEnd) {
1197
- // kéo lên trên
1198
-
1199
- const rowSelectedStart = getFirstSelectCell(selectedCells.current).row;
1200
- if (row < rowSelectedStart) {
1201
- const newPasteCells = new Set();
1202
- for (let r = Math.min(rowSelectedStart, row); r <= Math.max(rowSelectedStart, row) - 1; r++) {
1203
- for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1204
- newPasteCells.add(`${r}-${c}`);
1205
- }
1237
+ Modal.confirm({
1238
+ content: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Paragraph, {
1239
+ style: {
1240
+ marginBottom: '.25rem',
1241
+ fontSize: 14
1206
1242
  }
1207
-
1208
- // setPasteCells(newPasteCells)
1209
-
1210
- if (pasteCells.current && pasteCells.current.size > 0) {
1211
- removeClassBorderPasteCell(pasteCells.current, 'up', id);
1243
+ }, "D\u1EEF li\u1EC7u sao ch\xE9p v\u01B0\u1EE3t qu\xE1 s\u1ED1 d\xF2ng cho ph\xE9p (500 d\xF2ng).Ph\u1EA7n m\u1EC1n s\u1EBD ch\u1EC9 l\u1EA5y 500 d\xF2ng \u0111\u1EA7u ti\xEAn."), /*#__PURE__*/React.createElement(Title, {
1244
+ level: 5,
1245
+ style: {
1246
+ marginTop: '.75rem'
1212
1247
  }
1213
- pasteCells.current = newPasteCells;
1214
- addClassBorderPasteCell(newPasteCells, 'up', id);
1248
+ }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
1249
+ centered: true,
1250
+ className: 'be-popup-container',
1251
+ onOk: () => {
1252
+ handlePasted(record, indexCol, rowNumber, rowsPasted);
1215
1253
  }
1216
- }
1217
- if (col > colEnd) {
1218
- // kéo sang phải
1219
- }
1220
- if (row < colStart) {
1221
- // kéo sang trái
1222
- }
1254
+ // footer: (_, { OkBtn, CancelBtn }) => (
1255
+ // <>
1256
+ // <OkBtn />
1257
+ // <CancelBtn />
1258
+ // </>
1259
+ // ),
1260
+ });
1261
+ } else {
1262
+ handlePasted(record, indexCol, rowNumber, rowsPasted);
1223
1263
  }
1264
+
1265
+ // const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
1266
+ //
1267
+ //
1268
+ // if (!record?.parentId ) {
1269
+ //
1270
+ // // Cập nhật data mới
1271
+ // const newData = [...dataSource];
1272
+ //
1273
+ // // @ts-ignore
1274
+ // const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
1275
+ //
1276
+ // // Lấy vị trí bắt đầu
1277
+ // // const { row: startRow, col: startCol } = selectedCell;
1278
+ // const startRow = indexRows
1279
+ // const startCol = indexCol
1280
+ //
1281
+ //
1282
+ //
1283
+ // // const flattData = flattenArray(newData);
1284
+ //
1285
+ // const pastedRows: RecordType[] = [];
1286
+ // const pastedColumns = new Set()
1287
+ //
1288
+ //
1289
+ // rows.forEach((rowValues: any, rowIndex: any) => {
1290
+ // const targetRow = startRow + rowIndex;
1291
+ //
1292
+ // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1293
+ // if (targetRow >= newData.length) {
1294
+ // // @ts-ignore
1295
+ // // newData.push({ id: newGuid()});
1296
+ // newData.push({ id: undefined, rowId: newGuid()});
1297
+ // }
1298
+ //
1299
+ // rowValues.forEach((cellValue: any, colIndex: any) => {
1300
+ // const targetCol = startCol + colIndex;
1301
+ // if (targetCol >= columns.length) { // Không vượt quá số cột
1302
+ // return
1303
+ // }
1304
+ //
1305
+ // if (columns[targetCol].editEnable) {
1306
+ // // @ts-ignore
1307
+ // const columnKey = columns[targetCol].field;
1308
+ //
1309
+ // // @ts-ignore
1310
+ // newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
1311
+ // pastedColumns.add(columnKey);
1312
+ // }
1313
+ //
1314
+ // });
1315
+ //
1316
+ // // Lưu dòng được paste
1317
+ // pastedRows.push(newData[targetRow]);
1318
+ //
1319
+ // });
1320
+ //
1321
+ // const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1322
+ //
1323
+ // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
1324
+ //
1325
+ //
1326
+ // } else {
1327
+ //
1328
+ // // Cập nhật data mới
1329
+ // const newData = [...dataSource];
1330
+ //
1331
+ // const parent = findItemByKey(newData, rowKey as any, record.parentId)
1332
+ //
1333
+ // // Cập nhật childData mới
1334
+ // const childData: any[] = parent?.children ? [...parent.children] : []
1335
+ //
1336
+ //
1337
+ // // Lấy vị trí bắt đầu
1338
+ // // const { row: startRow, col: startCol } = selectedCell;
1339
+ // const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
1340
+ // const startCol = indexCol
1341
+ //
1342
+ // const pastedRows: RecordType[] = []
1343
+ // const pastedColumns = new Set()
1344
+ //
1345
+ //
1346
+ // rows.forEach((rowValues: any, rowIndex: any) => {
1347
+ // const targetRow = startRow + rowIndex
1348
+ //
1349
+ // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1350
+ // if (targetRow >= childData.length) {
1351
+ //
1352
+ // childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
1353
+ // }
1354
+ //
1355
+ // rowValues.forEach((cellValue: any, colIndex: any) => {
1356
+ // const targetCol = startCol + colIndex
1357
+ // if (targetCol >= columns.length) { // Không vượt quá số cột
1358
+ // return
1359
+ // }
1360
+ //
1361
+ // if (columns[targetCol].editEnable) {
1362
+ //
1363
+ // // @ts-ignore
1364
+ // const columnKey = columns[targetCol].field
1365
+ //
1366
+ // // @ts-ignore
1367
+ // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
1368
+ // pastedColumns.add(columnKey)
1369
+ // }
1370
+ //
1371
+ // })
1372
+ //
1373
+ // // Lưu dòng được paste
1374
+ // pastedRows.push(childData[targetRow])
1375
+ //
1376
+ // })
1377
+ //
1378
+ // const pastedColumnsArray = Array.from(pastedColumns) ?? []
1379
+ //
1380
+ // const newRowData = {...parent, children: childData}
1381
+ //
1382
+ // const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
1383
+ //
1384
+ // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
1385
+ // }
1224
1386
  };
1225
- const handleClickColHeader = (column, indexColumn) => {
1226
- const newSelectedCells = new Set();
1227
- for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
1228
- for (let c = Math.min(indexColumn, indexColumn); c <= Math.max(indexColumn, indexColumn); c++) {
1229
- newSelectedCells.add(`${r}-${c}`);
1387
+ const handlePointDoubleClick = e => {
1388
+ // e.preventDefault()
1389
+ e.stopPropagation();
1390
+ const colStart = getFirstSelectCell(selectedCells.current).col;
1391
+ const colEnd = getLastSelectCell(selectedCells.current).col;
1392
+ const startPasteRow = getLastSelectCell(selectedCells.current).row;
1393
+ const newPasteCells = new Set();
1394
+ for (let r = Math.min(startPasteRow, dataSource.length - 1) + 1; r <= Math.max(startPasteRow, dataSource.length - 1); r++) {
1395
+ for (let c = Math.min(colStart, colStart); c <= Math.max(colStart, colEnd); c++) {
1396
+ newPasteCells.add(`${r}-${c}`);
1230
1397
  }
1231
1398
  }
1232
-
1233
- // setSelectedCells(new Set(newSelectedCells));
1234
-
1235
- if (selectedCells.current && selectedCells.current.size > 0) {
1236
- // onRemoveBgSelectedCell(selectedCells.current, id)
1237
- // onRemoveBorderSelectedCell(selectedCells.current, id)
1238
- }
1239
- if (rowsSelected.current && rowsSelected.current.size > 0) {
1240
- removeClassCellIndexSelected(rowsSelected.current, id);
1241
- }
1242
- selectedCells.current = newSelectedCells;
1243
-
1244
- // onAddBgSelectedCell(newSelectedCells, id)
1245
- // onAddBorderSelectedCell(newSelectedCells, id)
1246
-
1247
1399
  hideDraggingPoint(selectedCells.current, id);
1248
- showDraggingPoint(newSelectedCells, id);
1400
+ triggerDragPaste(newPasteCells);
1249
1401
  };
1250
- const handleMouseDownRowHeader = (row, col, column, e) => {
1402
+ const handleMouseDown = (record, row, col, e) => {
1251
1403
  if (e.button === 2) {
1252
1404
  e.stopPropagation();
1253
1405
  return;
1254
1406
  }
1255
- if (editingKey) {
1256
- setEditingKey('');
1407
+ if (editingKey && editingKey === record[rowKey]) {
1408
+ return;
1257
1409
  }
1258
- isSelectingRow.current = true;
1259
- rowStart.current = {
1260
- row,
1261
- col
1262
- };
1263
- const newSelectedCells = new Set();
1264
- const tCols = editAbleColumns(visibleCols);
1265
- for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
1266
- for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
1267
- newSelectedCells.add(`${r}-${c}`);
1410
+ if (record[rowKey] !== editingKey && editingKey !== '') {
1411
+ setTimeout(() => {
1412
+ setEditingKey('');
1413
+ });
1414
+ }
1415
+
1416
+ // isDragMouse.current = true
1417
+ isMouseDown.current = true;
1418
+ if (e.ctrlKey) {
1419
+ isSelecting.current = true;
1420
+ startCell.current = {
1421
+ row,
1422
+ col
1423
+ };
1424
+
1425
+ // const cell: any = new Set([`${row}-${col}`])
1426
+
1427
+ // setCurrentCtrlCells(cell)
1428
+ } else {
1429
+ isSelecting.current = true;
1430
+ startCell.current = {
1431
+ row,
1432
+ col
1433
+ };
1434
+ const target = e.target;
1435
+ if (target.closest('.dragging-point')) {
1436
+ e.stopPropagation();
1437
+ e.preventDefault();
1438
+ return; // Không xử lý gì cả
1439
+ } else {
1440
+ // setStartSelectedCell({row, col})
1441
+
1442
+ startSelectedCells.current = {
1443
+ row,
1444
+ col
1445
+ };
1446
+
1447
+ // setSelectedCells(new Set([`${row}-${col}`]));
1448
+
1449
+ const cells = new Set([`${row}-${col}`]);
1450
+ if (selectedCells.current && selectedCells.current.size > 0) {
1451
+ if (!isEqualSet(cells, rangeCells)) {
1452
+ // onRemoveBgSelectedCell(rangeCells, id)
1453
+ // onRemoveBorderSelectedCell(rangeCells, id)
1454
+ hideDraggingPoint(rangeCells, id);
1455
+ onRemoveBgCellIndex(selectedCells.current, id);
1456
+ }
1457
+ }
1458
+ if (rowsSelected.current && rowsSelected.current.size > 0) {
1459
+ removeClassCellIndexSelected(rowsSelected.current, id);
1460
+ }
1461
+ if (!isEqualSet(cells, selectedCells.current)) {
1462
+ onRemoveBgSelectedCell(selectedCells.current, id);
1463
+ hideDraggingPoint(selectedCells.current, id);
1464
+ selectedCells.current = cells;
1465
+ // setRangeCells(cells)
1466
+
1467
+ onAddBgCellIndex(cells, id);
1468
+ onAddBorderSelectedCell(cells, id);
1469
+ onAddBgSelectedCell(selectedCells.current, id, false);
1470
+ showDraggingPoint(selectedCells.current, id);
1471
+ }
1472
+
1473
+ // setRowsSelected(new Set())
1474
+ rowsSelected.current = new Set();
1475
+ }
1476
+ }
1477
+ };
1478
+ const handleMouseUp = e => {
1479
+ isSelecting.current = false;
1480
+ startCell.current = null;
1481
+ isSelectingRow.current = false;
1482
+ rowStart.current = null;
1483
+ isDragMouse.current = false;
1484
+ isMouseDown.current = false;
1485
+ setIsPasteDragging(false);
1486
+ if (e.ctrlKey) {
1487
+
1488
+ // setCtrlCells([...ctrlCells, currentCtrlCells])
1489
+ }
1490
+
1491
+ // nếu ctrlCell length > 0 thì set selectCells
1492
+
1493
+ if (pasteCells && pasteCells.current.size > 0) {
1494
+ triggerDragPaste(pasteCells.current);
1495
+ } else {
1496
+ setRangeCells(selectedCells.current);
1497
+ const target = e.target;
1498
+ if (target.closest('.dragging-point')) {
1499
+ e.stopPropagation();
1500
+ e.preventDefault();
1501
+ return; // Không xử lý gì cả
1502
+ }
1503
+ if (selectedCells.current && selectedCells.current.size > 1) {
1504
+ hideDraggingPoint(selectedCells.current, id);
1505
+ onAddBorderSelectedCell(selectedCells.current, id);
1506
+
1507
+ // showDraggingPoint(selectedCells.current, id)
1508
+ }
1509
+ showDraggingPoint(selectedCells.current, id);
1510
+ // onAddBorderSelectedCell(selectedCells.current, id)
1511
+ }
1512
+ };
1513
+ const handleMouseEnter = (row, col, e) => {
1514
+ if (!isSelecting.current || !startCell.current) {
1515
+ return;
1516
+ }
1517
+ const {
1518
+ row: startRow,
1519
+ col: startCol
1520
+ } = startCell.current;
1521
+ if (e.ctrlKey) {
1522
+ // const newCtrlCells = new Set();
1523
+ // for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1524
+ // for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1525
+ // newCtrlCells.add(`${r}-${c}`)
1526
+ // }
1527
+ // }
1528
+
1529
+ // setCurrentCtrlCells(newCtrlCells)
1530
+
1531
+ return;
1532
+ }
1533
+ if (!isPasteDragging) {
1534
+ // chọn vùng copy
1535
+
1536
+ // setSelectIsDragging(true)
1537
+
1538
+ setIsPasteDragging(false);
1539
+ // isPasteDragging.current = false
1540
+
1541
+ const newSelectedCells = new Set();
1542
+ for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1543
+ for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1544
+ newSelectedCells.add(`${r}-${c}`);
1545
+ }
1546
+ }
1547
+
1548
+ // setSelectedCells(newSelectedCells)
1549
+
1550
+ if (selectedCells.current && selectedCells.current.size > 0) {
1551
+ onRemoveBgSelectedCell(selectedCells.current, id);
1552
+ }
1553
+ selectedCells.current = newSelectedCells;
1554
+ onAddBgSelectedCell(newSelectedCells, id);
1555
+ } else {
1556
+ // chọn vùng paste
1557
+
1558
+ // setSelectIsDragging(false)
1559
+
1560
+ // setIsPasteDragging(true) ////////
1561
+
1562
+ const newSelectedCells = new Set();
1563
+ for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1564
+ for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1565
+ newSelectedCells.add(`${r}-${c}`);
1566
+ }
1567
+ }
1568
+ const colStart = getFirstSelectCell(selectedCells.current).col;
1569
+ const colEnd = getLastSelectCell(selectedCells.current).col;
1570
+ const rowSelectedEnd = getLastSelectCell(selectedCells.current).row;
1571
+ if (row >= rowSelectedEnd) {
1572
+ // kéo xuống dưới
1573
+
1574
+ const newPasteCells = new Set();
1575
+ for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
1576
+ for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1577
+ newPasteCells.add(`${r}-${c}`);
1578
+ }
1579
+ }
1580
+
1581
+ // setPasteCells(newPasteCells)
1582
+
1583
+ if (pasteCells.current && pasteCells.current.size > 0) {
1584
+ removeClassBorderPasteCell(pasteCells.current, 'down', id);
1585
+ }
1586
+ pasteCells.current = newPasteCells;
1587
+ addClassBorderPasteCell(newPasteCells, 'down', id);
1588
+ }
1589
+ if (row < rowSelectedEnd) {
1590
+ // kéo lên trên
1591
+
1592
+ const rowSelectedStart = getFirstSelectCell(selectedCells.current).row;
1593
+ if (row < rowSelectedStart) {
1594
+ const newPasteCells = new Set();
1595
+ for (let r = Math.min(rowSelectedStart, row); r <= Math.max(rowSelectedStart, row) - 1; r++) {
1596
+ for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1597
+ newPasteCells.add(`${r}-${c}`);
1598
+ }
1599
+ }
1600
+
1601
+ // setPasteCells(newPasteCells)
1602
+
1603
+ if (pasteCells.current && pasteCells.current.size > 0) {
1604
+ removeClassBorderPasteCell(pasteCells.current, 'up', id);
1605
+ }
1606
+ pasteCells.current = newPasteCells;
1607
+ addClassBorderPasteCell(newPasteCells, 'up', id);
1608
+ }
1609
+ }
1610
+ if (col > colEnd) {
1611
+ // kéo sang phải
1612
+ }
1613
+ if (row < colStart) {
1614
+ // kéo sang trái
1615
+ }
1616
+ }
1617
+ };
1618
+ const handleClickColHeader = (column, indexColumn) => {
1619
+ const newSelectedCells = new Set();
1620
+ for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
1621
+ for (let c = Math.min(indexColumn, indexColumn); c <= Math.max(indexColumn, indexColumn); c++) {
1622
+ newSelectedCells.add(`${r}-${c}`);
1623
+ }
1624
+ }
1625
+
1626
+ // setSelectedCells(new Set(newSelectedCells));
1627
+
1628
+ if (selectedCells.current && selectedCells.current.size > 0) {
1629
+ // onRemoveBgSelectedCell(selectedCells.current, id)
1630
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
1631
+ }
1632
+ if (rowsSelected.current && rowsSelected.current.size > 0) {
1633
+ removeClassCellIndexSelected(rowsSelected.current, id);
1634
+ }
1635
+ selectedCells.current = newSelectedCells;
1636
+
1637
+ // onAddBgSelectedCell(newSelectedCells, id)
1638
+ // onAddBorderSelectedCell(newSelectedCells, id)
1639
+
1640
+ hideDraggingPoint(selectedCells.current, id);
1641
+ showDraggingPoint(newSelectedCells, id);
1642
+ };
1643
+ const handleMouseDownRowHeader = (row, col, column, e) => {
1644
+ if (e.button === 2) {
1645
+ e.stopPropagation();
1646
+ return;
1647
+ }
1648
+ if (editingKey) {
1649
+ setEditingKey('');
1650
+ }
1651
+ isSelectingRow.current = true;
1652
+ rowStart.current = {
1653
+ row,
1654
+ col
1655
+ };
1656
+ const newSelectedCells = new Set();
1657
+ const tCols = editAbleColumns(visibleCols);
1658
+ for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
1659
+ for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
1660
+ newSelectedCells.add(`${r}-${c}`);
1268
1661
  }
1269
1662
  }
1270
1663
  if (selectedCells.current && selectedCells.current.size > 0) {
@@ -1308,357 +1701,87 @@ const GridEdit = props => {
1308
1701
  for (let c = Math.min(editAbleColumns(columns).length, col) + 1; c <= Math.max(editAbleColumns(columns).length, col); c++) {
1309
1702
  newSelectedCells.add(`${r}-${c}`);
1310
1703
  }
1311
- }
1312
- if (selectedCells.current && selectedCells.current.size > 0) {
1313
- onRemoveBgSelectedCell(selectedCells.current, id);
1314
- }
1315
- selectedCells.current = newSelectedCells;
1316
- onAddBgSelectedCell(newSelectedCells, id);
1317
- if (rowsSelected.current && rowsSelected.current.size > 0) {
1318
- removeClassCellIndexSelected(rowsSelected.current, id);
1319
- }
1320
- rowsSelected.current = newSelectedRows;
1321
- addClassCellIndexSelected(newSelectedRows, id);
1322
- };
1323
- const handleCellClick = (indexRow, record, column) => {
1324
- const cellClickCallback = newOptions => {
1325
- if (newOptions) {
1326
- const newElem = {
1327
- ...column,
1328
- editSelectSettings: {
1329
- ...(column?.editSelectSettings ? {
1330
- ...column?.editSelectSettings
1331
- } : {}),
1332
- options: newOptions
1333
- }
1334
- };
1335
- const rrr = updateArrayByKey([...columns], newElem, 'field');
1336
- triggerChangeColumns?.(rrr, 'click');
1337
- }
1338
- };
1339
- if (onCellClick) {
1340
- onCellClick({
1341
- index: indexRow,
1342
- rowId: record.rowId,
1343
- cellValue: record[record.field],
1344
- type: "Editing",
1345
- field: column.field,
1346
- rowData: record
1347
- }, cellClickCallback);
1348
- }
1349
- };
1350
- const handleCopy = e => {
1351
- const selectedArray = Array.from(selectedCells.current).map(key => {
1352
- const [row, col] = key.split("-").map(Number);
1353
- // @ts-ignore
1354
- const columnKey = editAbleColumns(columns)[col - 1].field;
1355
-
1356
- // @ts-ignore
1357
- return {
1358
- row,
1359
- col,
1360
- value: flattenData(childrenColumnName, dataSource)[row][columnKey] ?? ''
1361
- };
1362
- // return { row, col, value: '' };
1363
- });
1364
-
1365
- // Xác định min/max row và col để sắp xếp dữ liệu
1366
- const minRow = Math.min(...selectedArray.map(cell => cell.row));
1367
- const maxRow = Math.max(...selectedArray.map(cell => cell.row));
1368
- const minCol = Math.min(...selectedArray.map(cell => cell.col));
1369
- const maxCol = Math.max(...selectedArray.map(cell => cell.col));
1370
-
1371
- // Tạo dữ liệu dạng bảng (mảng 2D)
1372
- const table = Array.from({
1373
- length: maxRow - minRow + 1
1374
- }, () => Array(maxCol - minCol + 1).fill(""));
1375
-
1376
- // Gán giá trị vào bảng
1377
- selectedArray.forEach(({
1378
- row,
1379
- col,
1380
- value
1381
- }) => {
1382
- table[row - minRow][col - minCol] = value;
1383
- });
1384
-
1385
- // Chuyển mảng 2D thành chuỗi định dạng Excel
1386
- const copyText = table.map(row => row.join("\t")).join("\n");
1387
-
1388
- // Copy vào clipboard
1389
- e.preventDefault();
1390
- e.clipboardData.setData("text/plain", copyText);
1391
- Message(t ? t('CopySuccessful') : 'Copy Successful');
1392
- };
1393
- const handlePasted = (record, indexCol, rowNumber, pasteData) => {
1394
- const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1395
- if (!record?.parentId) {
1396
- // Cập nhật data mới
1397
- const newData = [...dataSource];
1398
-
1399
- // const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
1400
-
1401
- // Lấy vị trí bắt đầu
1402
- // const { row: startRow, col: startCol } = selectedCell;
1403
- const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
1404
- const startCol = indexCol;
1405
-
1406
- // const flattData = flattenArray(newData);
1407
-
1408
- const pastedRows = [];
1409
- const pastedColumns = new Set();
1410
- rows.forEach((rowValues, rowIndex) => {
1411
- const targetRow = startRow + rowIndex;
1412
-
1413
- // Nếu vượt quá số dòng hiện có, thêm dòng mới
1414
- if (targetRow >= newData.length) {
1415
- // @ts-ignore
1416
- // newData.push({ id: newGuid()});
1417
- newData.push({
1418
- id: undefined,
1419
- rowId: newGuid()
1420
- });
1421
- }
1422
- rowValues.forEach((cellValue, colIndex) => {
1423
- const targetCol = startCol + colIndex;
1424
- if (targetCol >= visibleCols.length) {
1425
- // Không vượt quá số cột
1426
- return;
1427
- }
1428
- if (visibleCols[targetCol].editEnable) {
1429
- // @ts-ignore
1430
- const columnKey = visibleCols[targetCol].field;
1431
-
1432
- // @ts-ignore
1433
- newData[targetRow] = {
1434
- ...newData[targetRow],
1435
- [columnKey]: cellValue.trim()
1436
- };
1437
- pastedColumns.add(columnKey);
1438
- }
1439
- });
1440
-
1441
- // Lưu dòng được paste
1442
- pastedRows.push(newData[targetRow]);
1443
- });
1444
- const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1445
- triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1446
- } else {
1447
- // Cập nhật data mới
1448
- const newData = [...dataSource];
1449
- const parent = findItemByKey(newData, rowKey, record.parentId);
1450
-
1451
- // Cập nhật childData mới
1452
- const childData = parent?.children ? [...parent.children] : [];
1453
-
1454
- // Lấy vị trí bắt đầu
1455
- // const { row: startRow, col: startCol } = selectedCell;
1456
- const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
1457
- const startCol = indexCol;
1458
- const pastedRows = [];
1459
- const pastedColumns = new Set();
1460
- rows.forEach((rowValues, rowIndex) => {
1461
- const targetRow = startRow + rowIndex;
1462
-
1463
- // Nếu vượt quá số dòng hiện có, thêm dòng mới
1464
- if (targetRow >= childData.length) {
1465
- childData.push({
1466
- id: undefined,
1467
- rowId: newGuid(),
1468
- parentId: parent[rowKey ?? 'id']
1469
- });
1470
- }
1471
- rowValues.forEach((cellValue, colIndex) => {
1472
- const targetCol = startCol + colIndex;
1473
- if (targetCol >= visibleCols.length) {
1474
- // Không vượt quá số cột
1475
- return;
1476
- }
1477
- if (visibleCols[targetCol].editEnable) {
1478
- // @ts-ignore
1479
- const columnKey = visibleCols[targetCol].field;
1480
-
1481
- // @ts-ignore
1482
- childData[targetRow] = {
1483
- ...childData[targetRow],
1484
- [columnKey]: cellValue.trim()
1485
- };
1486
- pastedColumns.add(columnKey);
1487
- }
1488
- });
1489
-
1490
- // Lưu dòng được paste
1491
- pastedRows.push(childData[targetRow]);
1492
- });
1493
- const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1494
- const newRowData = {
1495
- ...parent,
1496
- children: childData
1497
- };
1498
- const newDataSource = updateArrayByKey(newData, newRowData, rowKey);
1499
- triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
1500
- }
1501
- };
1502
- const handlePaste = (record, indexCol, rowNumber, e) => {
1503
- // const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
1504
- const pasteData = e.clipboardData.getData("text/plain");
1505
-
1506
- // Chuyển đổi dữ liệu từ clipboard thành mảng
1507
- const rowsPasted = pasteData.split("\n").map(row =>
1508
- // const rows = pasteData.split("\n").map((row: any) =>
1509
- row.replace(/\r/g, "").split("\t"));
1510
- if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
1511
- // bật popup thông báo
1512
-
1513
- Modal.confirm({
1514
- content: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Paragraph, {
1515
- style: {
1516
- marginBottom: '.25rem',
1517
- fontSize: 14
1518
- }
1519
- }, "D\u1EEF li\u1EC7u sao ch\xE9p v\u01B0\u1EE3t qu\xE1 s\u1ED1 d\xF2ng cho ph\xE9p (500 d\xF2ng).Ph\u1EA7n m\u1EC1n s\u1EBD ch\u1EC9 l\u1EA5y 500 d\xF2ng \u0111\u1EA7u ti\xEAn."), /*#__PURE__*/React.createElement(Title, {
1520
- level: 5,
1521
- style: {
1522
- marginTop: '.75rem'
1523
- }
1524
- }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
1525
- centered: true,
1526
- className: 'be-popup-container',
1527
- onOk: () => {
1528
- handlePasted(record, indexCol, rowNumber, rowsPasted);
1529
- }
1530
- // footer: (_, { OkBtn, CancelBtn }) => (
1531
- // <>
1532
- // <OkBtn />
1533
- // <CancelBtn />
1534
- // </>
1535
- // ),
1536
- });
1537
- } else {
1538
- handlePasted(record, indexCol, rowNumber, rowsPasted);
1539
- }
1540
-
1541
- // const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
1542
- //
1543
- //
1544
- // if (!record?.parentId ) {
1545
- //
1546
- // // Cập nhật data mới
1547
- // const newData = [...dataSource];
1548
- //
1549
- // // @ts-ignore
1550
- // const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
1551
- //
1552
- // // Lấy vị trí bắt đầu
1553
- // // const { row: startRow, col: startCol } = selectedCell;
1554
- // const startRow = indexRows
1555
- // const startCol = indexCol
1556
- //
1557
- //
1558
- //
1559
- // // const flattData = flattenArray(newData);
1560
- //
1561
- // const pastedRows: RecordType[] = [];
1562
- // const pastedColumns = new Set()
1563
- //
1564
- //
1565
- // rows.forEach((rowValues: any, rowIndex: any) => {
1566
- // const targetRow = startRow + rowIndex;
1567
- //
1568
- // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1569
- // if (targetRow >= newData.length) {
1570
- // // @ts-ignore
1571
- // // newData.push({ id: newGuid()});
1572
- // newData.push({ id: undefined, rowId: newGuid()});
1573
- // }
1574
- //
1575
- // rowValues.forEach((cellValue: any, colIndex: any) => {
1576
- // const targetCol = startCol + colIndex;
1577
- // if (targetCol >= columns.length) { // Không vượt quá số cột
1578
- // return
1579
- // }
1580
- //
1581
- // if (columns[targetCol].editEnable) {
1582
- // // @ts-ignore
1583
- // const columnKey = columns[targetCol].field;
1584
- //
1585
- // // @ts-ignore
1586
- // newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
1587
- // pastedColumns.add(columnKey);
1588
- // }
1589
- //
1590
- // });
1591
- //
1592
- // // Lưu dòng được paste
1593
- // pastedRows.push(newData[targetRow]);
1594
- //
1595
- // });
1596
- //
1597
- // const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1598
- //
1599
- // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
1600
- //
1601
- //
1602
- // } else {
1603
- //
1604
- // // Cập nhật data mới
1605
- // const newData = [...dataSource];
1606
- //
1607
- // const parent = findItemByKey(newData, rowKey as any, record.parentId)
1608
- //
1609
- // // Cập nhật childData mới
1610
- // const childData: any[] = parent?.children ? [...parent.children] : []
1611
- //
1612
- //
1613
- // // Lấy vị trí bắt đầu
1614
- // // const { row: startRow, col: startCol } = selectedCell;
1615
- // const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
1616
- // const startCol = indexCol
1617
- //
1618
- // const pastedRows: RecordType[] = []
1619
- // const pastedColumns = new Set()
1620
- //
1621
- //
1622
- // rows.forEach((rowValues: any, rowIndex: any) => {
1623
- // const targetRow = startRow + rowIndex
1624
- //
1625
- // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1626
- // if (targetRow >= childData.length) {
1627
- //
1628
- // childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
1629
- // }
1630
- //
1631
- // rowValues.forEach((cellValue: any, colIndex: any) => {
1632
- // const targetCol = startCol + colIndex
1633
- // if (targetCol >= columns.length) { // Không vượt quá số cột
1634
- // return
1635
- // }
1636
- //
1637
- // if (columns[targetCol].editEnable) {
1638
- //
1639
- // // @ts-ignore
1640
- // const columnKey = columns[targetCol].field
1641
- //
1642
- // // @ts-ignore
1643
- // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
1644
- // pastedColumns.add(columnKey)
1645
- // }
1646
- //
1647
- // })
1648
- //
1649
- // // Lưu dòng được paste
1650
- // pastedRows.push(childData[targetRow])
1651
- //
1652
- // })
1653
- //
1654
- // const pastedColumnsArray = Array.from(pastedColumns) ?? []
1655
- //
1656
- // const newRowData = {...parent, children: childData}
1657
- //
1658
- // const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
1659
- //
1660
- // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
1661
- // }
1704
+ }
1705
+ if (selectedCells.current && selectedCells.current.size > 0) {
1706
+ onRemoveBgSelectedCell(selectedCells.current, id);
1707
+ }
1708
+ selectedCells.current = newSelectedCells;
1709
+ onAddBgSelectedCell(newSelectedCells, id);
1710
+ if (rowsSelected.current && rowsSelected.current.size > 0) {
1711
+ removeClassCellIndexSelected(rowsSelected.current, id);
1712
+ }
1713
+ rowsSelected.current = newSelectedRows;
1714
+ addClassCellIndexSelected(newSelectedRows, id);
1715
+ };
1716
+ const handleCellClick = (indexRow, record, column) => {
1717
+ const cellClickCallback = newOptions => {
1718
+ if (newOptions) {
1719
+ const newElem = {
1720
+ ...column,
1721
+ editSelectSettings: {
1722
+ ...(column?.editSelectSettings ? {
1723
+ ...column?.editSelectSettings
1724
+ } : {}),
1725
+ options: newOptions
1726
+ }
1727
+ };
1728
+ const rrr = updateArrayByKey([...columns], newElem, 'field');
1729
+ triggerChangeColumns?.(rrr, 'click');
1730
+ }
1731
+ };
1732
+ if (onCellClick) {
1733
+ onCellClick({
1734
+ index: indexRow,
1735
+ rowId: record.rowId,
1736
+ cellValue: record[record.field],
1737
+ type: "Editing",
1738
+ field: column.field,
1739
+ rowData: record
1740
+ }, cellClickCallback);
1741
+ }
1742
+ };
1743
+ const handleCopy = e => {
1744
+ const selectedArray = Array.from(selectedCells.current).map(key => {
1745
+ const [row, col] = key.split("-").map(Number);
1746
+ // @ts-ignore
1747
+ const columnKey = editAbleColumns(columns)[col - 1].field;
1748
+
1749
+ // @ts-ignore
1750
+ return {
1751
+ row,
1752
+ col,
1753
+ value: flattenData(childrenColumnName, dataSource)[row][columnKey] ?? ''
1754
+ };
1755
+ // return { row, col, value: '' };
1756
+ });
1757
+
1758
+ // Xác định min/max row và col để sắp xếp dữ liệu
1759
+ const minRow = Math.min(...selectedArray.map(cell => cell.row));
1760
+ const maxRow = Math.max(...selectedArray.map(cell => cell.row));
1761
+ const minCol = Math.min(...selectedArray.map(cell => cell.col));
1762
+ const maxCol = Math.max(...selectedArray.map(cell => cell.col));
1763
+
1764
+ // Tạo dữ liệu dạng bảng (mảng 2D)
1765
+ const table = Array.from({
1766
+ length: maxRow - minRow + 1
1767
+ }, () => Array(maxCol - minCol + 1).fill(""));
1768
+
1769
+ // Gán giá trị vào bảng
1770
+ selectedArray.forEach(({
1771
+ row,
1772
+ col,
1773
+ value
1774
+ }) => {
1775
+ table[row - minRow][col - minCol] = value;
1776
+ });
1777
+
1778
+ // Chuyển mảng 2D thành chuỗi định dạng Excel
1779
+ const copyText = table.map(row => row.join("\t")).join("\n");
1780
+
1781
+ // Copy vào clipboard
1782
+ e.preventDefault();
1783
+ e.clipboardData.setData("text/plain", copyText);
1784
+ Message(t ? t('CopySuccessful') : 'Copy Successful');
1662
1785
  };
1663
1786
  const onSubmit = formData => {
1664
1787
  try {
@@ -1896,312 +2019,344 @@ const GridEdit = props => {
1896
2019
  focusNextCell(cellEdit, cell);
1897
2020
  }
1898
2021
  };
1899
- const convertColumns = React.useMemo(() => {
1900
- return flatColumns2(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
1901
- if (column === SELECTION_COLUMN) {
1902
- return SELECTION_COLUMN;
1903
- }
1904
- if (column.field === '#') {
1905
- return {
1906
- ...column,
1907
- className: 'rc-ui-cell-editable rc-ui-cell-index',
1908
- onCell: (record, rowIndex) => {
1909
- const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
1910
- return {
1911
- 'data-row-index': rowNumber,
1912
- onPaste: event => {
1913
- if (editingKey === '') {
1914
- handlePaste(record, colIndex + 1, rowNumber, event);
1915
- event.preventDefault();
1916
- }
1917
- },
1918
- onCopy: e => {
1919
- if (editingKey === '') {
1920
- handleCopy(e);
1921
- e.preventDefault();
1922
- }
1923
- },
1924
- // onClick: () => {
1925
- // if (record[rowKey] !== editingKey && (editingKey !== '')) {
1926
- // setEditingKey('')
1927
- // }
1928
- // },
1929
- tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex
1930
- };
1931
- },
1932
- render: (value, record) => {
1933
- const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
1934
- return /*#__PURE__*/React.createElement("div", {
1935
- className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {}),
1936
- onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
1937
- onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
1938
- onMouseUp: event => handleMouseUp(event)
1939
- }, /*#__PURE__*/React.createElement("div", {
1940
- className: 'ui-rc_content'
1941
- }, findItemPath(dataSource, record, rowKey)));
1942
- }
1943
- };
1944
- }
1945
- if (column.field === 'command') {
1946
- return {
1947
- ...column
1948
- };
1949
- }
2022
+ const convertColumns = flatColumns2(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
2023
+ if (column === SELECTION_COLUMN) {
2024
+ return SELECTION_COLUMN;
2025
+ }
2026
+ if (column.field === '#') {
1950
2027
  return {
1951
2028
  ...column,
2029
+ className: 'rc-ui-cell-editable rc-ui-cell-index',
1952
2030
  onCell: (record, rowIndex) => {
1953
2031
  const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
1954
2032
  return {
1955
- ...column?.onCell?.(record, rowIndex),
1956
- onKeyDown: event => {
1957
- const key = getRowKey(record, dataSource.indexOf(record));
1958
- if (event.key === 'Control' && event.ctrlKey) {} else {
1959
- if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
1960
- if (record[rowKey] !== editingKey && isEditable(column, record)) {
1961
- // ~~ khi editingKey = ''
1962
- event.preventDefault();
1963
- event.stopPropagation();
1964
- handleEdit(record, column, column.editType, event);
2033
+ 'data-row-index': rowNumber,
2034
+ onPaste: event => {
2035
+ if (editingKey === '') {
2036
+ handlePaste(record, colIndex + 1, rowNumber, event);
2037
+ event.preventDefault();
2038
+ }
2039
+ },
2040
+ onCopy: e => {
2041
+ if (editingKey === '') {
2042
+ handleCopy(e);
2043
+ e.preventDefault();
2044
+ }
2045
+ },
2046
+ // onClick: () => {
2047
+ // if (record[rowKey] !== editingKey && (editingKey !== '')) {
2048
+ // setEditingKey('')
2049
+ // }
2050
+ // },
2051
+ tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex
2052
+ };
2053
+ },
2054
+ render: (value, record) => {
2055
+ const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
2056
+ return /*#__PURE__*/React.createElement("div", {
2057
+ className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {}),
2058
+ onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
2059
+ onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
2060
+ onMouseUp: event => handleMouseUp(event)
2061
+ }, /*#__PURE__*/React.createElement("div", {
2062
+ className: 'ui-rc_content'
2063
+ }, findItemPath(dataSource, record, rowKey)));
2064
+ }
2065
+ };
2066
+ }
2067
+ if (column.field === 'command') {
2068
+ return {
2069
+ ...column
2070
+ };
2071
+ }
2072
+ return {
2073
+ ...column,
2074
+ onCell: (record, rowIndex) => {
2075
+ const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
2076
+ return {
2077
+ ...column?.onCell?.(record, rowIndex),
2078
+ onKeyDown: event => {
2079
+ const key = getRowKey(record, dataSource.indexOf(record));
2080
+ if (event.key === 'Control' && event.ctrlKey) {} else {
2081
+ if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
2082
+ if (record[rowKey] !== editingKey && isEditable(column, record)) {
2083
+ // ~~ khi editingKey = ''
2084
+ event.preventDefault();
2085
+ event.stopPropagation();
2086
+ handleEdit(record, column, column.editType, event);
1965
2087
 
1966
- // onRemoveBgSelectedCell(selectedCells.current, id)
1967
- // onRemoveBorderSelectedCell(selectedCells.current, id)
2088
+ // onRemoveBgSelectedCell(selectedCells.current, id)
2089
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
1968
2090
 
1969
- // selectedCells.current = new Set()
2091
+ // selectedCells.current = new Set()
1970
2092
 
1971
- handleCellClick(rowNumber, record, column);
1972
- const hasKey = mergedExpandedKeys.has(key);
1973
- if (hasKey) {
1974
- // mergedExpandedKeys.delete(key);
1975
- // newExpandedKeys = [...mergedExpandedKeys];
1976
- } else {
1977
- onTriggerExpand(record);
1978
- }
2093
+ handleCellClick(rowNumber, record, column);
2094
+ const hasKey = mergedExpandedKeys.has(key);
2095
+ if (hasKey) {
2096
+ // mergedExpandedKeys.delete(key);
2097
+ // newExpandedKeys = [...mergedExpandedKeys];
1979
2098
  } else {
1980
- if (event.key === 'Enter') {
1981
- event.preventDefault();
1982
- event.stopPropagation();
1983
- if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length && event.key === 'Enter') {
1984
- handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
1985
- } else {
1986
- // // focus cell hiện tại và tắt edit
1987
- // handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
1988
- // setEditingKey('')
1989
-
1990
- // thêm dòng mới
1991
-
1992
- handleAddSingle();
1993
- handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true);
1994
- }
1995
- }
2099
+ onTriggerExpand(record);
1996
2100
  }
1997
- }
1998
- if (event.key === 'Tab') {
1999
- if (editingKey) {} else {
2000
- if (colIndex + 1 !== visibleCols.length) {
2001
- handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
2101
+ } else {
2102
+ if (event.key === 'Enter') {
2103
+ event.preventDefault();
2104
+ event.stopPropagation();
2105
+ if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length && event.key === 'Enter') {
2106
+ handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
2002
2107
  } else {
2003
- event.stopPropagation();
2004
- event.preventDefault();
2108
+ // // focus cell hiện tại và tắt edit
2109
+ // handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
2110
+ // setEditingKey('')
2111
+
2112
+ // thêm dòng mới
2113
+
2114
+ handleAddSingle();
2115
+ handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true);
2005
2116
  }
2006
2117
  }
2007
2118
  }
2008
- if (event.key === 'ArrowRight' && colIndex + 1 !== visibleCols.length) {
2009
- if (editingKey !== '') {} else {
2119
+ }
2120
+ if (event.key === 'Tab') {
2121
+ if (editingKey) {} else {
2122
+ if (colIndex + 1 !== visibleCols.length) {
2010
2123
  handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
2011
- }
2012
- }
2013
- if (event.key === 'ArrowLeft' && colIndex > 0) {
2014
- if (!column.dataIndex && !column.key || column.field === '#' || column.dataIndex === '#') {
2124
+ } else {
2015
2125
  event.stopPropagation();
2016
2126
  event.preventDefault();
2017
- } else {
2018
- if (editingKey !== '') {} else {
2019
- handleFocusCell(rowNumber, colIndex - 1, column, 'horizontal', event);
2020
- }
2021
2127
  }
2022
2128
  }
2023
- if (event.key === 'ArrowDown' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length) {
2024
- if (isEditing(record) && (getEditType(column, record) === 'treeSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'asyncSelect')) {
2025
- event.stopPropagation();
2026
- } else {
2027
- handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
2028
- }
2129
+ }
2130
+ if (event.key === 'ArrowRight' && colIndex + 1 !== visibleCols.length) {
2131
+ if (editingKey !== '') {} else {
2132
+ handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
2029
2133
  }
2030
- if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
2031
- if (isEditing(record) && (getEditType(column, record) === 'asyncSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'treeSelect')) {
2032
- event.stopPropagation();
2033
- } else {
2034
- handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
2134
+ }
2135
+ if (event.key === 'ArrowLeft' && colIndex > 0) {
2136
+ if (!column.dataIndex && !column.key || column.field === '#' || column.dataIndex === '#') {
2137
+ event.stopPropagation();
2138
+ event.preventDefault();
2139
+ } else {
2140
+ if (editingKey !== '') {} else {
2141
+ handleFocusCell(rowNumber, colIndex - 1, column, 'horizontal', event);
2035
2142
  }
2036
2143
  }
2037
- if (event.key === 'Delete') {
2038
- handleDeleteContent();
2144
+ }
2145
+ if (event.key === 'ArrowDown' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length) {
2146
+ if (isEditing(record) && (getEditType(column, record) === 'treeSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'asyncSelect')) {
2147
+ event.stopPropagation();
2148
+ } else {
2149
+ handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
2039
2150
  }
2040
- if (event.key === 'Escape') {
2041
- setEditingKey('');
2151
+ }
2152
+ if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
2153
+ if (isEditing(record) && (getEditType(column, record) === 'asyncSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'treeSelect')) {
2154
+ event.stopPropagation();
2155
+ } else {
2156
+ handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
2042
2157
  }
2043
2158
  }
2044
- },
2045
- onPaste: event => {
2046
- if (editingKey === '') {
2047
- handlePaste(record, colIndex, rowNumber, event);
2048
- event.preventDefault();
2159
+ if (event.key === 'Delete') {
2160
+ handleDeleteContent();
2049
2161
  }
2050
- },
2051
- onCopy: e => {
2052
- if (editingKey === '') {
2053
- handleCopy(e);
2054
- e.preventDefault();
2162
+ if (event.key === 'Escape') {
2163
+ setEditingKey('');
2055
2164
  }
2056
- },
2057
- onDoubleClick: event => {
2058
- if (!isEditing(record) && record[rowKey] !== editingKey && isEditable(column, record)) {
2059
- handleEdit(record, column, getEditType(column, record), event);
2165
+ }
2166
+ },
2167
+ onPaste: event => {
2168
+ if (editingKey === '') {
2169
+ handlePaste(record, colIndex, rowNumber, event);
2170
+ event.preventDefault();
2171
+ }
2172
+ },
2173
+ onCopy: e => {
2174
+ if (editingKey === '') {
2175
+ handleCopy(e);
2176
+ e.preventDefault();
2177
+ }
2178
+ },
2179
+ onDoubleClick: event => {
2180
+ if (!isEditing(record) && record[rowKey] !== editingKey && isEditable(column, record)) {
2181
+ handleEdit(record, column, getEditType(column, record), event);
2060
2182
 
2061
- // onRemoveBgSelectedCell(selectedCells.current, id)
2062
- // onRemoveBorderSelectedCell(selectedCells.current, id)
2063
- handleCellClick(rowNumber, record, column);
2064
- }
2065
- },
2066
- onContextMenu: () => {
2067
- // isSelecting.current = true;
2068
- // startCell.current = { row: rowNumber, col: colIndex };
2069
-
2070
- if (selectedCells.size === 0) {
2071
- // setStartSelectedCell({ row: rowNumber, col: colIndex })
2072
- // setSelectedCells(new Set([`${rowNumber}-${colIndex}`]));
2073
-
2074
- startSelectedCells.current = {
2075
- row: rowNumber,
2076
- col: colIndex
2077
- };
2078
- selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
2079
- rowsSelected.current = new Set();
2080
- }
2081
- },
2082
- onClick: () => {
2083
- if (record[rowKey] !== editingKey && editingKey !== '') {
2084
- // setEditingKey('')
2085
- } else {
2086
- if (record[rowKey] !== editingKey) {
2087
- onAddBorderSelectedCell(selectedCells.current, id);
2088
- }
2089
- if (editingKey) {
2090
- handleCellClick(rowNumber, record, column);
2091
- }
2092
- }
2093
- },
2094
- // className: isEditing(record) ? `rc-ui-cell-editable cell-editing ${!isEditable(column as any, record) ? 'disable' : ''}` : `rc-ui-cell-editable cell-editable ${!isEditable(column as any, record) ? 'disable' : ''}`,
2095
- className: classNames('rc-ui-cell-editable', {
2096
- 'cell-editing': isEditing(record),
2097
- 'cell-editable': !isEditing(record)
2098
- // selected: isSelectedCell(rangeCells,rowIndex, colIndex),
2099
- // 'cell-border-bottom': isRangeCell(rangeCells, 'bottom',rowIndex, colIndex),
2100
- // 'cell-border-right': isRangeCell(rangeCells, 'right',rowIndex, colIndex),
2101
- // 'cell-border-top': isRangeCell(rangeCells, 'top',rowIndex, colIndex),
2102
- // 'cell-border-left': isRangeCell(rangeCells, 'left',rowIndex, colIndex),
2103
- // disable: !isEditable(column as any, record)
2104
- }),
2105
- record,
2106
- column: column,
2107
- editType: getEditType(column, record),
2108
- dataIndex: column.dataIndex,
2109
- indexRow: rowNumber,
2110
- indexCol: colIndex,
2111
- title: getValueCell(column, record[column.field], format),
2112
- 'data-col-index': colIndex,
2113
- 'data-row-index': rowNumber,
2114
- 'data-tooltip-id': "tooltip-cell-content",
2115
- editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
2116
- cellEditing,
2117
- t,
2118
- tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex,
2119
- style: isPasteDragging ? {
2120
- cursor: "crosshair"
2121
- } : {}
2122
- };
2123
- },
2124
- onHeaderCell: (data, index) => {
2125
- return {
2126
- ...(column.onHeaderCell ? column.onHeaderCell?.(data, index) : {}),
2127
- onClick: () => {
2128
- handleClickColHeader(column, colIndex);
2129
- },
2130
- onCopy: e => {
2131
- if (editingKey === '') {
2132
- handleCopy(e);
2133
- e.preventDefault();
2183
+ // onRemoveBgSelectedCell(selectedCells.current, id)
2184
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
2185
+ handleCellClick(rowNumber, record, column);
2186
+ }
2187
+ },
2188
+ onContextMenu: () => {
2189
+ // isSelecting.current = true;
2190
+ // startCell.current = { row: rowNumber, col: colIndex };
2191
+
2192
+ if (selectedCells.size === 0) {
2193
+ // setStartSelectedCell({ row: rowNumber, col: colIndex })
2194
+ // setSelectedCells(new Set([`${rowNumber}-${colIndex}`]));
2195
+
2196
+ startSelectedCells.current = {
2197
+ row: rowNumber,
2198
+ col: colIndex
2199
+ };
2200
+ selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
2201
+ rowsSelected.current = new Set();
2202
+ }
2203
+ },
2204
+ onClick: () => {
2205
+ if (record[rowKey] !== editingKey && editingKey !== '') {
2206
+ // setEditingKey('')
2207
+ } else {
2208
+ if (record[rowKey] !== editingKey) {
2209
+ onAddBorderSelectedCell(selectedCells.current, id);
2134
2210
  }
2135
- },
2136
- onPaste: event => {
2137
- if (editingKey === '') {
2138
- handlePaste(dataSource[0], colIndex, 0, event);
2139
- event.preventDefault();
2211
+ if (editingKey) {
2212
+ handleCellClick(rowNumber, record, column);
2140
2213
  }
2141
- },
2142
- style: {
2143
- userSelect: 'none'
2144
2214
  }
2145
- };
2146
- },
2147
- render: (value, record, rowIndex) => {
2148
- const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
2149
- const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
2150
- const cellFormat = getFormat(colFormat, format);
2151
- const rowError = dataErrors.find(it => it.index === rowNumber);
2152
- const cellError = rowError && column.field && rowError[column.field]?.field === column.field ? rowError[column.field] : null;
2153
-
2154
- // const aaa = dataErrors.find((it) => column?.field && it[column.field].field === column.field && it.index === rowNumber)
2155
- // const aaa = column.field && rowError && rowError[column.field]?.field === column?.field
2215
+ },
2216
+ // className: isEditing(record) ? `rc-ui-cell-editable cell-editing ${!isEditable(column as any, record) ? 'disable' : ''}` : `rc-ui-cell-editable cell-editable ${!isEditable(column as any, record) ? 'disable' : ''}`,
2217
+ className: classNames('rc-ui-cell-editable', {
2218
+ 'cell-editing': isEditing(record),
2219
+ 'cell-editable': !isEditing(record),
2220
+ // selected: isSelectedCell(rangeCells,rowIndex, colIndex),
2221
+ // 'cell-border-bottom': isRangeCell(rangeCells, 'bottom',rowIndex, colIndex),
2222
+ // 'cell-border-right': isRangeCell(rangeCells, 'right',rowIndex, colIndex),
2223
+ // 'cell-border-top': isRangeCell(rangeCells, 'top',rowIndex, colIndex),
2224
+ // 'cell-border-left': isRangeCell(rangeCells, 'left',rowIndex, colIndex),
2225
+ disable: !isEditable(column, record)
2226
+ }),
2227
+ record,
2228
+ column: column,
2229
+ editType: getEditType(column, record),
2230
+ dataIndex: column.dataIndex,
2231
+ indexRow: rowNumber,
2232
+ indexCol: colIndex,
2233
+ title: getValueCell(column, record[column.field], format),
2234
+ 'data-col-index': colIndex,
2235
+ 'data-row-index': rowNumber,
2236
+ 'data-tooltip-id': "tooltip-cell-content",
2237
+ editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
2238
+ cellEditing,
2239
+ t,
2240
+ tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex,
2241
+ style: isPasteDragging ? {
2242
+ cursor: "crosshair"
2243
+ } : {}
2244
+ };
2245
+ },
2246
+ onHeaderCell: (data, index) => {
2247
+ return {
2248
+ ...(column.onHeaderCell ? column.onHeaderCell?.(data, index) : {}),
2249
+ onClick: () => {
2250
+ handleClickColHeader(column, colIndex);
2251
+ },
2252
+ onCopy: e => {
2253
+ if (editingKey === '') {
2254
+ handleCopy(e);
2255
+ e.preventDefault();
2256
+ }
2257
+ },
2258
+ onPaste: event => {
2259
+ if (editingKey === '') {
2260
+ handlePaste(dataSource[0], colIndex, 0, event);
2261
+ event.preventDefault();
2262
+ }
2263
+ },
2264
+ style: {
2265
+ userSelect: 'none'
2266
+ }
2267
+ };
2268
+ },
2269
+ render: (value, record, rowIndex) => {
2270
+ const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
2271
+ const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
2272
+ const cellFormat = getFormat(colFormat, format);
2273
+ const rowError = dataErrors.find(it => it.index === rowNumber);
2274
+ const cellError = rowError && column.field && rowError[column.field]?.field === column.field ? rowError[column.field] : null;
2275
+
2276
+ // const aaa = dataErrors.find((it) => column?.field && it[column.field].field === column.field && it.index === rowNumber)
2277
+ // const aaa = column.field && rowError && rowError[column.field]?.field === column?.field
2278
+
2279
+ return /*#__PURE__*/React.createElement("div", {
2280
+ className: classNames('ui-rc_cell-content', {
2281
+ // disable: !isEditable(column as any, record)
2282
+ isValid: column.field && rowError && rowError[column.field]?.field === column?.field
2283
+ }),
2284
+ onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
2285
+ onMouseEnter: event => {
2286
+ // setTooltipContent(cellError ? cellError.message : renderContent(column as any, value, record, rowIndex, cellFormat))
2287
+ setTooltipContent(cellError ? cellError.message : '');
2288
+ handleMouseEnter(rowNumber, colIndex, event);
2289
+ },
2290
+ onMouseUp: handleMouseUp,
2291
+ onMouseMove: () => {
2292
+ if (selectedCells && selectedCells.current.size > 0 && isMouseDown.current) {
2293
+ hideDraggingPoint(selectedCells.current, id);
2294
+ isDragMouse.current = true;
2295
+ }
2296
+ }
2156
2297
 
2157
- return /*#__PURE__*/React.createElement("div", {
2158
- className: classNames('ui-rc_cell-content', {
2159
- // disable: !isEditable(column as any, record)
2160
- isValid: column.field && rowError && rowError[column.field]?.field === column?.field
2161
- }),
2162
- onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
2163
- onMouseEnter: event => {
2164
- // setTooltipContent(cellError ? cellError.message : renderContent(column as any, value, record, rowIndex, cellFormat))
2165
- setTooltipContent(cellError ? cellError.message : '');
2166
- handleMouseEnter(rowNumber, colIndex, event);
2167
- },
2168
- onMouseUp: handleMouseUp,
2169
- onMouseMove: () => {
2170
- if (selectedCells && selectedCells.current.size > 0 && isMouseDown.current) {
2171
- hideDraggingPoint(selectedCells.current, id);
2172
- isDragMouse.current = true;
2173
- }
2298
+ // onClick={(event) => {
2299
+ //
2300
+ // handleClickCell(event)
2301
+ //
2302
+ // }}
2303
+ }, /*#__PURE__*/React.createElement("div", {
2304
+ className: 'ui-rc_content'
2305
+ }, renderContent(column, value, record, rowIndex, cellFormat)),
2306
+ // selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
2307
+ // getLastSelectCell(selectedCells.current).col === colIndex &&
2308
+ // isEditable(column as any, record) &&
2309
+
2310
+ !isDragMouse.current && /*#__PURE__*/React.createElement("div", {
2311
+ className: 'dragging-point hidden',
2312
+ onMouseDown: e => {
2313
+ // e.stopPropagation()
2314
+ e.preventDefault();
2315
+ if (e.button === 0) {
2316
+ setIsPasteDragging(true);
2174
2317
  }
2318
+ },
2319
+ onDoubleClick: handlePointDoubleClick
2320
+ }, /*#__PURE__*/React.createElement("span", {
2321
+ className: 'dot-point'
2322
+ })));
2323
+ }
2324
+ };
2325
+ });
2326
+ // [
2327
+ // cellEditing,
2328
+ // columns,
2329
+ // dataErrors,
2330
+ // dataSource,
2331
+ // editingKey,
2332
+ // format,
2333
+ // getRowKey,
2334
+ // handleAddSingle,
2335
+ // handleCellClick,
2336
+ // handleClickColHeader,
2337
+ // handleCopy,
2338
+ // handleDeleteContent,
2339
+ // handleEdit,
2340
+ // handleFocusCell,
2341
+ // handleMouseDown,
2342
+ // handleMouseDownRowHeader,
2343
+ // handleMouseEnter,
2344
+ // handleMouseEnterRowHeader,
2345
+ // handleMouseUp,
2346
+ // handlePaste,
2347
+ // handlePointDoubleClick,
2348
+ // id,
2349
+ // isEditing,
2350
+ // isPasteDragging,
2351
+ // mergedExpandedKeys,
2352
+ // onTriggerExpand,
2353
+ // rowEditable,
2354
+ // rowKey,
2355
+ // setTooltipContent,
2356
+ // t,
2357
+ // visibleCols.length
2358
+ // ])
2175
2359
 
2176
- // onClick={(event) => {
2177
- //
2178
- // handleClickCell(event)
2179
- //
2180
- // }}
2181
- }, /*#__PURE__*/React.createElement("div", {
2182
- className: 'ui-rc_content'
2183
- }, renderContent(column, value, record, rowIndex, cellFormat)),
2184
- // selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
2185
- // getLastSelectCell(selectedCells.current).col === colIndex &&
2186
- // isEditable(column as any, record) &&
2187
-
2188
- !isDragMouse.current && /*#__PURE__*/React.createElement("div", {
2189
- className: 'dragging-point hidden',
2190
- onMouseDown: e => {
2191
- // e.stopPropagation()
2192
- e.preventDefault();
2193
- if (e.button === 0) {
2194
- setIsPasteDragging(true);
2195
- }
2196
- },
2197
- onDoubleClick: handlePointDoubleClick
2198
- }, /*#__PURE__*/React.createElement("span", {
2199
- className: 'dot-point'
2200
- })));
2201
- }
2202
- };
2203
- });
2204
- }, [cellEditing, columns, dataErrors, dataSource, editingKey, format, getRowKey, handleAddSingle, handleCellClick, handleClickColHeader, handleCopy, handleDeleteContent, handleEdit, handleFocusCell, handleMouseDown, handleMouseDownRowHeader, handleMouseEnter, handleMouseEnterRowHeader, handleMouseUp, handlePaste, handlePointDoubleClick, id, isEditing, isPasteDragging, mergedExpandedKeys, onTriggerExpand, rangeCells, rowEditable, rowKey, setTooltipContent, t, visibleCols.length]);
2205
2360
  const transformColumns = React.useCallback(cols => {
2206
2361
  // @ts-ignore
2207
2362
  return cols.map(column => {
@@ -2209,6 +2364,14 @@ const GridEdit = props => {
2209
2364
  if (column === SELECTION_COLUMN) {
2210
2365
  return SELECTION_COLUMN;
2211
2366
  }
2367
+
2368
+ // Xử lý đệ quy cho children
2369
+ if (column.children?.length) {
2370
+ return {
2371
+ ...column,
2372
+ children: transformColumns(column.children)
2373
+ };
2374
+ }
2212
2375
  if (find) {
2213
2376
  return {
2214
2377
  ...find
@@ -2219,14 +2382,6 @@ const GridEdit = props => {
2219
2382
  ...column
2220
2383
  };
2221
2384
  }
2222
-
2223
- // Xử lý đệ quy cho children
2224
- if (column.children?.length) {
2225
- return {
2226
- ...column,
2227
- children: transformColumns(column.children)
2228
- };
2229
- }
2230
2385
  });
2231
2386
  }, [convertColumns]);
2232
2387
  const mergedColumns = React.useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
@@ -2309,10 +2464,12 @@ const GridEdit = props => {
2309
2464
  };
2310
2465
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
2311
2466
  $heightTable: height,
2467
+ $heightScroll: scrollHeight,
2312
2468
  style: {
2313
2469
  position: 'relative'
2314
2470
  },
2315
- ref: ref
2471
+ ref: ref,
2472
+ id: id
2316
2473
  }, /*#__PURE__*/React.createElement(TableContext.Provider, {
2317
2474
  value: {
2318
2475
  rowKey,