es-grid-template 1.5.17 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/grid-component/CheckboxFilter2.js +0 -4
- package/es/grid-component/ColumnsChoose.js +9 -4
- package/es/grid-component/ColumnsGroup/ColumnsGroup.js +11 -4
- package/es/grid-component/EditForm/EditForm.d.ts +27 -0
- package/es/grid-component/EditForm/EditForm.js +391 -0
- package/es/grid-component/EditForm/index.d.ts +1 -0
- package/es/grid-component/EditForm/index.js +1 -0
- package/es/grid-component/EditableCell.js +72 -52
- package/es/grid-component/InternalTable.js +79 -27
- package/es/grid-component/TableGrid.js +39 -107
- package/es/grid-component/control/InputControl/InputControl.d.ts +26 -0
- package/es/grid-component/control/InputControl/InputControl.js +121 -0
- package/es/grid-component/control/InputControl/index.d.ts +1 -0
- package/es/grid-component/control/InputControl/index.js +1 -0
- package/es/grid-component/hooks/columns/index.d.ts +3 -2
- package/es/grid-component/hooks/columns/index.js +84 -8
- package/es/grid-component/hooks/content/ControlCheckbox.d.ts +13 -0
- package/es/grid-component/hooks/content/ControlCheckbox.js +87 -0
- package/es/grid-component/hooks/content/HeaderContent.d.ts +1 -1
- package/es/grid-component/hooks/content/HeaderContent.js +9 -4
- package/es/grid-component/hooks/useColumns.js +5 -5
- package/es/grid-component/hooks/utils.d.ts +28 -3
- package/es/grid-component/hooks/utils.js +544 -12
- package/es/grid-component/styles.scss +50 -1
- package/es/grid-component/table/Grid.d.ts +3 -0
- package/es/grid-component/table/GridEdit.d.ts +3 -0
- package/es/grid-component/table/GridEdit.js +353 -328
- package/es/grid-component/table/Group.d.ts +3 -0
- package/es/grid-component/table/InfiniteTable.d.ts +3 -0
- package/es/grid-component/table/InfiniteTable.js +4 -2
- package/es/grid-component/type.d.ts +28 -0
- package/es/grid-component/useContext.d.ts +0 -1
- package/es/index.d.ts +2 -0
- package/es/index.js +1 -0
- package/es/select/index.d.ts +1 -1
- package/lib/grid-component/CheckboxFilter2.js +0 -4
- package/lib/grid-component/ColumnsChoose.js +9 -4
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +11 -4
- package/lib/grid-component/EditForm/EditForm.d.ts +27 -0
- package/lib/grid-component/EditForm/EditForm.js +401 -0
- package/lib/grid-component/EditForm/index.d.ts +1 -0
- package/lib/grid-component/EditForm/index.js +16 -0
- package/lib/grid-component/EditableCell.js +72 -52
- package/lib/grid-component/InternalTable.js +78 -26
- package/lib/grid-component/TableGrid.js +37 -105
- package/lib/grid-component/control/InputControl/InputControl.d.ts +26 -0
- package/lib/grid-component/control/InputControl/InputControl.js +131 -0
- package/lib/grid-component/control/InputControl/index.d.ts +1 -0
- package/lib/grid-component/control/InputControl/index.js +16 -0
- package/lib/grid-component/hooks/columns/index.d.ts +3 -2
- package/lib/grid-component/hooks/columns/index.js +86 -9
- package/lib/grid-component/hooks/content/ControlCheckbox.d.ts +13 -0
- package/lib/grid-component/hooks/content/ControlCheckbox.js +95 -0
- package/lib/grid-component/hooks/content/HeaderContent.d.ts +1 -1
- package/lib/grid-component/hooks/content/HeaderContent.js +9 -4
- package/lib/grid-component/hooks/useColumns.js +5 -5
- package/lib/grid-component/hooks/utils.d.ts +28 -3
- package/lib/grid-component/hooks/utils.js +565 -19
- package/lib/grid-component/styles.scss +50 -1
- package/lib/grid-component/table/Grid.d.ts +3 -0
- package/lib/grid-component/table/GridEdit.d.ts +3 -0
- package/lib/grid-component/table/GridEdit.js +343 -325
- package/lib/grid-component/table/Group.d.ts +3 -0
- package/lib/grid-component/table/InfiniteTable.d.ts +3 -0
- package/lib/grid-component/table/InfiniteTable.js +4 -2
- package/lib/grid-component/type.d.ts +28 -0
- package/lib/grid-component/useContext.d.ts +0 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +7 -0
- package/lib/select/index.d.ts +1 -1
- package/package.json +2 -1
|
@@ -27,8 +27,12 @@ var _rcMasterUi = require("rc-master-ui");
|
|
|
27
27
|
var _becoxyIcons = require("becoxy-icons");
|
|
28
28
|
var _InternalTable = require("../InternalTable");
|
|
29
29
|
var _reactNumericComponent = require("react-numeric-component");
|
|
30
|
+
var _HeaderContent = _interopRequireDefault(require("../hooks/content/HeaderContent"));
|
|
31
|
+
var _sortable = require("@dnd-kit/sortable");
|
|
30
32
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
31
33
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
34
|
+
// import {Button, Dropdown, Form, Modal, Typography} from "antd"
|
|
35
|
+
|
|
32
36
|
// import {faker} from "@faker-js/faker";
|
|
33
37
|
|
|
34
38
|
const {
|
|
@@ -182,6 +186,35 @@ const validateData = async (data, formSchema) => {
|
|
|
182
186
|
return errors;
|
|
183
187
|
}
|
|
184
188
|
};
|
|
189
|
+
const SortableHeaderCell = ({
|
|
190
|
+
children,
|
|
191
|
+
columnKey
|
|
192
|
+
}) => {
|
|
193
|
+
const {
|
|
194
|
+
attributes,
|
|
195
|
+
listeners,
|
|
196
|
+
setNodeRef,
|
|
197
|
+
isDragging
|
|
198
|
+
} = (0, _sortable.useSortable)({
|
|
199
|
+
id: columnKey
|
|
200
|
+
});
|
|
201
|
+
const style = {
|
|
202
|
+
// ...props.style,
|
|
203
|
+
cursor: 'move',
|
|
204
|
+
// position: 'absolute',
|
|
205
|
+
// left: 3,
|
|
206
|
+
// top: -2,
|
|
207
|
+
...(isDragging ? {
|
|
208
|
+
zIndex: 9999,
|
|
209
|
+
userSelect: 'none'
|
|
210
|
+
} : {})
|
|
211
|
+
// ...dragActiveStyle(dragState, props.id),
|
|
212
|
+
};
|
|
213
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
214
|
+
ref: setNodeRef,
|
|
215
|
+
style: style
|
|
216
|
+
}, attributes, listeners), children);
|
|
217
|
+
};
|
|
185
218
|
const GridEdit = props => {
|
|
186
219
|
const {
|
|
187
220
|
id,
|
|
@@ -189,6 +222,7 @@ const GridEdit = props => {
|
|
|
189
222
|
t,
|
|
190
223
|
columns,
|
|
191
224
|
dataSource,
|
|
225
|
+
originData,
|
|
192
226
|
components,
|
|
193
227
|
allowResizing,
|
|
194
228
|
rowKey = 'id',
|
|
@@ -215,12 +249,17 @@ const GridEdit = props => {
|
|
|
215
249
|
setTooltipContent,
|
|
216
250
|
onBlur,
|
|
217
251
|
locale,
|
|
252
|
+
mergedFilterKeys,
|
|
253
|
+
setMergedFilterKeys,
|
|
254
|
+
wrapSettings,
|
|
218
255
|
...rest
|
|
219
256
|
} = props;
|
|
220
257
|
const ref = (0, _react.useRef)(null);
|
|
221
258
|
const isSelecting = (0, _react.useRef)(false);
|
|
222
259
|
const startCell = (0, _react.useRef)(null);
|
|
223
260
|
const childrenColumnName = 'children';
|
|
261
|
+
|
|
262
|
+
// const hoveredRow: any = useRef(null)
|
|
224
263
|
const isSelectingRow = (0, _react.useRef)(false);
|
|
225
264
|
const rowStart = (0, _react.useRef)(null);
|
|
226
265
|
const rowsSelected = (0, _react.useRef)(new Set());
|
|
@@ -376,12 +415,20 @@ const GridEdit = props => {
|
|
|
376
415
|
})
|
|
377
416
|
}];
|
|
378
417
|
}, [t, locale]);
|
|
379
|
-
|
|
418
|
+
|
|
419
|
+
// const [form] = Form.useForm()
|
|
380
420
|
|
|
381
421
|
// const [editingKey, setEditingKey] = useState<string | number>('')
|
|
382
422
|
|
|
383
423
|
const [dataErrors, setDataErrors] = (0, _react.useState)([]);
|
|
384
|
-
|
|
424
|
+
|
|
425
|
+
// const abc = useMemo(() => {
|
|
426
|
+
//
|
|
427
|
+
// return selectedCells
|
|
428
|
+
// // return [...new Set(Array.from(selectedCells.current).map((item: any) => parseInt(item.split('-')[0])))]
|
|
429
|
+
//
|
|
430
|
+
// }, [selectedCells])
|
|
431
|
+
|
|
385
432
|
const [rangeCells, setRangeCells] = (0, _react.useState)(new Set());
|
|
386
433
|
const [openModalAddRow, setOpenModalAddRow] = (0, _react.useState)({
|
|
387
434
|
open: false,
|
|
@@ -414,8 +461,12 @@ const GridEdit = props => {
|
|
|
414
461
|
}
|
|
415
462
|
}, [validate, dataSource]);
|
|
416
463
|
const rowsFocus = _react.default.useMemo(() => {
|
|
417
|
-
|
|
418
|
-
|
|
464
|
+
const leng = (0, _hooks.flattenArray)(dataSource).length;
|
|
465
|
+
const arr = [...new Set(Array.from(rangeCells).map(item => parseInt(item.split('-')[0])))];
|
|
466
|
+
|
|
467
|
+
// return [...new Set(Array.from(rangeCells).map((item: any) => parseInt(item.split('-')[0])))] ?? []
|
|
468
|
+
return arr.filter(it => it < leng);
|
|
469
|
+
}, [dataSource.length, rangeCells]);
|
|
419
470
|
const contextMenuItems = _react.default.useMemo(() => {
|
|
420
471
|
const a = showDefaultContext !== false ? [...defaultContext] : [];
|
|
421
472
|
const b = propsContext && propsContext.length > 0 ? [...propsContext, {
|
|
@@ -457,7 +508,7 @@ const GridEdit = props => {
|
|
|
457
508
|
triggerChangeData?.(newData, 'Add');
|
|
458
509
|
}
|
|
459
510
|
}, [dataSource, defaultValue, triggerChangeData]);
|
|
460
|
-
const handleAddMulti = _react.default.useCallback((item,
|
|
511
|
+
const handleAddMulti = _react.default.useCallback((item, n) => {
|
|
461
512
|
if (item.onClick) {
|
|
462
513
|
item.onClick({
|
|
463
514
|
toolbar: item
|
|
@@ -465,7 +516,7 @@ const GridEdit = props => {
|
|
|
465
516
|
} else {
|
|
466
517
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
467
518
|
const newRows = Array.from({
|
|
468
|
-
length:
|
|
519
|
+
length: n
|
|
469
520
|
}).map(() => defaultRowValue ? {
|
|
470
521
|
...defaultRowValue,
|
|
471
522
|
id: undefined,
|
|
@@ -474,10 +525,13 @@ const GridEdit = props => {
|
|
|
474
525
|
id: undefined,
|
|
475
526
|
rowId: (0, _hooks.newGuid)()
|
|
476
527
|
});
|
|
528
|
+
const kkk = (0, _hooks.getAllRowKey)(newRows) ?? [];
|
|
529
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
530
|
+
setMergedFilterKeys?.(rs);
|
|
477
531
|
const newData = dataSource.concat(newRows);
|
|
478
532
|
triggerChangeData?.(newData, 'Add');
|
|
479
533
|
}
|
|
480
|
-
}, [dataSource, defaultValue, triggerChangeData]);
|
|
534
|
+
}, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
|
|
481
535
|
const handleDuplicate = _react.default.useCallback(() => {
|
|
482
536
|
// không tính tree
|
|
483
537
|
|
|
@@ -492,22 +546,17 @@ const GridEdit = props => {
|
|
|
492
546
|
|
|
493
547
|
// Vị trí chèn là ngay sau phần tử lớn nhất trong rowsFocus
|
|
494
548
|
const insertAfter = Math.max(...rowsFocus);
|
|
495
|
-
const
|
|
549
|
+
const rsFilter = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
|
|
550
|
+
|
|
551
|
+
// const rs = updateOrInsertInOrder(originData, rsFilter)
|
|
552
|
+
const rs = (0, _hooks.updateOrInsert)(originData, rsFilter);
|
|
553
|
+
// const rs2 = mergeWithFilter(originData, rsFilter)
|
|
554
|
+
|
|
496
555
|
triggerChangeData?.(rs, 'DUPLICATE');
|
|
497
|
-
}, [dataSource, rowsFocus, triggerChangeData]);
|
|
556
|
+
}, [dataSource, originData, rowsFocus, triggerChangeData]);
|
|
498
557
|
|
|
499
558
|
// thêm n dòng bên trên
|
|
500
559
|
const handleInsertBefore = _react.default.useCallback((item, n) => {
|
|
501
|
-
//
|
|
502
|
-
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
503
|
-
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
504
|
-
//
|
|
505
|
-
|
|
506
|
-
// setTimeout(() => {
|
|
507
|
-
// onAddBgSelectedCell(selectedCells.current, id)
|
|
508
|
-
// onAddBorderSelectedCell(selectedCells.current, id)
|
|
509
|
-
// }, 10)
|
|
510
|
-
|
|
511
560
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
512
561
|
// const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
|
|
513
562
|
|
|
@@ -519,51 +568,40 @@ const GridEdit = props => {
|
|
|
519
568
|
} else {
|
|
520
569
|
if (!record?.parentId) {
|
|
521
570
|
// Cập nhật data mới
|
|
522
|
-
const newData = [...dataSource]
|
|
571
|
+
// const newData = [...dataSource]
|
|
572
|
+
const newData = [...originData];
|
|
523
573
|
const newRows = Array.from({
|
|
524
574
|
length: n
|
|
525
|
-
}).map(() => defaultRowValue ?
|
|
526
|
-
...defaultRowValue,
|
|
527
|
-
id: undefined,
|
|
528
|
-
rowId: (0, _hooks.newGuid)(),
|
|
529
|
-
isFilterState: true
|
|
530
|
-
} : {
|
|
575
|
+
}).map(() => defaultRowValue ? {
|
|
531
576
|
...defaultRowValue,
|
|
532
577
|
id: undefined,
|
|
533
578
|
rowId: (0, _hooks.newGuid)()
|
|
534
|
-
} : isFilter ? {
|
|
535
|
-
id: undefined,
|
|
536
|
-
rowId: (0, _hooks.newGuid)(),
|
|
537
|
-
isFilterState: true
|
|
538
579
|
} : {
|
|
539
580
|
id: undefined,
|
|
540
581
|
rowId: (0, _hooks.newGuid)()
|
|
541
582
|
});
|
|
583
|
+
const kkk = (0, _hooks.getAllRowKey)(newRows) ?? [];
|
|
584
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
585
|
+
setMergedFilterKeys?.(rs);
|
|
542
586
|
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
543
587
|
newData.splice(index, 0, ...newRows);
|
|
544
588
|
triggerChangeData?.(newData, 'INSERT_BEFORE');
|
|
545
589
|
} else {
|
|
546
|
-
const newData = [...dataSource]
|
|
590
|
+
// const newData = [...dataSource]
|
|
591
|
+
const newData = [...originData];
|
|
592
|
+
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
547
593
|
const newRows = Array.from({
|
|
548
594
|
length: n
|
|
549
|
-
}).map(() => defaultRowValue ?
|
|
595
|
+
}).map(() => defaultRowValue ? {
|
|
550
596
|
...defaultRowValue,
|
|
551
597
|
id: undefined,
|
|
552
598
|
rowId: (0, _hooks.newGuid)(),
|
|
553
|
-
|
|
599
|
+
parentId: parent.rowId
|
|
554
600
|
} : {
|
|
555
|
-
...defaultRowValue,
|
|
556
|
-
id: undefined,
|
|
557
|
-
rowId: (0, _hooks.newGuid)()
|
|
558
|
-
} : isFilter ? {
|
|
559
601
|
id: undefined,
|
|
560
602
|
rowId: (0, _hooks.newGuid)(),
|
|
561
|
-
|
|
562
|
-
} : {
|
|
563
|
-
id: undefined,
|
|
564
|
-
rowId: (0, _hooks.newGuid)()
|
|
603
|
+
parentId: parent.rowId
|
|
565
604
|
});
|
|
566
|
-
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
567
605
|
|
|
568
606
|
// Cập nhật childData mới
|
|
569
607
|
const childData = parent?.children ? [...parent.children] : [];
|
|
@@ -577,12 +615,15 @@ const GridEdit = props => {
|
|
|
577
615
|
triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
|
|
578
616
|
}
|
|
579
617
|
}
|
|
580
|
-
}, [dataSource, defaultValue,
|
|
618
|
+
}, [dataSource, defaultValue, mergedFilterKeys, originData, rowKey, rowsFocus, setMergedFilterKeys, triggerChangeData]);
|
|
581
619
|
|
|
582
620
|
//thêm 1 dòng bên dưới
|
|
583
621
|
const handleInsertAfter = _react.default.useCallback((item, n) => {
|
|
584
622
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
585
|
-
const
|
|
623
|
+
const insertAfter = Math.max(...rowsFocus);
|
|
624
|
+
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[insertAfter];
|
|
625
|
+
|
|
626
|
+
// const record: RecordType = flattenData(childrenColumnName, originData)[rowsFocus[rowsFocus.length - 1]]
|
|
586
627
|
|
|
587
628
|
// const record = getRecordByKey()
|
|
588
629
|
|
|
@@ -593,51 +634,41 @@ const GridEdit = props => {
|
|
|
593
634
|
} else {
|
|
594
635
|
if (!record?.parentId) {
|
|
595
636
|
// Cập nhật data mới
|
|
596
|
-
const newData = [...
|
|
637
|
+
const newData = [...originData];
|
|
597
638
|
const newRows = Array.from({
|
|
598
639
|
length: n
|
|
599
|
-
}).map(() => defaultRowValue ?
|
|
600
|
-
...defaultRowValue,
|
|
601
|
-
id: undefined,
|
|
602
|
-
rowId: (0, _hooks.newGuid)(),
|
|
603
|
-
isFilterState: true
|
|
604
|
-
} : {
|
|
640
|
+
}).map(() => defaultRowValue ? {
|
|
605
641
|
...defaultRowValue,
|
|
606
642
|
id: undefined,
|
|
607
643
|
rowId: (0, _hooks.newGuid)()
|
|
608
|
-
} : isFilter ? {
|
|
609
|
-
id: undefined,
|
|
610
|
-
rowId: (0, _hooks.newGuid)(),
|
|
611
|
-
isFilterState: true
|
|
612
644
|
} : {
|
|
613
645
|
id: undefined,
|
|
614
646
|
rowId: (0, _hooks.newGuid)()
|
|
615
647
|
});
|
|
648
|
+
const kkk = (0, _hooks.getAllRowKey)(newRows) ?? [];
|
|
649
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
650
|
+
setMergedFilterKeys?.(rs);
|
|
616
651
|
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
617
652
|
newData.splice(index + 1, 0, ...newRows);
|
|
618
653
|
triggerChangeData?.(newData, 'INSERT_AFTER');
|
|
619
654
|
} else {
|
|
620
|
-
const newData = [...
|
|
655
|
+
const newData = [...originData];
|
|
656
|
+
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
621
657
|
const newRows = Array.from({
|
|
622
658
|
length: n
|
|
623
|
-
}).map(() => defaultRowValue ?
|
|
659
|
+
}).map(() => defaultRowValue ? {
|
|
624
660
|
...defaultRowValue,
|
|
625
661
|
id: undefined,
|
|
626
662
|
rowId: (0, _hooks.newGuid)(),
|
|
627
|
-
|
|
663
|
+
parentId: parent.rowId
|
|
628
664
|
} : {
|
|
629
|
-
...defaultRowValue,
|
|
630
|
-
id: undefined,
|
|
631
|
-
rowId: (0, _hooks.newGuid)()
|
|
632
|
-
} : isFilter ? {
|
|
633
665
|
id: undefined,
|
|
634
666
|
rowId: (0, _hooks.newGuid)(),
|
|
635
|
-
|
|
636
|
-
} : {
|
|
637
|
-
id: undefined,
|
|
638
|
-
rowId: (0, _hooks.newGuid)()
|
|
667
|
+
parentId: parent.rowId
|
|
639
668
|
});
|
|
640
|
-
const
|
|
669
|
+
const kkk = (0, _hooks.getAllRowKey)(newRows) ?? [];
|
|
670
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
671
|
+
setMergedFilterKeys?.(rs);
|
|
641
672
|
|
|
642
673
|
// Cập nhật childData mới
|
|
643
674
|
const childData = parent?.children ? [...parent.children] : [];
|
|
@@ -651,17 +682,18 @@ const GridEdit = props => {
|
|
|
651
682
|
triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
|
|
652
683
|
}
|
|
653
684
|
}
|
|
654
|
-
}, [dataSource,
|
|
685
|
+
}, [defaultValue, dataSource, rowsFocus, originData, mergedFilterKeys, setMergedFilterKeys, triggerChangeData, rowKey]);
|
|
655
686
|
const handleInsertChild = _react.default.useCallback(item => {
|
|
656
687
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
657
|
-
const rowId =
|
|
688
|
+
const rowId = (0, _hooks.newGuid)();
|
|
658
689
|
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
|
|
659
690
|
if (item.onClick) {
|
|
660
691
|
item.onClick({
|
|
661
692
|
toolbar: item
|
|
662
693
|
});
|
|
663
694
|
} else {
|
|
664
|
-
const newData = [...dataSource]
|
|
695
|
+
// const newData = [...dataSource]
|
|
696
|
+
const newData = [...originData];
|
|
665
697
|
let newElement;
|
|
666
698
|
if (!record.children || record.children.length === 0) {
|
|
667
699
|
newElement = {
|
|
@@ -682,6 +714,8 @@ const GridEdit = props => {
|
|
|
682
714
|
}]
|
|
683
715
|
};
|
|
684
716
|
}
|
|
717
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, rowId] : [rowId];
|
|
718
|
+
setMergedFilterKeys?.(rs);
|
|
685
719
|
const newDataSource = (0, _hooks.updateArrayByKey)(newData, newElement, rowKey);
|
|
686
720
|
triggerChangeData?.(newDataSource, 'INSERT_CHILDREN');
|
|
687
721
|
}
|
|
@@ -705,16 +739,25 @@ const GridEdit = props => {
|
|
|
705
739
|
toolbar: item
|
|
706
740
|
});
|
|
707
741
|
} else {
|
|
708
|
-
const
|
|
742
|
+
// const filterData = flattenArray([...dataSource])
|
|
743
|
+
const filterData = (0, _hooks.flattenArray)([...originData]);
|
|
709
744
|
const indexesToDelete = [...rowsFocus];
|
|
710
745
|
|
|
711
746
|
// Sắp xếp giảm dần để xóa từ cuối lên đầu
|
|
712
747
|
indexesToDelete.sort((a, b) => b - a).forEach(index => {
|
|
713
|
-
|
|
748
|
+
filterData.splice(index, 1);
|
|
714
749
|
});
|
|
715
|
-
|
|
750
|
+
|
|
751
|
+
// const newData = updateOrInsert(flattenArray([...originData]), filterData)
|
|
752
|
+
//
|
|
753
|
+
const rs = (0, _hooks.unFlattenData)(filterData);
|
|
754
|
+
triggerChangeData?.([...rs], 'DELETE_ROWS');
|
|
716
755
|
}
|
|
717
|
-
|
|
756
|
+
setTimeout(() => {
|
|
757
|
+
(0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
|
|
758
|
+
(0, _hooks.showDraggingPoint)(selectedCells.current, id);
|
|
759
|
+
}, 0);
|
|
760
|
+
}, [id, originData, rowsFocus, triggerChangeData]);
|
|
718
761
|
const handleDeleteAll = _react.default.useCallback(() => {
|
|
719
762
|
triggerChangeData?.([], 'INSERT_BEFORE');
|
|
720
763
|
}, [triggerChangeData]);
|
|
@@ -738,9 +781,12 @@ const GridEdit = props => {
|
|
|
738
781
|
newData[rowIndex][field] = '';
|
|
739
782
|
}
|
|
740
783
|
}
|
|
741
|
-
|
|
784
|
+
const rsFilterData = (0, _hooks.updateOrInsert)((0, _hooks.flattenArray)([...originData]), newData);
|
|
785
|
+
|
|
786
|
+
// triggerChangeData?.([...newData], 'DELETE_CONTENT')
|
|
787
|
+
triggerChangeData?.([...rsFilterData], 'DELETE_CONTENT');
|
|
742
788
|
}
|
|
743
|
-
}, [dataSource, triggerChangeData, visibleCols]);
|
|
789
|
+
}, [dataSource, originData, triggerChangeData, visibleCols]);
|
|
744
790
|
const toolbarItemsBottom = (0, _react.useMemo)(() => {
|
|
745
791
|
if (!rowsFocus || rowsFocus.length === 0) {
|
|
746
792
|
return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER' && it.key !== 'DELETE_ROWS' && it.key !== 'INSERT_CHILDREN').map(item => {
|
|
@@ -760,13 +806,13 @@ const GridEdit = props => {
|
|
|
760
806
|
className: 'toolbar-button toolbar-dropdown-button',
|
|
761
807
|
menu: {
|
|
762
808
|
items: itemsAdd,
|
|
763
|
-
onClick: e => handleAddMulti(item, e)
|
|
809
|
+
onClick: e => handleAddMulti(item, Number(e.key))
|
|
764
810
|
}
|
|
765
811
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
766
812
|
style: {
|
|
767
813
|
color: '#28c76f'
|
|
768
814
|
},
|
|
769
|
-
onClick: () =>
|
|
815
|
+
onClick: () => handleAddMulti(item, 1)
|
|
770
816
|
}, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
|
|
771
817
|
}
|
|
772
818
|
};
|
|
@@ -810,13 +856,13 @@ const GridEdit = props => {
|
|
|
810
856
|
className: 'toolbar-button toolbar-dropdown-button',
|
|
811
857
|
menu: {
|
|
812
858
|
items: itemsAdd,
|
|
813
|
-
onClick: e => handleAddMulti(item, e)
|
|
859
|
+
onClick: e => handleAddMulti(item, Number(e.key))
|
|
814
860
|
}
|
|
815
861
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
816
862
|
style: {
|
|
817
863
|
color: '#28c76f'
|
|
818
864
|
},
|
|
819
|
-
onClick: () =>
|
|
865
|
+
onClick: () => handleAddMulti(item, 1)
|
|
820
866
|
}, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
|
|
821
867
|
}
|
|
822
868
|
};
|
|
@@ -949,7 +995,7 @@ const GridEdit = props => {
|
|
|
949
995
|
...item
|
|
950
996
|
};
|
|
951
997
|
});
|
|
952
|
-
}, [handleAddMulti,
|
|
998
|
+
}, [handleAddMulti, handleDeleteAll, handleDeleteRows, handleDuplicate, handleInsertAfter, handleInsertBefore, handleInsertChild, itemsAdd, rowsFocus, t, toolbarItems]);
|
|
953
999
|
const {
|
|
954
1000
|
control,
|
|
955
1001
|
handleSubmit,
|
|
@@ -969,8 +1015,6 @@ const GridEdit = props => {
|
|
|
969
1015
|
// return record[rowKey as any] === editingKey.current
|
|
970
1016
|
// }, [editingKey, rowKey])
|
|
971
1017
|
|
|
972
|
-
// console.log('isEditing', isEditing)
|
|
973
|
-
|
|
974
1018
|
_react.default.useEffect(() => {
|
|
975
1019
|
const handleClickOutside = event => {
|
|
976
1020
|
const element = event.target;
|
|
@@ -1028,7 +1072,7 @@ const GridEdit = props => {
|
|
|
1028
1072
|
// document.removeEventListener('touchstart', handleClickOutside)
|
|
1029
1073
|
};
|
|
1030
1074
|
}, [dataSource, id, onBlur]);
|
|
1031
|
-
const triggerDragPaste = pastesArray => {
|
|
1075
|
+
const triggerDragPaste = (pastesArray, ctrlKey) => {
|
|
1032
1076
|
const mergedSet = new Set([...selectedCells.current, ...pastesArray]);
|
|
1033
1077
|
const tmpCols = {
|
|
1034
1078
|
...visibleCols
|
|
@@ -1073,57 +1117,69 @@ const GridEdit = props => {
|
|
|
1073
1117
|
let newRange;
|
|
1074
1118
|
if (rowPasteLast > rowSelectedFirst) {
|
|
1075
1119
|
// kéo xuóng
|
|
1076
|
-
newRange = (0, _hooks.
|
|
1120
|
+
newRange = ctrlKey ? (0, _hooks.addRowsDownWithCtrl)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length) : (0, _hooks.addRowsDown)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
|
|
1077
1121
|
} else {
|
|
1078
1122
|
// kéo lên
|
|
1079
|
-
newRange = (0, _hooks.addRowsUp)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
|
|
1123
|
+
newRange = ctrlKey ? (0, _hooks.addRowsUpWithCtrl)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length) : (0, _hooks.addRowsUp)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
|
|
1080
1124
|
}
|
|
1081
|
-
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[(0, _hooks.getFirstSelectCell)(pastesArray).row];
|
|
1082
|
-
if (!record?.parentId) {
|
|
1083
|
-
// Cập nhật data mới
|
|
1084
|
-
const newData = [...dataSource];
|
|
1085
1125
|
|
|
1086
|
-
|
|
1087
|
-
// const { row: startRow, col: startCol } = selectedCell;
|
|
1088
|
-
const startRow = (0, _hooks.getFirstSelectCell)(pastesArray).row;
|
|
1089
|
-
const startCol = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
|
|
1090
|
-
const pastedRows = [];
|
|
1091
|
-
const pastedColumns = new Set();
|
|
1092
|
-
newRange.addedRows.forEach((rowValues, rowIndex) => {
|
|
1093
|
-
const targetRow = startRow + rowIndex;
|
|
1094
|
-
|
|
1095
|
-
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1096
|
-
if (targetRow >= newData.length) {
|
|
1097
|
-
// @ts-ignore
|
|
1098
|
-
newData.push({
|
|
1099
|
-
id: undefined,
|
|
1100
|
-
rowId: (0, _hooks.newGuid)()
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
rowValues.forEach((cellValue, colIndex) => {
|
|
1104
|
-
const targetCol = startCol + colIndex;
|
|
1105
|
-
if (targetCol >= tmpCols.length) {
|
|
1106
|
-
// Không vượt quá số cột
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1126
|
+
// const record = flattenData(childrenColumnName, dataSource)[getFirstSelectCell(pastesArray).row]
|
|
1109
1127
|
|
|
1110
|
-
|
|
1111
|
-
const columnKey = tmpCols[targetCol].field;
|
|
1128
|
+
// if (!record?.parentId) {
|
|
1112
1129
|
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1130
|
+
// Cập nhật data mới
|
|
1131
|
+
const newData = (0, _hooks.flattenArray)([...dataSource]);
|
|
1132
|
+
// const newData = flattenArray([...originData])
|
|
1133
|
+
|
|
1134
|
+
// Lấy vị trí bắt đầu
|
|
1135
|
+
// const { row: startRow, col: startCol } = selectedCell;
|
|
1136
|
+
const startRow = (0, _hooks.getFirstSelectCell)(pastesArray).row;
|
|
1137
|
+
const startCol = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
|
|
1138
|
+
const pastedRows = [];
|
|
1139
|
+
const pastedColumns = new Set();
|
|
1140
|
+
newRange.addedRows.forEach((rowValues, rowIndex) => {
|
|
1141
|
+
const targetRow = startRow + rowIndex;
|
|
1142
|
+
|
|
1143
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1144
|
+
if (targetRow >= newData.length) {
|
|
1145
|
+
// @ts-ignore
|
|
1146
|
+
newData.push({
|
|
1147
|
+
id: undefined,
|
|
1148
|
+
rowId: (0, _hooks.newGuid)()
|
|
1119
1149
|
});
|
|
1150
|
+
}
|
|
1151
|
+
rowValues.forEach((cellValue, colIndex) => {
|
|
1152
|
+
const targetCol = startCol + colIndex;
|
|
1153
|
+
if (targetCol >= tmpCols.length) {
|
|
1154
|
+
// Không vượt quá số cột
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1120
1157
|
|
|
1121
|
-
//
|
|
1122
|
-
|
|
1158
|
+
// @ts-ignore
|
|
1159
|
+
const columnKey = tmpCols[targetCol].field;
|
|
1160
|
+
|
|
1161
|
+
// @ts-ignore
|
|
1162
|
+
newData[targetRow] = {
|
|
1163
|
+
...newData[targetRow],
|
|
1164
|
+
[columnKey]: typeof cellValue === 'string' ? cellValue.trim() : cellValue
|
|
1165
|
+
};
|
|
1166
|
+
pastedColumns.add(columnKey);
|
|
1123
1167
|
});
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1168
|
+
|
|
1169
|
+
// Lưu dòng được paste
|
|
1170
|
+
pastedRows.push(newData[targetRow]);
|
|
1171
|
+
});
|
|
1172
|
+
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1173
|
+
|
|
1174
|
+
// const rsFilterData = updateDataByFilter(flattenArray([...originData]), newData)
|
|
1175
|
+
const rsFilterData = (0, _hooks.updateOrInsert)((0, _hooks.flattenArray)([...originData]), newData);
|
|
1176
|
+
// const rsFilterData = mergeWithFilter(flattenArray([...originData]), newData)
|
|
1177
|
+
// const rsFilterData = mergeWithFilter2(flattenArray([...originData]), newData)
|
|
1178
|
+
|
|
1179
|
+
const rs = (0, _hooks.unFlattenData)(rsFilterData);
|
|
1180
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, rs, copyRows);
|
|
1181
|
+
|
|
1182
|
+
// }
|
|
1127
1183
|
|
|
1128
1184
|
/// cập nhật cell class
|
|
1129
1185
|
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
@@ -1154,7 +1210,7 @@ const GridEdit = props => {
|
|
|
1154
1210
|
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
1155
1211
|
if (!record?.parentId) {
|
|
1156
1212
|
// Cập nhật data mới
|
|
1157
|
-
const newData = [...dataSource];
|
|
1213
|
+
const newData = (0, _hooks.flattenArray)([...dataSource]);
|
|
1158
1214
|
|
|
1159
1215
|
// const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
1160
1216
|
|
|
@@ -1185,10 +1241,12 @@ const GridEdit = props => {
|
|
|
1185
1241
|
// Không vượt quá số cột
|
|
1186
1242
|
return;
|
|
1187
1243
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1244
|
+
const columnTarget = visibleCols[targetCol];
|
|
1245
|
+
const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(newData[targetRow]) : columnTarget.editEnable;
|
|
1246
|
+
if (isEdit) {
|
|
1191
1247
|
const columnKey = visibleCols[targetCol].field;
|
|
1248
|
+
// const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(newData[targetRow]) : columnTarget.editEnable
|
|
1249
|
+
|
|
1192
1250
|
if (columnTarget.type === 'number' && (0, _hooks.isFormattedNumber)(cellValue.trim())) {
|
|
1193
1251
|
const colFormat = typeof columnTarget.format === 'function' ? columnTarget.format(record) : columnTarget.format;
|
|
1194
1252
|
const valuePasteFormat = (0, _hooks.detectSeparators)(cellValue.trim());
|
|
@@ -1227,11 +1285,17 @@ const GridEdit = props => {
|
|
|
1227
1285
|
pastedRows.push(newData[targetRow]);
|
|
1228
1286
|
});
|
|
1229
1287
|
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1230
|
-
|
|
1288
|
+
|
|
1289
|
+
// const rsFilterData = updateDataByFilter(flattenArray([...originData]), newData)
|
|
1290
|
+
// const rsFilterData = mergeWithFilter(flattenArray([...originData]), newData)
|
|
1291
|
+
const rsFilterData = (0, _hooks.updateOrInsert)((0, _hooks.flattenArray)([...originData]), newData);
|
|
1292
|
+
const rs = (0, _hooks.unFlattenData)(rsFilterData);
|
|
1293
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, rs, []);
|
|
1231
1294
|
} else {
|
|
1232
1295
|
// Cập nhật data mới
|
|
1233
|
-
const newData = [...dataSource]
|
|
1234
|
-
|
|
1296
|
+
// const newData = flattenArray([...dataSource])
|
|
1297
|
+
|
|
1298
|
+
const parent = (0, _hooks.findItemByKey)(dataSource, rowKey, record.parentId);
|
|
1235
1299
|
|
|
1236
1300
|
// Cập nhật childData mới
|
|
1237
1301
|
const childData = parent?.children ? [...parent.children] : [];
|
|
@@ -1259,7 +1323,9 @@ const GridEdit = props => {
|
|
|
1259
1323
|
// Không vượt quá số cột
|
|
1260
1324
|
return;
|
|
1261
1325
|
}
|
|
1262
|
-
|
|
1326
|
+
const columnTarget = visibleCols[targetCol];
|
|
1327
|
+
const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(childData[targetRow]) : columnTarget.editEnable;
|
|
1328
|
+
if (isEdit) {
|
|
1263
1329
|
// @ts-ignore
|
|
1264
1330
|
const columnKey = visibleCols[targetCol].field;
|
|
1265
1331
|
|
|
@@ -1279,8 +1345,21 @@ const GridEdit = props => {
|
|
|
1279
1345
|
const newRowData = {
|
|
1280
1346
|
...parent,
|
|
1281
1347
|
children: childData
|
|
1282
|
-
};
|
|
1283
|
-
|
|
1348
|
+
}; // item đã được filter
|
|
1349
|
+
|
|
1350
|
+
// const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
|
|
1351
|
+
const newDataSource = (0, _hooks.updateArrayByKey)(originData, newRowData, rowKey);
|
|
1352
|
+
|
|
1353
|
+
//
|
|
1354
|
+
// // const rsFilterData = updateDataByFilter(flattenArray([...originData]), flattenArray(newDataSource))
|
|
1355
|
+
// // const rsFilterData = mergeWithFilter(flattenArray([...originData]), flattenArray(newDataSource))
|
|
1356
|
+
|
|
1357
|
+
// const rsFilterData1 = updateOrInsert(flattenArray([...originData]), flattenArray([...newDataSource]))
|
|
1358
|
+
//
|
|
1359
|
+
//
|
|
1360
|
+
// // const rs = unFlattenData(rsFilterData)
|
|
1361
|
+
// const rs1 = unFlattenData(rsFilterData1)
|
|
1362
|
+
|
|
1284
1363
|
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
|
|
1285
1364
|
}
|
|
1286
1365
|
};
|
|
@@ -1322,128 +1401,6 @@ const GridEdit = props => {
|
|
|
1322
1401
|
} else {
|
|
1323
1402
|
handlePasted(record, indexCol, rowNumber, rowsPasted);
|
|
1324
1403
|
}
|
|
1325
|
-
|
|
1326
|
-
// const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
|
|
1327
|
-
//
|
|
1328
|
-
//
|
|
1329
|
-
// if (!record?.parentId ) {
|
|
1330
|
-
//
|
|
1331
|
-
// // Cập nhật data mới
|
|
1332
|
-
// const newData = [...dataSource];
|
|
1333
|
-
//
|
|
1334
|
-
// // @ts-ignore
|
|
1335
|
-
// const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
|
|
1336
|
-
//
|
|
1337
|
-
// // Lấy vị trí bắt đầu
|
|
1338
|
-
// // const { row: startRow, col: startCol } = selectedCell;
|
|
1339
|
-
// const startRow = indexRows
|
|
1340
|
-
// const startCol = indexCol
|
|
1341
|
-
//
|
|
1342
|
-
//
|
|
1343
|
-
//
|
|
1344
|
-
// // const flattData = flattenArray(newData);
|
|
1345
|
-
//
|
|
1346
|
-
// const pastedRows: RecordType[] = [];
|
|
1347
|
-
// const pastedColumns = new Set()
|
|
1348
|
-
//
|
|
1349
|
-
//
|
|
1350
|
-
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
1351
|
-
// const targetRow = startRow + rowIndex;
|
|
1352
|
-
//
|
|
1353
|
-
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1354
|
-
// if (targetRow >= newData.length) {
|
|
1355
|
-
// // @ts-ignore
|
|
1356
|
-
// // newData.push({ id: newGuid()});
|
|
1357
|
-
// newData.push({ id: undefined, rowId: newGuid()});
|
|
1358
|
-
// }
|
|
1359
|
-
//
|
|
1360
|
-
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
1361
|
-
// const targetCol = startCol + colIndex;
|
|
1362
|
-
// if (targetCol >= columns.length) { // Không vượt quá số cột
|
|
1363
|
-
// return
|
|
1364
|
-
// }
|
|
1365
|
-
//
|
|
1366
|
-
// if (columns[targetCol].editEnable) {
|
|
1367
|
-
// // @ts-ignore
|
|
1368
|
-
// const columnKey = columns[targetCol].field;
|
|
1369
|
-
//
|
|
1370
|
-
// // @ts-ignore
|
|
1371
|
-
// newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
|
|
1372
|
-
// pastedColumns.add(columnKey);
|
|
1373
|
-
// }
|
|
1374
|
-
//
|
|
1375
|
-
// });
|
|
1376
|
-
//
|
|
1377
|
-
// // Lưu dòng được paste
|
|
1378
|
-
// pastedRows.push(newData[targetRow]);
|
|
1379
|
-
//
|
|
1380
|
-
// });
|
|
1381
|
-
//
|
|
1382
|
-
// const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1383
|
-
//
|
|
1384
|
-
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
|
|
1385
|
-
//
|
|
1386
|
-
//
|
|
1387
|
-
// } else {
|
|
1388
|
-
//
|
|
1389
|
-
// // Cập nhật data mới
|
|
1390
|
-
// const newData = [...dataSource];
|
|
1391
|
-
//
|
|
1392
|
-
// const parent = findItemByKey(newData, rowKey as any, record.parentId)
|
|
1393
|
-
//
|
|
1394
|
-
// // Cập nhật childData mới
|
|
1395
|
-
// const childData: any[] = parent?.children ? [...parent.children] : []
|
|
1396
|
-
//
|
|
1397
|
-
//
|
|
1398
|
-
// // Lấy vị trí bắt đầu
|
|
1399
|
-
// // const { row: startRow, col: startCol } = selectedCell;
|
|
1400
|
-
// const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
|
|
1401
|
-
// const startCol = indexCol
|
|
1402
|
-
//
|
|
1403
|
-
// const pastedRows: RecordType[] = []
|
|
1404
|
-
// const pastedColumns = new Set()
|
|
1405
|
-
//
|
|
1406
|
-
//
|
|
1407
|
-
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
1408
|
-
// const targetRow = startRow + rowIndex
|
|
1409
|
-
//
|
|
1410
|
-
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1411
|
-
// if (targetRow >= childData.length) {
|
|
1412
|
-
//
|
|
1413
|
-
// childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
|
|
1414
|
-
// }
|
|
1415
|
-
//
|
|
1416
|
-
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
1417
|
-
// const targetCol = startCol + colIndex
|
|
1418
|
-
// if (targetCol >= columns.length) { // Không vượt quá số cột
|
|
1419
|
-
// return
|
|
1420
|
-
// }
|
|
1421
|
-
//
|
|
1422
|
-
// if (columns[targetCol].editEnable) {
|
|
1423
|
-
//
|
|
1424
|
-
// // @ts-ignore
|
|
1425
|
-
// const columnKey = columns[targetCol].field
|
|
1426
|
-
//
|
|
1427
|
-
// // @ts-ignore
|
|
1428
|
-
// childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
|
|
1429
|
-
// pastedColumns.add(columnKey)
|
|
1430
|
-
// }
|
|
1431
|
-
//
|
|
1432
|
-
// })
|
|
1433
|
-
//
|
|
1434
|
-
// // Lưu dòng được paste
|
|
1435
|
-
// pastedRows.push(childData[targetRow])
|
|
1436
|
-
//
|
|
1437
|
-
// })
|
|
1438
|
-
//
|
|
1439
|
-
// const pastedColumnsArray = Array.from(pastedColumns) ?? []
|
|
1440
|
-
//
|
|
1441
|
-
// const newRowData = {...parent, children: childData}
|
|
1442
|
-
//
|
|
1443
|
-
// const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
|
|
1444
|
-
//
|
|
1445
|
-
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
|
|
1446
|
-
// }
|
|
1447
1404
|
};
|
|
1448
1405
|
const handlePointDoubleClick = e => {
|
|
1449
1406
|
// e.preventDefault()
|
|
@@ -1554,7 +1511,7 @@ const GridEdit = props => {
|
|
|
1554
1511
|
// nếu ctrlCell length > 0 thì set selectCells
|
|
1555
1512
|
|
|
1556
1513
|
if (pasteCells && pasteCells.current.size > 0) {
|
|
1557
|
-
triggerDragPaste(pasteCells.current);
|
|
1514
|
+
triggerDragPaste(pasteCells.current, e.ctrlKey);
|
|
1558
1515
|
} else {
|
|
1559
1516
|
setRangeCells(selectedCells.current);
|
|
1560
1517
|
const target = e.target;
|
|
@@ -1582,6 +1539,7 @@ const GridEdit = props => {
|
|
|
1582
1539
|
col: startCol
|
|
1583
1540
|
} = startCell.current;
|
|
1584
1541
|
if (e.ctrlKey) {
|
|
1542
|
+
|
|
1585
1543
|
// const newCtrlCells = new Set();
|
|
1586
1544
|
// for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
1587
1545
|
// for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
@@ -1591,7 +1549,7 @@ const GridEdit = props => {
|
|
|
1591
1549
|
|
|
1592
1550
|
// setCurrentCtrlCells(newCtrlCells)
|
|
1593
1551
|
|
|
1594
|
-
return
|
|
1552
|
+
// return
|
|
1595
1553
|
}
|
|
1596
1554
|
if (!isPasteDragging) {
|
|
1597
1555
|
// chọn vùng copy
|
|
@@ -1696,10 +1654,8 @@ const GridEdit = props => {
|
|
|
1696
1654
|
(0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
|
|
1697
1655
|
}
|
|
1698
1656
|
selectedCells.current = newSelectedCells;
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
// onAddBorderSelectedCell(newSelectedCells, id)
|
|
1702
|
-
|
|
1657
|
+
(0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
|
|
1658
|
+
(0, _hooks.onAddBorderSelectedCell)(newSelectedCells, id);
|
|
1703
1659
|
(0, _hooks.hideDraggingPoint)(selectedCells.current, id);
|
|
1704
1660
|
(0, _hooks.showDraggingPoint)(newSelectedCells, id);
|
|
1705
1661
|
};
|
|
@@ -1855,7 +1811,9 @@ const GridEdit = props => {
|
|
|
1855
1811
|
const row = {
|
|
1856
1812
|
...formData
|
|
1857
1813
|
};
|
|
1858
|
-
|
|
1814
|
+
|
|
1815
|
+
// const newData = [...dataSource]
|
|
1816
|
+
const newData = [...originData];
|
|
1859
1817
|
|
|
1860
1818
|
// @ts-ignore
|
|
1861
1819
|
const index = (0, _hooks.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
|
|
@@ -1879,7 +1837,6 @@ const GridEdit = props => {
|
|
|
1879
1837
|
indexRow,
|
|
1880
1838
|
key
|
|
1881
1839
|
} = args;
|
|
1882
|
-
if (changeType === 'enter') {}
|
|
1883
1840
|
if (changeType === 'blur') {
|
|
1884
1841
|
const handleChangeCallback = callbackData => {
|
|
1885
1842
|
const callbackRecord = callbackData;
|
|
@@ -1899,7 +1856,8 @@ const GridEdit = props => {
|
|
|
1899
1856
|
indexRow,
|
|
1900
1857
|
rowData: record,
|
|
1901
1858
|
rowId: key,
|
|
1902
|
-
rowsData: [...dataSource],
|
|
1859
|
+
// rowsData: [...dataSource],
|
|
1860
|
+
rowsData: [...originData],
|
|
1903
1861
|
sumValue: []
|
|
1904
1862
|
}, handleChangeCallback);
|
|
1905
1863
|
} else {
|
|
@@ -1912,7 +1870,8 @@ const GridEdit = props => {
|
|
|
1912
1870
|
indexRow,
|
|
1913
1871
|
rowData: record,
|
|
1914
1872
|
rowId: key,
|
|
1915
|
-
rowsData: [...dataSource],
|
|
1873
|
+
// rowsData: [...dataSource],
|
|
1874
|
+
rowsData: [...originData],
|
|
1916
1875
|
sumValue: []
|
|
1917
1876
|
}, handleChangeCallback);
|
|
1918
1877
|
onSubmit(record);
|
|
@@ -1923,7 +1882,7 @@ const GridEdit = props => {
|
|
|
1923
1882
|
onSubmit(record);
|
|
1924
1883
|
}
|
|
1925
1884
|
};
|
|
1926
|
-
const handleEdit = (record, col, editType, e) => {
|
|
1885
|
+
const handleEdit = (record, col, editType, rowIndex, e) => {
|
|
1927
1886
|
(0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
|
|
1928
1887
|
setTooltipContent('');
|
|
1929
1888
|
|
|
@@ -1965,7 +1924,17 @@ const GridEdit = props => {
|
|
|
1965
1924
|
if (startSelectedCells.current && startSelectedCells.current.row !== undefined && startSelectedCells.current.col !== undefined) {
|
|
1966
1925
|
setTimeout(() => {
|
|
1967
1926
|
const input = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${startSelectedCells.current.row}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] input`);
|
|
1927
|
+
const textarea = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${startSelectedCells.current.row}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] textarea`);
|
|
1968
1928
|
const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells.current.col}"] .ant-select-selection-search input`);
|
|
1929
|
+
if (textarea) {
|
|
1930
|
+
// input.focus({
|
|
1931
|
+
// preventScroll: true,
|
|
1932
|
+
// cursor: 'end'
|
|
1933
|
+
// })
|
|
1934
|
+
|
|
1935
|
+
textarea.focus();
|
|
1936
|
+
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
|
1937
|
+
}
|
|
1969
1938
|
if (input) {
|
|
1970
1939
|
input.focus();
|
|
1971
1940
|
}
|
|
@@ -1975,7 +1944,7 @@ const GridEdit = props => {
|
|
|
1975
1944
|
// @ts-ignore
|
|
1976
1945
|
select.focus();
|
|
1977
1946
|
}
|
|
1978
|
-
},
|
|
1947
|
+
}, 20);
|
|
1979
1948
|
}
|
|
1980
1949
|
};
|
|
1981
1950
|
|
|
@@ -2146,6 +2115,31 @@ const GridEdit = props => {
|
|
|
2146
2115
|
}
|
|
2147
2116
|
return {
|
|
2148
2117
|
...column,
|
|
2118
|
+
title: /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(SortableHeaderCell, {
|
|
2119
|
+
columnKey: column.field
|
|
2120
|
+
}, /*#__PURE__*/_react.default.createElement(_HeaderContent.default, {
|
|
2121
|
+
column: {
|
|
2122
|
+
...column
|
|
2123
|
+
},
|
|
2124
|
+
t: t,
|
|
2125
|
+
id: id,
|
|
2126
|
+
wrapSettings: wrapSettings,
|
|
2127
|
+
onClick: () => {
|
|
2128
|
+
handleClickColHeader(column, colIndex);
|
|
2129
|
+
},
|
|
2130
|
+
onCopy: e => {
|
|
2131
|
+
if (editingKey.current === '') {
|
|
2132
|
+
handleCopy(e);
|
|
2133
|
+
e.preventDefault();
|
|
2134
|
+
}
|
|
2135
|
+
},
|
|
2136
|
+
onPaste: event => {
|
|
2137
|
+
if (editingKey.current === '') {
|
|
2138
|
+
handlePaste(dataSource[0], colIndex, 0, event);
|
|
2139
|
+
event.preventDefault();
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
}))),
|
|
2149
2143
|
onCell: (record, rowIndex) => {
|
|
2150
2144
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
2151
2145
|
return {
|
|
@@ -2158,7 +2152,7 @@ const GridEdit = props => {
|
|
|
2158
2152
|
// ~~ khi editingKey = ''
|
|
2159
2153
|
event.preventDefault();
|
|
2160
2154
|
event.stopPropagation();
|
|
2161
|
-
handleEdit(record, column, column.editType, event);
|
|
2155
|
+
handleEdit(record, column, column.editType, rowNumber, event);
|
|
2162
2156
|
|
|
2163
2157
|
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
2164
2158
|
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
@@ -2174,20 +2168,22 @@ const GridEdit = props => {
|
|
|
2174
2168
|
onTriggerExpand(record);
|
|
2175
2169
|
}
|
|
2176
2170
|
} else {
|
|
2177
|
-
if (event.key === 'Enter') {
|
|
2178
|
-
event.
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2171
|
+
if (event.shiftKey && event.key === 'Enter') {} else {
|
|
2172
|
+
if (event.key === 'Enter') {
|
|
2173
|
+
event.preventDefault();
|
|
2174
|
+
event.stopPropagation();
|
|
2175
|
+
if (editingKey && editingKey.current !== '' && (rowNumber ?? 0) + 1 < (0, _hooks.flattenArray)(dataSource).length && event.key === 'Enter') {
|
|
2176
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
2177
|
+
} else {
|
|
2178
|
+
// // focus cell hiện tại và tắt edit
|
|
2179
|
+
// handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
|
|
2180
|
+
// setEditingKey('')
|
|
2181
|
+
|
|
2182
|
+
// thêm dòng mới
|
|
2183
|
+
|
|
2184
|
+
handleAddSingle();
|
|
2185
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true);
|
|
2186
|
+
}
|
|
2191
2187
|
}
|
|
2192
2188
|
}
|
|
2193
2189
|
}
|
|
@@ -2257,7 +2253,7 @@ const GridEdit = props => {
|
|
|
2257
2253
|
onDoubleClick: event => {
|
|
2258
2254
|
// if (!isEditing(record) && record[rowKey] !== editingKey.current && isEditable(column as any, record)) {
|
|
2259
2255
|
if (!(record[rowKey] === editingKey.current) && record[rowKey] !== editingKey.current && (0, _hooks.isEditable)(column, record)) {
|
|
2260
|
-
handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
|
|
2256
|
+
handleEdit(record, column, (0, _hooks.getEditType)(column, record), rowNumber, event);
|
|
2261
2257
|
|
|
2262
2258
|
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
2263
2259
|
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
@@ -2268,17 +2264,21 @@ const GridEdit = props => {
|
|
|
2268
2264
|
// isSelecting.current = true;
|
|
2269
2265
|
// startCell.current = { row: rowNumber, col: colIndex };
|
|
2270
2266
|
|
|
2271
|
-
if (selectedCells.size === 0) {
|
|
2272
|
-
|
|
2273
|
-
|
|
2267
|
+
// if (selectedCells.size === 0) {
|
|
2268
|
+
// setStartSelectedCell({ row: rowNumber, col: colIndex })
|
|
2269
|
+
// setSelectedCells(new Set([`${rowNumber}-${colIndex}`]));
|
|
2270
|
+
(0, _hooks.hideDraggingPoint)(selectedCells.current, id);
|
|
2271
|
+
startSelectedCells.current = {
|
|
2272
|
+
row: rowNumber,
|
|
2273
|
+
col: colIndex
|
|
2274
|
+
};
|
|
2275
|
+
selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
|
|
2276
|
+
rowsSelected.current = new Set();
|
|
2277
|
+
(0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
|
|
2278
|
+
(0, _hooks.showDraggingPoint)(selectedCells.current, id);
|
|
2279
|
+
setRangeCells(selectedCells.current);
|
|
2274
2280
|
|
|
2275
|
-
|
|
2276
|
-
row: rowNumber,
|
|
2277
|
-
col: colIndex
|
|
2278
|
-
};
|
|
2279
|
-
selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
|
|
2280
|
-
rowsSelected.current = new Set();
|
|
2281
|
-
}
|
|
2281
|
+
// }
|
|
2282
2282
|
},
|
|
2283
2283
|
onClick: () => {
|
|
2284
2284
|
if (record[rowKey] !== editingKey.current && editingKey.current !== '') {
|
|
@@ -2304,7 +2304,7 @@ const GridEdit = props => {
|
|
|
2304
2304
|
dataIndex: column.dataIndex,
|
|
2305
2305
|
indexRow: rowNumber,
|
|
2306
2306
|
indexCol: colIndex,
|
|
2307
|
-
title: (0, _columns.getValueCell)(column, record[column.field], record, format),
|
|
2307
|
+
title: (0, _columns.getValueCell)(column, record[column.field], record, rowNumber, colIndex, format),
|
|
2308
2308
|
'data-col-index': colIndex,
|
|
2309
2309
|
'data-row-index': rowNumber,
|
|
2310
2310
|
// 'data-tooltip-id': "tooltip-cell-content",
|
|
@@ -2319,35 +2319,50 @@ const GridEdit = props => {
|
|
|
2319
2319
|
} : {}
|
|
2320
2320
|
};
|
|
2321
2321
|
},
|
|
2322
|
-
onHeaderCell: (data, index) => {
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
},
|
|
2322
|
+
// onHeaderCell: (data: any, index: any) => {
|
|
2323
|
+
//
|
|
2324
|
+
// return ({
|
|
2325
|
+
// ...column.onHeaderCell ? column.onHeaderCell?.(data, index) : {},
|
|
2326
|
+
// // onClick: () => {
|
|
2327
|
+
// // handleClickColHeader(column, colIndex)
|
|
2328
|
+
// // },
|
|
2329
|
+
// // onCopy: (e: any) => {
|
|
2330
|
+
// // if (editingKey.current === '') {
|
|
2331
|
+
// // handleCopy(e)
|
|
2332
|
+
// // e.preventDefault()
|
|
2333
|
+
// // }
|
|
2334
|
+
// // },
|
|
2335
|
+
// //
|
|
2336
|
+
// // onPaste: (event: any) => {
|
|
2337
|
+
// //
|
|
2338
|
+
// // if (editingKey.current === '') {
|
|
2339
|
+
// //
|
|
2340
|
+
// // handlePaste(dataSource[0], colIndex, 0 as number, event)
|
|
2341
|
+
// // event.preventDefault()
|
|
2342
|
+
// // }
|
|
2343
|
+
// //
|
|
2344
|
+
// // },
|
|
2345
|
+
// style: {
|
|
2346
|
+
// userSelect: 'none'
|
|
2347
|
+
// }
|
|
2348
|
+
// })
|
|
2349
|
+
// },
|
|
2350
|
+
|
|
2345
2351
|
render: (value, record, rowIndex) => {
|
|
2346
2352
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
2347
2353
|
const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
|
|
2348
2354
|
const cellFormat = (0, _hooks.getFormat)(colFormat, format);
|
|
2349
2355
|
const rowError = dataErrors.find(it => it.index === rowNumber);
|
|
2350
2356
|
const cellError = rowError && column.field && rowError[column.field]?.field === column.field ? rowError[column.field] : null;
|
|
2357
|
+
const handleClick = event => {
|
|
2358
|
+
if (!(record[rowKey] === editingKey.current) && record[rowKey] !== editingKey.current && (0, _hooks.isEditable)(column, record)) {
|
|
2359
|
+
handleEdit(record, column, (0, _hooks.getEditType)(column, record), rowNumber, event);
|
|
2360
|
+
|
|
2361
|
+
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
2362
|
+
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
2363
|
+
handleCellClick(rowNumber, record, column);
|
|
2364
|
+
}
|
|
2365
|
+
};
|
|
2351
2366
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
2352
2367
|
className: (0, _classnames.default)('ui-rc_cell-content', {
|
|
2353
2368
|
isValid: column.field && rowError && rowError[column.field]?.field === column?.field
|
|
@@ -2356,6 +2371,8 @@ const GridEdit = props => {
|
|
|
2356
2371
|
onMouseEnter: event => {
|
|
2357
2372
|
setTooltipContent(cellError ? cellError.message : '');
|
|
2358
2373
|
handleMouseEnter(rowNumber, colIndex, event);
|
|
2374
|
+
|
|
2375
|
+
// hoveredRow.current = rowNumber
|
|
2359
2376
|
},
|
|
2360
2377
|
onMouseUp: handleMouseUp,
|
|
2361
2378
|
onMouseMove: () => {
|
|
@@ -2365,8 +2382,10 @@ const GridEdit = props => {
|
|
|
2365
2382
|
}
|
|
2366
2383
|
}
|
|
2367
2384
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
2368
|
-
className: 'ui-rc_content'
|
|
2369
|
-
|
|
2385
|
+
className: (0, _classnames.default)('ui-rc_content', {
|
|
2386
|
+
'select-cell': ['select', 'selectTable', 'asyncSelect'].includes((0, _hooks.getEditType)(column, record))
|
|
2387
|
+
})
|
|
2388
|
+
}, (0, _columns.renderContent)(column, value, record, rowIndex, colIndex, true, cellFormat, handleClick)), !isDragMouse.current && /*#__PURE__*/_react.default.createElement("div", {
|
|
2370
2389
|
className: 'dragging-point hidden',
|
|
2371
2390
|
onMouseDown: e => {
|
|
2372
2391
|
// e.stopPropagation()
|
|
@@ -2533,7 +2552,7 @@ const GridEdit = props => {
|
|
|
2533
2552
|
value: {
|
|
2534
2553
|
id: id ?? '',
|
|
2535
2554
|
rowKey,
|
|
2536
|
-
form,
|
|
2555
|
+
// form,
|
|
2537
2556
|
format,
|
|
2538
2557
|
control,
|
|
2539
2558
|
trigger,
|
|
@@ -2572,6 +2591,7 @@ const GridEdit = props => {
|
|
|
2572
2591
|
...components,
|
|
2573
2592
|
body: {
|
|
2574
2593
|
cell: _EditableCell.default
|
|
2594
|
+
// row: RowComponent
|
|
2575
2595
|
}
|
|
2576
2596
|
},
|
|
2577
2597
|
className: (0, _classnames.default)(className, 'grid-editable'),
|
|
@@ -2633,8 +2653,6 @@ const GridEdit = props => {
|
|
|
2633
2653
|
} : undefined,
|
|
2634
2654
|
triggerChangeColumns: triggerChangeColumns,
|
|
2635
2655
|
clickHeaderToSort: false,
|
|
2636
|
-
isFilter: isFilter,
|
|
2637
|
-
setIsFilter: setIsFilter,
|
|
2638
2656
|
contextMenuItems: contextMenuItems,
|
|
2639
2657
|
contextMenuClick: contextMenuClick,
|
|
2640
2658
|
onScroll: () => {
|