es-grid-template 1.5.17 → 1.6.0
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/EditableCell.js +26 -9
- package/es/grid-component/InternalTable.js +79 -27
- package/es/grid-component/TableGrid.js +39 -107
- 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 +349 -324
- 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 +1 -0
- 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/EditableCell.js +26 -9
- package/lib/grid-component/InternalTable.js +78 -26
- package/lib/grid-component/TableGrid.js +37 -105
- 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 +339 -322
- 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 +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +7 -0
- package/lib/select/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -27,6 +27,8 @@ 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; }
|
|
32
34
|
// import {faker} from "@faker-js/faker";
|
|
@@ -182,6 +184,35 @@ const validateData = async (data, formSchema) => {
|
|
|
182
184
|
return errors;
|
|
183
185
|
}
|
|
184
186
|
};
|
|
187
|
+
const SortableHeaderCell = ({
|
|
188
|
+
children,
|
|
189
|
+
columnKey
|
|
190
|
+
}) => {
|
|
191
|
+
const {
|
|
192
|
+
attributes,
|
|
193
|
+
listeners,
|
|
194
|
+
setNodeRef,
|
|
195
|
+
isDragging
|
|
196
|
+
} = (0, _sortable.useSortable)({
|
|
197
|
+
id: columnKey
|
|
198
|
+
});
|
|
199
|
+
const style = {
|
|
200
|
+
// ...props.style,
|
|
201
|
+
cursor: 'move',
|
|
202
|
+
// position: 'absolute',
|
|
203
|
+
// left: 3,
|
|
204
|
+
// top: -2,
|
|
205
|
+
...(isDragging ? {
|
|
206
|
+
zIndex: 9999,
|
|
207
|
+
userSelect: 'none'
|
|
208
|
+
} : {})
|
|
209
|
+
// ...dragActiveStyle(dragState, props.id),
|
|
210
|
+
};
|
|
211
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
212
|
+
ref: setNodeRef,
|
|
213
|
+
style: style
|
|
214
|
+
}, attributes, listeners), children);
|
|
215
|
+
};
|
|
185
216
|
const GridEdit = props => {
|
|
186
217
|
const {
|
|
187
218
|
id,
|
|
@@ -189,6 +220,7 @@ const GridEdit = props => {
|
|
|
189
220
|
t,
|
|
190
221
|
columns,
|
|
191
222
|
dataSource,
|
|
223
|
+
originData,
|
|
192
224
|
components,
|
|
193
225
|
allowResizing,
|
|
194
226
|
rowKey = 'id',
|
|
@@ -215,12 +247,17 @@ const GridEdit = props => {
|
|
|
215
247
|
setTooltipContent,
|
|
216
248
|
onBlur,
|
|
217
249
|
locale,
|
|
250
|
+
mergedFilterKeys,
|
|
251
|
+
setMergedFilterKeys,
|
|
252
|
+
wrapSettings,
|
|
218
253
|
...rest
|
|
219
254
|
} = props;
|
|
220
255
|
const ref = (0, _react.useRef)(null);
|
|
221
256
|
const isSelecting = (0, _react.useRef)(false);
|
|
222
257
|
const startCell = (0, _react.useRef)(null);
|
|
223
258
|
const childrenColumnName = 'children';
|
|
259
|
+
|
|
260
|
+
// const hoveredRow: any = useRef(null)
|
|
224
261
|
const isSelectingRow = (0, _react.useRef)(false);
|
|
225
262
|
const rowStart = (0, _react.useRef)(null);
|
|
226
263
|
const rowsSelected = (0, _react.useRef)(new Set());
|
|
@@ -381,7 +418,14 @@ const GridEdit = props => {
|
|
|
381
418
|
// const [editingKey, setEditingKey] = useState<string | number>('')
|
|
382
419
|
|
|
383
420
|
const [dataErrors, setDataErrors] = (0, _react.useState)([]);
|
|
384
|
-
|
|
421
|
+
|
|
422
|
+
// const abc = useMemo(() => {
|
|
423
|
+
//
|
|
424
|
+
// return selectedCells
|
|
425
|
+
// // return [...new Set(Array.from(selectedCells.current).map((item: any) => parseInt(item.split('-')[0])))]
|
|
426
|
+
//
|
|
427
|
+
// }, [selectedCells])
|
|
428
|
+
|
|
385
429
|
const [rangeCells, setRangeCells] = (0, _react.useState)(new Set());
|
|
386
430
|
const [openModalAddRow, setOpenModalAddRow] = (0, _react.useState)({
|
|
387
431
|
open: false,
|
|
@@ -414,8 +458,12 @@ const GridEdit = props => {
|
|
|
414
458
|
}
|
|
415
459
|
}, [validate, dataSource]);
|
|
416
460
|
const rowsFocus = _react.default.useMemo(() => {
|
|
417
|
-
|
|
418
|
-
|
|
461
|
+
const leng = (0, _hooks.flattenArray)(dataSource).length;
|
|
462
|
+
const arr = [...new Set(Array.from(rangeCells).map(item => parseInt(item.split('-')[0])))];
|
|
463
|
+
|
|
464
|
+
// return [...new Set(Array.from(rangeCells).map((item: any) => parseInt(item.split('-')[0])))] ?? []
|
|
465
|
+
return arr.filter(it => it < leng);
|
|
466
|
+
}, [dataSource.length, rangeCells]);
|
|
419
467
|
const contextMenuItems = _react.default.useMemo(() => {
|
|
420
468
|
const a = showDefaultContext !== false ? [...defaultContext] : [];
|
|
421
469
|
const b = propsContext && propsContext.length > 0 ? [...propsContext, {
|
|
@@ -457,7 +505,7 @@ const GridEdit = props => {
|
|
|
457
505
|
triggerChangeData?.(newData, 'Add');
|
|
458
506
|
}
|
|
459
507
|
}, [dataSource, defaultValue, triggerChangeData]);
|
|
460
|
-
const handleAddMulti = _react.default.useCallback((item,
|
|
508
|
+
const handleAddMulti = _react.default.useCallback((item, n) => {
|
|
461
509
|
if (item.onClick) {
|
|
462
510
|
item.onClick({
|
|
463
511
|
toolbar: item
|
|
@@ -465,7 +513,7 @@ const GridEdit = props => {
|
|
|
465
513
|
} else {
|
|
466
514
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
467
515
|
const newRows = Array.from({
|
|
468
|
-
length:
|
|
516
|
+
length: n
|
|
469
517
|
}).map(() => defaultRowValue ? {
|
|
470
518
|
...defaultRowValue,
|
|
471
519
|
id: undefined,
|
|
@@ -474,10 +522,13 @@ const GridEdit = props => {
|
|
|
474
522
|
id: undefined,
|
|
475
523
|
rowId: (0, _hooks.newGuid)()
|
|
476
524
|
});
|
|
525
|
+
const kkk = (0, _hooks.getAllRowKey)(newRows) ?? [];
|
|
526
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
527
|
+
setMergedFilterKeys?.(rs);
|
|
477
528
|
const newData = dataSource.concat(newRows);
|
|
478
529
|
triggerChangeData?.(newData, 'Add');
|
|
479
530
|
}
|
|
480
|
-
}, [dataSource, defaultValue, triggerChangeData]);
|
|
531
|
+
}, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
|
|
481
532
|
const handleDuplicate = _react.default.useCallback(() => {
|
|
482
533
|
// không tính tree
|
|
483
534
|
|
|
@@ -492,22 +543,17 @@ const GridEdit = props => {
|
|
|
492
543
|
|
|
493
544
|
// Vị trí chèn là ngay sau phần tử lớn nhất trong rowsFocus
|
|
494
545
|
const insertAfter = Math.max(...rowsFocus);
|
|
495
|
-
const
|
|
546
|
+
const rsFilter = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
|
|
547
|
+
|
|
548
|
+
// const rs = updateOrInsertInOrder(originData, rsFilter)
|
|
549
|
+
const rs = (0, _hooks.updateOrInsert)(originData, rsFilter);
|
|
550
|
+
// const rs2 = mergeWithFilter(originData, rsFilter)
|
|
551
|
+
|
|
496
552
|
triggerChangeData?.(rs, 'DUPLICATE');
|
|
497
|
-
}, [dataSource, rowsFocus, triggerChangeData]);
|
|
553
|
+
}, [dataSource, originData, rowsFocus, triggerChangeData]);
|
|
498
554
|
|
|
499
555
|
// thêm n dòng bên trên
|
|
500
556
|
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
557
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
512
558
|
// const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
|
|
513
559
|
|
|
@@ -519,51 +565,40 @@ const GridEdit = props => {
|
|
|
519
565
|
} else {
|
|
520
566
|
if (!record?.parentId) {
|
|
521
567
|
// Cập nhật data mới
|
|
522
|
-
const newData = [...dataSource]
|
|
568
|
+
// const newData = [...dataSource]
|
|
569
|
+
const newData = [...originData];
|
|
523
570
|
const newRows = Array.from({
|
|
524
571
|
length: n
|
|
525
|
-
}).map(() => defaultRowValue ?
|
|
526
|
-
...defaultRowValue,
|
|
527
|
-
id: undefined,
|
|
528
|
-
rowId: (0, _hooks.newGuid)(),
|
|
529
|
-
isFilterState: true
|
|
530
|
-
} : {
|
|
572
|
+
}).map(() => defaultRowValue ? {
|
|
531
573
|
...defaultRowValue,
|
|
532
574
|
id: undefined,
|
|
533
575
|
rowId: (0, _hooks.newGuid)()
|
|
534
|
-
} : isFilter ? {
|
|
535
|
-
id: undefined,
|
|
536
|
-
rowId: (0, _hooks.newGuid)(),
|
|
537
|
-
isFilterState: true
|
|
538
576
|
} : {
|
|
539
577
|
id: undefined,
|
|
540
578
|
rowId: (0, _hooks.newGuid)()
|
|
541
579
|
});
|
|
580
|
+
const kkk = (0, _hooks.getAllRowKey)(newRows) ?? [];
|
|
581
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
582
|
+
setMergedFilterKeys?.(rs);
|
|
542
583
|
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
543
584
|
newData.splice(index, 0, ...newRows);
|
|
544
585
|
triggerChangeData?.(newData, 'INSERT_BEFORE');
|
|
545
586
|
} else {
|
|
546
|
-
const newData = [...dataSource]
|
|
587
|
+
// const newData = [...dataSource]
|
|
588
|
+
const newData = [...originData];
|
|
589
|
+
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
547
590
|
const newRows = Array.from({
|
|
548
591
|
length: n
|
|
549
|
-
}).map(() => defaultRowValue ?
|
|
592
|
+
}).map(() => defaultRowValue ? {
|
|
550
593
|
...defaultRowValue,
|
|
551
594
|
id: undefined,
|
|
552
595
|
rowId: (0, _hooks.newGuid)(),
|
|
553
|
-
|
|
596
|
+
parentId: parent.rowId
|
|
554
597
|
} : {
|
|
555
|
-
...defaultRowValue,
|
|
556
|
-
id: undefined,
|
|
557
|
-
rowId: (0, _hooks.newGuid)()
|
|
558
|
-
} : isFilter ? {
|
|
559
598
|
id: undefined,
|
|
560
599
|
rowId: (0, _hooks.newGuid)(),
|
|
561
|
-
|
|
562
|
-
} : {
|
|
563
|
-
id: undefined,
|
|
564
|
-
rowId: (0, _hooks.newGuid)()
|
|
600
|
+
parentId: parent.rowId
|
|
565
601
|
});
|
|
566
|
-
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
567
602
|
|
|
568
603
|
// Cập nhật childData mới
|
|
569
604
|
const childData = parent?.children ? [...parent.children] : [];
|
|
@@ -577,12 +612,15 @@ const GridEdit = props => {
|
|
|
577
612
|
triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
|
|
578
613
|
}
|
|
579
614
|
}
|
|
580
|
-
}, [dataSource, defaultValue,
|
|
615
|
+
}, [dataSource, defaultValue, mergedFilterKeys, originData, rowKey, rowsFocus, setMergedFilterKeys, triggerChangeData]);
|
|
581
616
|
|
|
582
617
|
//thêm 1 dòng bên dưới
|
|
583
618
|
const handleInsertAfter = _react.default.useCallback((item, n) => {
|
|
584
619
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
585
|
-
const
|
|
620
|
+
const insertAfter = Math.max(...rowsFocus);
|
|
621
|
+
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[insertAfter];
|
|
622
|
+
|
|
623
|
+
// const record: RecordType = flattenData(childrenColumnName, originData)[rowsFocus[rowsFocus.length - 1]]
|
|
586
624
|
|
|
587
625
|
// const record = getRecordByKey()
|
|
588
626
|
|
|
@@ -593,51 +631,41 @@ const GridEdit = props => {
|
|
|
593
631
|
} else {
|
|
594
632
|
if (!record?.parentId) {
|
|
595
633
|
// Cập nhật data mới
|
|
596
|
-
const newData = [...
|
|
634
|
+
const newData = [...originData];
|
|
597
635
|
const newRows = Array.from({
|
|
598
636
|
length: n
|
|
599
|
-
}).map(() => defaultRowValue ?
|
|
600
|
-
...defaultRowValue,
|
|
601
|
-
id: undefined,
|
|
602
|
-
rowId: (0, _hooks.newGuid)(),
|
|
603
|
-
isFilterState: true
|
|
604
|
-
} : {
|
|
637
|
+
}).map(() => defaultRowValue ? {
|
|
605
638
|
...defaultRowValue,
|
|
606
639
|
id: undefined,
|
|
607
640
|
rowId: (0, _hooks.newGuid)()
|
|
608
|
-
} : isFilter ? {
|
|
609
|
-
id: undefined,
|
|
610
|
-
rowId: (0, _hooks.newGuid)(),
|
|
611
|
-
isFilterState: true
|
|
612
641
|
} : {
|
|
613
642
|
id: undefined,
|
|
614
643
|
rowId: (0, _hooks.newGuid)()
|
|
615
644
|
});
|
|
645
|
+
const kkk = (0, _hooks.getAllRowKey)(newRows) ?? [];
|
|
646
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
647
|
+
setMergedFilterKeys?.(rs);
|
|
616
648
|
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
617
649
|
newData.splice(index + 1, 0, ...newRows);
|
|
618
650
|
triggerChangeData?.(newData, 'INSERT_AFTER');
|
|
619
651
|
} else {
|
|
620
|
-
const newData = [...
|
|
652
|
+
const newData = [...originData];
|
|
653
|
+
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
621
654
|
const newRows = Array.from({
|
|
622
655
|
length: n
|
|
623
|
-
}).map(() => defaultRowValue ?
|
|
656
|
+
}).map(() => defaultRowValue ? {
|
|
624
657
|
...defaultRowValue,
|
|
625
658
|
id: undefined,
|
|
626
659
|
rowId: (0, _hooks.newGuid)(),
|
|
627
|
-
|
|
660
|
+
parentId: parent.rowId
|
|
628
661
|
} : {
|
|
629
|
-
...defaultRowValue,
|
|
630
|
-
id: undefined,
|
|
631
|
-
rowId: (0, _hooks.newGuid)()
|
|
632
|
-
} : isFilter ? {
|
|
633
662
|
id: undefined,
|
|
634
663
|
rowId: (0, _hooks.newGuid)(),
|
|
635
|
-
|
|
636
|
-
} : {
|
|
637
|
-
id: undefined,
|
|
638
|
-
rowId: (0, _hooks.newGuid)()
|
|
664
|
+
parentId: parent.rowId
|
|
639
665
|
});
|
|
640
|
-
const
|
|
666
|
+
const kkk = (0, _hooks.getAllRowKey)(newRows) ?? [];
|
|
667
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
668
|
+
setMergedFilterKeys?.(rs);
|
|
641
669
|
|
|
642
670
|
// Cập nhật childData mới
|
|
643
671
|
const childData = parent?.children ? [...parent.children] : [];
|
|
@@ -651,17 +679,18 @@ const GridEdit = props => {
|
|
|
651
679
|
triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
|
|
652
680
|
}
|
|
653
681
|
}
|
|
654
|
-
}, [dataSource,
|
|
682
|
+
}, [defaultValue, dataSource, rowsFocus, originData, mergedFilterKeys, setMergedFilterKeys, triggerChangeData, rowKey]);
|
|
655
683
|
const handleInsertChild = _react.default.useCallback(item => {
|
|
656
684
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
657
|
-
const rowId =
|
|
685
|
+
const rowId = (0, _hooks.newGuid)();
|
|
658
686
|
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
|
|
659
687
|
if (item.onClick) {
|
|
660
688
|
item.onClick({
|
|
661
689
|
toolbar: item
|
|
662
690
|
});
|
|
663
691
|
} else {
|
|
664
|
-
const newData = [...dataSource]
|
|
692
|
+
// const newData = [...dataSource]
|
|
693
|
+
const newData = [...originData];
|
|
665
694
|
let newElement;
|
|
666
695
|
if (!record.children || record.children.length === 0) {
|
|
667
696
|
newElement = {
|
|
@@ -682,6 +711,8 @@ const GridEdit = props => {
|
|
|
682
711
|
}]
|
|
683
712
|
};
|
|
684
713
|
}
|
|
714
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, rowId] : [rowId];
|
|
715
|
+
setMergedFilterKeys?.(rs);
|
|
685
716
|
const newDataSource = (0, _hooks.updateArrayByKey)(newData, newElement, rowKey);
|
|
686
717
|
triggerChangeData?.(newDataSource, 'INSERT_CHILDREN');
|
|
687
718
|
}
|
|
@@ -705,16 +736,25 @@ const GridEdit = props => {
|
|
|
705
736
|
toolbar: item
|
|
706
737
|
});
|
|
707
738
|
} else {
|
|
708
|
-
const
|
|
739
|
+
// const filterData = flattenArray([...dataSource])
|
|
740
|
+
const filterData = (0, _hooks.flattenArray)([...originData]);
|
|
709
741
|
const indexesToDelete = [...rowsFocus];
|
|
710
742
|
|
|
711
743
|
// Sắp xếp giảm dần để xóa từ cuối lên đầu
|
|
712
744
|
indexesToDelete.sort((a, b) => b - a).forEach(index => {
|
|
713
|
-
|
|
745
|
+
filterData.splice(index, 1);
|
|
714
746
|
});
|
|
715
|
-
|
|
747
|
+
|
|
748
|
+
// const newData = updateOrInsert(flattenArray([...originData]), filterData)
|
|
749
|
+
//
|
|
750
|
+
const rs = (0, _hooks.unFlattenData)(filterData);
|
|
751
|
+
triggerChangeData?.([...rs], 'DELETE_ROWS');
|
|
716
752
|
}
|
|
717
|
-
|
|
753
|
+
setTimeout(() => {
|
|
754
|
+
(0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
|
|
755
|
+
(0, _hooks.showDraggingPoint)(selectedCells.current, id);
|
|
756
|
+
}, 0);
|
|
757
|
+
}, [id, originData, rowsFocus, triggerChangeData]);
|
|
718
758
|
const handleDeleteAll = _react.default.useCallback(() => {
|
|
719
759
|
triggerChangeData?.([], 'INSERT_BEFORE');
|
|
720
760
|
}, [triggerChangeData]);
|
|
@@ -738,9 +778,12 @@ const GridEdit = props => {
|
|
|
738
778
|
newData[rowIndex][field] = '';
|
|
739
779
|
}
|
|
740
780
|
}
|
|
741
|
-
|
|
781
|
+
const rsFilterData = (0, _hooks.updateOrInsert)((0, _hooks.flattenArray)([...originData]), newData);
|
|
782
|
+
|
|
783
|
+
// triggerChangeData?.([...newData], 'DELETE_CONTENT')
|
|
784
|
+
triggerChangeData?.([...rsFilterData], 'DELETE_CONTENT');
|
|
742
785
|
}
|
|
743
|
-
}, [dataSource, triggerChangeData, visibleCols]);
|
|
786
|
+
}, [dataSource, originData, triggerChangeData, visibleCols]);
|
|
744
787
|
const toolbarItemsBottom = (0, _react.useMemo)(() => {
|
|
745
788
|
if (!rowsFocus || rowsFocus.length === 0) {
|
|
746
789
|
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 +803,13 @@ const GridEdit = props => {
|
|
|
760
803
|
className: 'toolbar-button toolbar-dropdown-button',
|
|
761
804
|
menu: {
|
|
762
805
|
items: itemsAdd,
|
|
763
|
-
onClick: e => handleAddMulti(item, e)
|
|
806
|
+
onClick: e => handleAddMulti(item, Number(e.key))
|
|
764
807
|
}
|
|
765
808
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
766
809
|
style: {
|
|
767
810
|
color: '#28c76f'
|
|
768
811
|
},
|
|
769
|
-
onClick: () =>
|
|
812
|
+
onClick: () => handleAddMulti(item, 1)
|
|
770
813
|
}, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
|
|
771
814
|
}
|
|
772
815
|
};
|
|
@@ -810,13 +853,13 @@ const GridEdit = props => {
|
|
|
810
853
|
className: 'toolbar-button toolbar-dropdown-button',
|
|
811
854
|
menu: {
|
|
812
855
|
items: itemsAdd,
|
|
813
|
-
onClick: e => handleAddMulti(item, e)
|
|
856
|
+
onClick: e => handleAddMulti(item, Number(e.key))
|
|
814
857
|
}
|
|
815
858
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
816
859
|
style: {
|
|
817
860
|
color: '#28c76f'
|
|
818
861
|
},
|
|
819
|
-
onClick: () =>
|
|
862
|
+
onClick: () => handleAddMulti(item, 1)
|
|
820
863
|
}, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
|
|
821
864
|
}
|
|
822
865
|
};
|
|
@@ -949,7 +992,7 @@ const GridEdit = props => {
|
|
|
949
992
|
...item
|
|
950
993
|
};
|
|
951
994
|
});
|
|
952
|
-
}, [handleAddMulti,
|
|
995
|
+
}, [handleAddMulti, handleDeleteAll, handleDeleteRows, handleDuplicate, handleInsertAfter, handleInsertBefore, handleInsertChild, itemsAdd, rowsFocus, t, toolbarItems]);
|
|
953
996
|
const {
|
|
954
997
|
control,
|
|
955
998
|
handleSubmit,
|
|
@@ -969,8 +1012,6 @@ const GridEdit = props => {
|
|
|
969
1012
|
// return record[rowKey as any] === editingKey.current
|
|
970
1013
|
// }, [editingKey, rowKey])
|
|
971
1014
|
|
|
972
|
-
// console.log('isEditing', isEditing)
|
|
973
|
-
|
|
974
1015
|
_react.default.useEffect(() => {
|
|
975
1016
|
const handleClickOutside = event => {
|
|
976
1017
|
const element = event.target;
|
|
@@ -1028,7 +1069,7 @@ const GridEdit = props => {
|
|
|
1028
1069
|
// document.removeEventListener('touchstart', handleClickOutside)
|
|
1029
1070
|
};
|
|
1030
1071
|
}, [dataSource, id, onBlur]);
|
|
1031
|
-
const triggerDragPaste = pastesArray => {
|
|
1072
|
+
const triggerDragPaste = (pastesArray, ctrlKey) => {
|
|
1032
1073
|
const mergedSet = new Set([...selectedCells.current, ...pastesArray]);
|
|
1033
1074
|
const tmpCols = {
|
|
1034
1075
|
...visibleCols
|
|
@@ -1073,57 +1114,69 @@ const GridEdit = props => {
|
|
|
1073
1114
|
let newRange;
|
|
1074
1115
|
if (rowPasteLast > rowSelectedFirst) {
|
|
1075
1116
|
// kéo xuóng
|
|
1076
|
-
newRange = (0, _hooks.
|
|
1117
|
+
newRange = ctrlKey ? (0, _hooks.addRowsDownWithCtrl)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length) : (0, _hooks.addRowsDown)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
|
|
1077
1118
|
} else {
|
|
1078
1119
|
// kéo lên
|
|
1079
|
-
newRange = (0, _hooks.addRowsUp)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
|
|
1120
|
+
newRange = ctrlKey ? (0, _hooks.addRowsUpWithCtrl)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length) : (0, _hooks.addRowsUp)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
|
|
1080
1121
|
}
|
|
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
1122
|
|
|
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;
|
|
1123
|
+
// const record = flattenData(childrenColumnName, dataSource)[getFirstSelectCell(pastesArray).row]
|
|
1094
1124
|
|
|
1095
|
-
|
|
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
|
-
}
|
|
1109
|
-
|
|
1110
|
-
// @ts-ignore
|
|
1111
|
-
const columnKey = tmpCols[targetCol].field;
|
|
1125
|
+
// if (!record?.parentId) {
|
|
1112
1126
|
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1127
|
+
// Cập nhật data mới
|
|
1128
|
+
const newData = (0, _hooks.flattenArray)([...dataSource]);
|
|
1129
|
+
// const newData = flattenArray([...originData])
|
|
1130
|
+
|
|
1131
|
+
// Lấy vị trí bắt đầu
|
|
1132
|
+
// const { row: startRow, col: startCol } = selectedCell;
|
|
1133
|
+
const startRow = (0, _hooks.getFirstSelectCell)(pastesArray).row;
|
|
1134
|
+
const startCol = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
|
|
1135
|
+
const pastedRows = [];
|
|
1136
|
+
const pastedColumns = new Set();
|
|
1137
|
+
newRange.addedRows.forEach((rowValues, rowIndex) => {
|
|
1138
|
+
const targetRow = startRow + rowIndex;
|
|
1139
|
+
|
|
1140
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1141
|
+
if (targetRow >= newData.length) {
|
|
1142
|
+
// @ts-ignore
|
|
1143
|
+
newData.push({
|
|
1144
|
+
id: undefined,
|
|
1145
|
+
rowId: (0, _hooks.newGuid)()
|
|
1119
1146
|
});
|
|
1147
|
+
}
|
|
1148
|
+
rowValues.forEach((cellValue, colIndex) => {
|
|
1149
|
+
const targetCol = startCol + colIndex;
|
|
1150
|
+
if (targetCol >= tmpCols.length) {
|
|
1151
|
+
// Không vượt quá số cột
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1120
1154
|
|
|
1121
|
-
//
|
|
1122
|
-
|
|
1155
|
+
// @ts-ignore
|
|
1156
|
+
const columnKey = tmpCols[targetCol].field;
|
|
1157
|
+
|
|
1158
|
+
// @ts-ignore
|
|
1159
|
+
newData[targetRow] = {
|
|
1160
|
+
...newData[targetRow],
|
|
1161
|
+
[columnKey]: typeof cellValue === 'string' ? cellValue.trim() : cellValue
|
|
1162
|
+
};
|
|
1163
|
+
pastedColumns.add(columnKey);
|
|
1123
1164
|
});
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1165
|
+
|
|
1166
|
+
// Lưu dòng được paste
|
|
1167
|
+
pastedRows.push(newData[targetRow]);
|
|
1168
|
+
});
|
|
1169
|
+
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1170
|
+
|
|
1171
|
+
// const rsFilterData = updateDataByFilter(flattenArray([...originData]), newData)
|
|
1172
|
+
const rsFilterData = (0, _hooks.updateOrInsert)((0, _hooks.flattenArray)([...originData]), newData);
|
|
1173
|
+
// const rsFilterData = mergeWithFilter(flattenArray([...originData]), newData)
|
|
1174
|
+
// const rsFilterData = mergeWithFilter2(flattenArray([...originData]), newData)
|
|
1175
|
+
|
|
1176
|
+
const rs = (0, _hooks.unFlattenData)(rsFilterData);
|
|
1177
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, rs, copyRows);
|
|
1178
|
+
|
|
1179
|
+
// }
|
|
1127
1180
|
|
|
1128
1181
|
/// cập nhật cell class
|
|
1129
1182
|
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
@@ -1154,7 +1207,7 @@ const GridEdit = props => {
|
|
|
1154
1207
|
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
1155
1208
|
if (!record?.parentId) {
|
|
1156
1209
|
// Cập nhật data mới
|
|
1157
|
-
const newData = [...dataSource];
|
|
1210
|
+
const newData = (0, _hooks.flattenArray)([...dataSource]);
|
|
1158
1211
|
|
|
1159
1212
|
// const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
1160
1213
|
|
|
@@ -1185,10 +1238,12 @@ const GridEdit = props => {
|
|
|
1185
1238
|
// Không vượt quá số cột
|
|
1186
1239
|
return;
|
|
1187
1240
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1241
|
+
const columnTarget = visibleCols[targetCol];
|
|
1242
|
+
const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(newData[targetRow]) : columnTarget.editEnable;
|
|
1243
|
+
if (isEdit) {
|
|
1191
1244
|
const columnKey = visibleCols[targetCol].field;
|
|
1245
|
+
// const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(newData[targetRow]) : columnTarget.editEnable
|
|
1246
|
+
|
|
1192
1247
|
if (columnTarget.type === 'number' && (0, _hooks.isFormattedNumber)(cellValue.trim())) {
|
|
1193
1248
|
const colFormat = typeof columnTarget.format === 'function' ? columnTarget.format(record) : columnTarget.format;
|
|
1194
1249
|
const valuePasteFormat = (0, _hooks.detectSeparators)(cellValue.trim());
|
|
@@ -1227,11 +1282,17 @@ const GridEdit = props => {
|
|
|
1227
1282
|
pastedRows.push(newData[targetRow]);
|
|
1228
1283
|
});
|
|
1229
1284
|
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1230
|
-
|
|
1285
|
+
|
|
1286
|
+
// const rsFilterData = updateDataByFilter(flattenArray([...originData]), newData)
|
|
1287
|
+
// const rsFilterData = mergeWithFilter(flattenArray([...originData]), newData)
|
|
1288
|
+
const rsFilterData = (0, _hooks.updateOrInsert)((0, _hooks.flattenArray)([...originData]), newData);
|
|
1289
|
+
const rs = (0, _hooks.unFlattenData)(rsFilterData);
|
|
1290
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, rs, []);
|
|
1231
1291
|
} else {
|
|
1232
1292
|
// Cập nhật data mới
|
|
1233
|
-
const newData = [...dataSource]
|
|
1234
|
-
|
|
1293
|
+
// const newData = flattenArray([...dataSource])
|
|
1294
|
+
|
|
1295
|
+
const parent = (0, _hooks.findItemByKey)(dataSource, rowKey, record.parentId);
|
|
1235
1296
|
|
|
1236
1297
|
// Cập nhật childData mới
|
|
1237
1298
|
const childData = parent?.children ? [...parent.children] : [];
|
|
@@ -1259,7 +1320,9 @@ const GridEdit = props => {
|
|
|
1259
1320
|
// Không vượt quá số cột
|
|
1260
1321
|
return;
|
|
1261
1322
|
}
|
|
1262
|
-
|
|
1323
|
+
const columnTarget = visibleCols[targetCol];
|
|
1324
|
+
const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(childData[targetRow]) : columnTarget.editEnable;
|
|
1325
|
+
if (isEdit) {
|
|
1263
1326
|
// @ts-ignore
|
|
1264
1327
|
const columnKey = visibleCols[targetCol].field;
|
|
1265
1328
|
|
|
@@ -1279,8 +1342,21 @@ const GridEdit = props => {
|
|
|
1279
1342
|
const newRowData = {
|
|
1280
1343
|
...parent,
|
|
1281
1344
|
children: childData
|
|
1282
|
-
};
|
|
1283
|
-
|
|
1345
|
+
}; // item đã được filter
|
|
1346
|
+
|
|
1347
|
+
// const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
|
|
1348
|
+
const newDataSource = (0, _hooks.updateArrayByKey)(originData, newRowData, rowKey);
|
|
1349
|
+
|
|
1350
|
+
//
|
|
1351
|
+
// // const rsFilterData = updateDataByFilter(flattenArray([...originData]), flattenArray(newDataSource))
|
|
1352
|
+
// // const rsFilterData = mergeWithFilter(flattenArray([...originData]), flattenArray(newDataSource))
|
|
1353
|
+
|
|
1354
|
+
// const rsFilterData1 = updateOrInsert(flattenArray([...originData]), flattenArray([...newDataSource]))
|
|
1355
|
+
//
|
|
1356
|
+
//
|
|
1357
|
+
// // const rs = unFlattenData(rsFilterData)
|
|
1358
|
+
// const rs1 = unFlattenData(rsFilterData1)
|
|
1359
|
+
|
|
1284
1360
|
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
|
|
1285
1361
|
}
|
|
1286
1362
|
};
|
|
@@ -1322,128 +1398,6 @@ const GridEdit = props => {
|
|
|
1322
1398
|
} else {
|
|
1323
1399
|
handlePasted(record, indexCol, rowNumber, rowsPasted);
|
|
1324
1400
|
}
|
|
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
1401
|
};
|
|
1448
1402
|
const handlePointDoubleClick = e => {
|
|
1449
1403
|
// e.preventDefault()
|
|
@@ -1554,7 +1508,7 @@ const GridEdit = props => {
|
|
|
1554
1508
|
// nếu ctrlCell length > 0 thì set selectCells
|
|
1555
1509
|
|
|
1556
1510
|
if (pasteCells && pasteCells.current.size > 0) {
|
|
1557
|
-
triggerDragPaste(pasteCells.current);
|
|
1511
|
+
triggerDragPaste(pasteCells.current, e.ctrlKey);
|
|
1558
1512
|
} else {
|
|
1559
1513
|
setRangeCells(selectedCells.current);
|
|
1560
1514
|
const target = e.target;
|
|
@@ -1582,6 +1536,7 @@ const GridEdit = props => {
|
|
|
1582
1536
|
col: startCol
|
|
1583
1537
|
} = startCell.current;
|
|
1584
1538
|
if (e.ctrlKey) {
|
|
1539
|
+
|
|
1585
1540
|
// const newCtrlCells = new Set();
|
|
1586
1541
|
// for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
1587
1542
|
// for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
@@ -1591,7 +1546,7 @@ const GridEdit = props => {
|
|
|
1591
1546
|
|
|
1592
1547
|
// setCurrentCtrlCells(newCtrlCells)
|
|
1593
1548
|
|
|
1594
|
-
return
|
|
1549
|
+
// return
|
|
1595
1550
|
}
|
|
1596
1551
|
if (!isPasteDragging) {
|
|
1597
1552
|
// chọn vùng copy
|
|
@@ -1696,10 +1651,8 @@ const GridEdit = props => {
|
|
|
1696
1651
|
(0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
|
|
1697
1652
|
}
|
|
1698
1653
|
selectedCells.current = newSelectedCells;
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
// onAddBorderSelectedCell(newSelectedCells, id)
|
|
1702
|
-
|
|
1654
|
+
(0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
|
|
1655
|
+
(0, _hooks.onAddBorderSelectedCell)(newSelectedCells, id);
|
|
1703
1656
|
(0, _hooks.hideDraggingPoint)(selectedCells.current, id);
|
|
1704
1657
|
(0, _hooks.showDraggingPoint)(newSelectedCells, id);
|
|
1705
1658
|
};
|
|
@@ -1855,7 +1808,9 @@ const GridEdit = props => {
|
|
|
1855
1808
|
const row = {
|
|
1856
1809
|
...formData
|
|
1857
1810
|
};
|
|
1858
|
-
|
|
1811
|
+
|
|
1812
|
+
// const newData = [...dataSource]
|
|
1813
|
+
const newData = [...originData];
|
|
1859
1814
|
|
|
1860
1815
|
// @ts-ignore
|
|
1861
1816
|
const index = (0, _hooks.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
|
|
@@ -1899,7 +1854,8 @@ const GridEdit = props => {
|
|
|
1899
1854
|
indexRow,
|
|
1900
1855
|
rowData: record,
|
|
1901
1856
|
rowId: key,
|
|
1902
|
-
rowsData: [...dataSource],
|
|
1857
|
+
// rowsData: [...dataSource],
|
|
1858
|
+
rowsData: [...originData],
|
|
1903
1859
|
sumValue: []
|
|
1904
1860
|
}, handleChangeCallback);
|
|
1905
1861
|
} else {
|
|
@@ -1912,7 +1868,8 @@ const GridEdit = props => {
|
|
|
1912
1868
|
indexRow,
|
|
1913
1869
|
rowData: record,
|
|
1914
1870
|
rowId: key,
|
|
1915
|
-
rowsData: [...dataSource],
|
|
1871
|
+
// rowsData: [...dataSource],
|
|
1872
|
+
rowsData: [...originData],
|
|
1916
1873
|
sumValue: []
|
|
1917
1874
|
}, handleChangeCallback);
|
|
1918
1875
|
onSubmit(record);
|
|
@@ -1923,7 +1880,7 @@ const GridEdit = props => {
|
|
|
1923
1880
|
onSubmit(record);
|
|
1924
1881
|
}
|
|
1925
1882
|
};
|
|
1926
|
-
const handleEdit = (record, col, editType, e) => {
|
|
1883
|
+
const handleEdit = (record, col, editType, rowIndex, e) => {
|
|
1927
1884
|
(0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
|
|
1928
1885
|
setTooltipContent('');
|
|
1929
1886
|
|
|
@@ -1965,7 +1922,17 @@ const GridEdit = props => {
|
|
|
1965
1922
|
if (startSelectedCells.current && startSelectedCells.current.row !== undefined && startSelectedCells.current.col !== undefined) {
|
|
1966
1923
|
setTimeout(() => {
|
|
1967
1924
|
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`);
|
|
1925
|
+
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
1926
|
const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells.current.col}"] .ant-select-selection-search input`);
|
|
1927
|
+
if (textarea) {
|
|
1928
|
+
// input.focus({
|
|
1929
|
+
// preventScroll: true,
|
|
1930
|
+
// cursor: 'end'
|
|
1931
|
+
// })
|
|
1932
|
+
|
|
1933
|
+
textarea.focus();
|
|
1934
|
+
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
|
1935
|
+
}
|
|
1969
1936
|
if (input) {
|
|
1970
1937
|
input.focus();
|
|
1971
1938
|
}
|
|
@@ -1975,7 +1942,7 @@ const GridEdit = props => {
|
|
|
1975
1942
|
// @ts-ignore
|
|
1976
1943
|
select.focus();
|
|
1977
1944
|
}
|
|
1978
|
-
},
|
|
1945
|
+
}, 20);
|
|
1979
1946
|
}
|
|
1980
1947
|
};
|
|
1981
1948
|
|
|
@@ -2146,6 +2113,31 @@ const GridEdit = props => {
|
|
|
2146
2113
|
}
|
|
2147
2114
|
return {
|
|
2148
2115
|
...column,
|
|
2116
|
+
title: /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(SortableHeaderCell, {
|
|
2117
|
+
columnKey: column.field
|
|
2118
|
+
}, /*#__PURE__*/_react.default.createElement(_HeaderContent.default, {
|
|
2119
|
+
column: {
|
|
2120
|
+
...column
|
|
2121
|
+
},
|
|
2122
|
+
t: t,
|
|
2123
|
+
id: id,
|
|
2124
|
+
wrapSettings: wrapSettings,
|
|
2125
|
+
onClick: () => {
|
|
2126
|
+
handleClickColHeader(column, colIndex);
|
|
2127
|
+
},
|
|
2128
|
+
onCopy: e => {
|
|
2129
|
+
if (editingKey.current === '') {
|
|
2130
|
+
handleCopy(e);
|
|
2131
|
+
e.preventDefault();
|
|
2132
|
+
}
|
|
2133
|
+
},
|
|
2134
|
+
onPaste: event => {
|
|
2135
|
+
if (editingKey.current === '') {
|
|
2136
|
+
handlePaste(dataSource[0], colIndex, 0, event);
|
|
2137
|
+
event.preventDefault();
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
}))),
|
|
2149
2141
|
onCell: (record, rowIndex) => {
|
|
2150
2142
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
2151
2143
|
return {
|
|
@@ -2158,7 +2150,7 @@ const GridEdit = props => {
|
|
|
2158
2150
|
// ~~ khi editingKey = ''
|
|
2159
2151
|
event.preventDefault();
|
|
2160
2152
|
event.stopPropagation();
|
|
2161
|
-
handleEdit(record, column, column.editType, event);
|
|
2153
|
+
handleEdit(record, column, column.editType, rowNumber, event);
|
|
2162
2154
|
|
|
2163
2155
|
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
2164
2156
|
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
@@ -2174,20 +2166,22 @@ const GridEdit = props => {
|
|
|
2174
2166
|
onTriggerExpand(record);
|
|
2175
2167
|
}
|
|
2176
2168
|
} else {
|
|
2177
|
-
if (event.key === 'Enter') {
|
|
2178
|
-
event.
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2169
|
+
if (event.shiftKey && event.key === 'Enter') {} else {
|
|
2170
|
+
if (event.key === 'Enter') {
|
|
2171
|
+
event.preventDefault();
|
|
2172
|
+
event.stopPropagation();
|
|
2173
|
+
if (editingKey && editingKey.current !== '' && (rowNumber ?? 0) + 1 < (0, _hooks.flattenArray)(dataSource).length && event.key === 'Enter') {
|
|
2174
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
2175
|
+
} else {
|
|
2176
|
+
// // focus cell hiện tại và tắt edit
|
|
2177
|
+
// handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
|
|
2178
|
+
// setEditingKey('')
|
|
2179
|
+
|
|
2180
|
+
// thêm dòng mới
|
|
2181
|
+
|
|
2182
|
+
handleAddSingle();
|
|
2183
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true);
|
|
2184
|
+
}
|
|
2191
2185
|
}
|
|
2192
2186
|
}
|
|
2193
2187
|
}
|
|
@@ -2257,7 +2251,7 @@ const GridEdit = props => {
|
|
|
2257
2251
|
onDoubleClick: event => {
|
|
2258
2252
|
// if (!isEditing(record) && record[rowKey] !== editingKey.current && isEditable(column as any, record)) {
|
|
2259
2253
|
if (!(record[rowKey] === editingKey.current) && record[rowKey] !== editingKey.current && (0, _hooks.isEditable)(column, record)) {
|
|
2260
|
-
handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
|
|
2254
|
+
handleEdit(record, column, (0, _hooks.getEditType)(column, record), rowNumber, event);
|
|
2261
2255
|
|
|
2262
2256
|
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
2263
2257
|
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
@@ -2268,17 +2262,21 @@ const GridEdit = props => {
|
|
|
2268
2262
|
// isSelecting.current = true;
|
|
2269
2263
|
// startCell.current = { row: rowNumber, col: colIndex };
|
|
2270
2264
|
|
|
2271
|
-
if (selectedCells.size === 0) {
|
|
2272
|
-
|
|
2273
|
-
|
|
2265
|
+
// if (selectedCells.size === 0) {
|
|
2266
|
+
// setStartSelectedCell({ row: rowNumber, col: colIndex })
|
|
2267
|
+
// setSelectedCells(new Set([`${rowNumber}-${colIndex}`]));
|
|
2268
|
+
(0, _hooks.hideDraggingPoint)(selectedCells.current, id);
|
|
2269
|
+
startSelectedCells.current = {
|
|
2270
|
+
row: rowNumber,
|
|
2271
|
+
col: colIndex
|
|
2272
|
+
};
|
|
2273
|
+
selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
|
|
2274
|
+
rowsSelected.current = new Set();
|
|
2275
|
+
(0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
|
|
2276
|
+
(0, _hooks.showDraggingPoint)(selectedCells.current, id);
|
|
2277
|
+
setRangeCells(selectedCells.current);
|
|
2274
2278
|
|
|
2275
|
-
|
|
2276
|
-
row: rowNumber,
|
|
2277
|
-
col: colIndex
|
|
2278
|
-
};
|
|
2279
|
-
selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
|
|
2280
|
-
rowsSelected.current = new Set();
|
|
2281
|
-
}
|
|
2279
|
+
// }
|
|
2282
2280
|
},
|
|
2283
2281
|
onClick: () => {
|
|
2284
2282
|
if (record[rowKey] !== editingKey.current && editingKey.current !== '') {
|
|
@@ -2304,7 +2302,7 @@ const GridEdit = props => {
|
|
|
2304
2302
|
dataIndex: column.dataIndex,
|
|
2305
2303
|
indexRow: rowNumber,
|
|
2306
2304
|
indexCol: colIndex,
|
|
2307
|
-
title: (0, _columns.getValueCell)(column, record[column.field], record, format),
|
|
2305
|
+
title: (0, _columns.getValueCell)(column, record[column.field], record, rowNumber, colIndex, format),
|
|
2308
2306
|
'data-col-index': colIndex,
|
|
2309
2307
|
'data-row-index': rowNumber,
|
|
2310
2308
|
// 'data-tooltip-id': "tooltip-cell-content",
|
|
@@ -2319,35 +2317,51 @@ const GridEdit = props => {
|
|
|
2319
2317
|
} : {}
|
|
2320
2318
|
};
|
|
2321
2319
|
},
|
|
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
|
-
|
|
2320
|
+
// onHeaderCell: (data: any, index: any) => {
|
|
2321
|
+
//
|
|
2322
|
+
// return ({
|
|
2323
|
+
// ...column.onHeaderCell ? column.onHeaderCell?.(data, index) : {},
|
|
2324
|
+
// // onClick: () => {
|
|
2325
|
+
// // handleClickColHeader(column, colIndex)
|
|
2326
|
+
// // },
|
|
2327
|
+
// // onCopy: (e: any) => {
|
|
2328
|
+
// // if (editingKey.current === '') {
|
|
2329
|
+
// // handleCopy(e)
|
|
2330
|
+
// // e.preventDefault()
|
|
2331
|
+
// // }
|
|
2332
|
+
// // },
|
|
2333
|
+
// //
|
|
2334
|
+
// // onPaste: (event: any) => {
|
|
2335
|
+
// // console.log('3333', event)
|
|
2336
|
+
// //
|
|
2337
|
+
// // if (editingKey.current === '') {
|
|
2338
|
+
// //
|
|
2339
|
+
// // handlePaste(dataSource[0], colIndex, 0 as number, event)
|
|
2340
|
+
// // event.preventDefault()
|
|
2341
|
+
// // }
|
|
2342
|
+
// //
|
|
2343
|
+
// // },
|
|
2344
|
+
// style: {
|
|
2345
|
+
// userSelect: 'none'
|
|
2346
|
+
// }
|
|
2347
|
+
// })
|
|
2348
|
+
// },
|
|
2349
|
+
|
|
2345
2350
|
render: (value, record, rowIndex) => {
|
|
2346
2351
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
2347
2352
|
const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
|
|
2348
2353
|
const cellFormat = (0, _hooks.getFormat)(colFormat, format);
|
|
2349
2354
|
const rowError = dataErrors.find(it => it.index === rowNumber);
|
|
2350
2355
|
const cellError = rowError && column.field && rowError[column.field]?.field === column.field ? rowError[column.field] : null;
|
|
2356
|
+
const handleClick = event => {
|
|
2357
|
+
if (!(record[rowKey] === editingKey.current) && record[rowKey] !== editingKey.current && (0, _hooks.isEditable)(column, record)) {
|
|
2358
|
+
handleEdit(record, column, (0, _hooks.getEditType)(column, record), rowNumber, event);
|
|
2359
|
+
|
|
2360
|
+
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
2361
|
+
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
2362
|
+
handleCellClick(rowNumber, record, column);
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2351
2365
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
2352
2366
|
className: (0, _classnames.default)('ui-rc_cell-content', {
|
|
2353
2367
|
isValid: column.field && rowError && rowError[column.field]?.field === column?.field
|
|
@@ -2356,6 +2370,8 @@ const GridEdit = props => {
|
|
|
2356
2370
|
onMouseEnter: event => {
|
|
2357
2371
|
setTooltipContent(cellError ? cellError.message : '');
|
|
2358
2372
|
handleMouseEnter(rowNumber, colIndex, event);
|
|
2373
|
+
|
|
2374
|
+
// hoveredRow.current = rowNumber
|
|
2359
2375
|
},
|
|
2360
2376
|
onMouseUp: handleMouseUp,
|
|
2361
2377
|
onMouseMove: () => {
|
|
@@ -2365,8 +2381,10 @@ const GridEdit = props => {
|
|
|
2365
2381
|
}
|
|
2366
2382
|
}
|
|
2367
2383
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
2368
|
-
className: 'ui-rc_content'
|
|
2369
|
-
|
|
2384
|
+
className: (0, _classnames.default)('ui-rc_content', {
|
|
2385
|
+
'select-cell': ['select', 'selectTable', 'asyncSelect'].includes((0, _hooks.getEditType)(column, record))
|
|
2386
|
+
})
|
|
2387
|
+
}, (0, _columns.renderContent)(column, value, record, rowIndex, colIndex, true, cellFormat, handleClick)), !isDragMouse.current && /*#__PURE__*/_react.default.createElement("div", {
|
|
2370
2388
|
className: 'dragging-point hidden',
|
|
2371
2389
|
onMouseDown: e => {
|
|
2372
2390
|
// e.stopPropagation()
|
|
@@ -2572,6 +2590,7 @@ const GridEdit = props => {
|
|
|
2572
2590
|
...components,
|
|
2573
2591
|
body: {
|
|
2574
2592
|
cell: _EditableCell.default
|
|
2593
|
+
// row: RowComponent
|
|
2575
2594
|
}
|
|
2576
2595
|
},
|
|
2577
2596
|
className: (0, _classnames.default)(className, 'grid-editable'),
|
|
@@ -2633,8 +2652,6 @@ const GridEdit = props => {
|
|
|
2633
2652
|
} : undefined,
|
|
2634
2653
|
triggerChangeColumns: triggerChangeColumns,
|
|
2635
2654
|
clickHeaderToSort: false,
|
|
2636
|
-
isFilter: isFilter,
|
|
2637
|
-
setIsFilter: setIsFilter,
|
|
2638
2655
|
contextMenuItems: contextMenuItems,
|
|
2639
2656
|
contextMenuClick: contextMenuClick,
|
|
2640
2657
|
onScroll: () => {
|