es-grid-template 1.5.16 → 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 +82 -28
- package/es/grid-component/TableGrid.js +42 -108
- 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.d.ts +3 -1
- 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 +4 -1
- package/es/grid-component/table/GridEdit.d.ts +4 -1
- package/es/grid-component/table/GridEdit.js +353 -336
- package/es/grid-component/table/Group.d.ts +4 -1
- package/es/grid-component/table/InfiniteTable.d.ts +4 -1
- package/es/grid-component/table/InfiniteTable.js +4 -2
- package/es/grid-component/type.d.ts +3 -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 +81 -27
- package/lib/grid-component/TableGrid.js +40 -106
- 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 +4 -1
- package/lib/grid-component/table/GridEdit.d.ts +4 -1
- package/lib/grid-component/table/GridEdit.js +343 -334
- package/lib/grid-component/table/Group.d.ts +4 -1
- package/lib/grid-component/table/InfiniteTable.d.ts +4 -1
- package/lib/grid-component/table/InfiniteTable.js +4 -2
- package/lib/grid-component/type.d.ts +3 -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
|
|
@@ -1047,6 +1088,9 @@ const GridEdit = props => {
|
|
|
1047
1088
|
};
|
|
1048
1089
|
// return { row, col, value: '' };
|
|
1049
1090
|
});
|
|
1091
|
+
const copyRows = selectedArray.map(it => ({
|
|
1092
|
+
...(0, _hooks.flattenData)(childrenColumnName, dataSource)[it.row]
|
|
1093
|
+
}));
|
|
1050
1094
|
|
|
1051
1095
|
// Xác định min/max row và col để sắp xếp dữ liệu
|
|
1052
1096
|
const minRow = Math.min(...selectedArray.map(cell => cell.row));
|
|
@@ -1070,57 +1114,69 @@ const GridEdit = props => {
|
|
|
1070
1114
|
let newRange;
|
|
1071
1115
|
if (rowPasteLast > rowSelectedFirst) {
|
|
1072
1116
|
// kéo xuóng
|
|
1073
|
-
newRange = (0, _hooks.
|
|
1117
|
+
newRange = ctrlKey ? (0, _hooks.addRowsDownWithCtrl)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length) : (0, _hooks.addRowsDown)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
|
|
1074
1118
|
} else {
|
|
1075
1119
|
// kéo lên
|
|
1076
|
-
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);
|
|
1077
1121
|
}
|
|
1078
|
-
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[(0, _hooks.getFirstSelectCell)(pastesArray).row];
|
|
1079
|
-
if (!record?.parentId) {
|
|
1080
|
-
// Cập nhật data mới
|
|
1081
|
-
const newData = [...dataSource];
|
|
1082
1122
|
|
|
1083
|
-
|
|
1084
|
-
// const { row: startRow, col: startCol } = selectedCell;
|
|
1085
|
-
const startRow = (0, _hooks.getFirstSelectCell)(pastesArray).row;
|
|
1086
|
-
const startCol = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
|
|
1087
|
-
const pastedRows = [];
|
|
1088
|
-
const pastedColumns = new Set();
|
|
1089
|
-
newRange.addedRows.forEach((rowValues, rowIndex) => {
|
|
1090
|
-
const targetRow = startRow + rowIndex;
|
|
1091
|
-
|
|
1092
|
-
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1093
|
-
if (targetRow >= newData.length) {
|
|
1094
|
-
// @ts-ignore
|
|
1095
|
-
newData.push({
|
|
1096
|
-
id: undefined,
|
|
1097
|
-
rowId: (0, _hooks.newGuid)()
|
|
1098
|
-
});
|
|
1099
|
-
}
|
|
1100
|
-
rowValues.forEach((cellValue, colIndex) => {
|
|
1101
|
-
const targetCol = startCol + colIndex;
|
|
1102
|
-
if (targetCol >= tmpCols.length) {
|
|
1103
|
-
// Không vượt quá số cột
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1123
|
+
// const record = flattenData(childrenColumnName, dataSource)[getFirstSelectCell(pastesArray).row]
|
|
1106
1124
|
|
|
1107
|
-
|
|
1108
|
-
const columnKey = tmpCols[targetCol].field;
|
|
1125
|
+
// if (!record?.parentId) {
|
|
1109
1126
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
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)()
|
|
1116
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
|
+
}
|
|
1117
1154
|
|
|
1118
|
-
//
|
|
1119
|
-
|
|
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);
|
|
1120
1164
|
});
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
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
|
+
// }
|
|
1124
1180
|
|
|
1125
1181
|
/// cập nhật cell class
|
|
1126
1182
|
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
@@ -1149,13 +1205,9 @@ const GridEdit = props => {
|
|
|
1149
1205
|
};
|
|
1150
1206
|
const handlePasted = (record, indexCol, rowNumber, pasteData) => {
|
|
1151
1207
|
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
1152
|
-
console.log('rows', rows);
|
|
1153
|
-
console.log('record', record);
|
|
1154
1208
|
if (!record?.parentId) {
|
|
1155
|
-
console.log('1');
|
|
1156
|
-
|
|
1157
1209
|
// Cập nhật data mới
|
|
1158
|
-
const newData = [...dataSource];
|
|
1210
|
+
const newData = (0, _hooks.flattenArray)([...dataSource]);
|
|
1159
1211
|
|
|
1160
1212
|
// const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
1161
1213
|
|
|
@@ -1186,10 +1238,12 @@ const GridEdit = props => {
|
|
|
1186
1238
|
// Không vượt quá số cột
|
|
1187
1239
|
return;
|
|
1188
1240
|
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1241
|
+
const columnTarget = visibleCols[targetCol];
|
|
1242
|
+
const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(newData[targetRow]) : columnTarget.editEnable;
|
|
1243
|
+
if (isEdit) {
|
|
1192
1244
|
const columnKey = visibleCols[targetCol].field;
|
|
1245
|
+
// const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(newData[targetRow]) : columnTarget.editEnable
|
|
1246
|
+
|
|
1193
1247
|
if (columnTarget.type === 'number' && (0, _hooks.isFormattedNumber)(cellValue.trim())) {
|
|
1194
1248
|
const colFormat = typeof columnTarget.format === 'function' ? columnTarget.format(record) : columnTarget.format;
|
|
1195
1249
|
const valuePasteFormat = (0, _hooks.detectSeparators)(cellValue.trim());
|
|
@@ -1228,15 +1282,17 @@ const GridEdit = props => {
|
|
|
1228
1282
|
pastedRows.push(newData[targetRow]);
|
|
1229
1283
|
});
|
|
1230
1284
|
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
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, []);
|
|
1235
1291
|
} else {
|
|
1236
|
-
console.log('2');
|
|
1237
1292
|
// Cập nhật data mới
|
|
1238
|
-
const newData = [...dataSource]
|
|
1239
|
-
|
|
1293
|
+
// const newData = flattenArray([...dataSource])
|
|
1294
|
+
|
|
1295
|
+
const parent = (0, _hooks.findItemByKey)(dataSource, rowKey, record.parentId);
|
|
1240
1296
|
|
|
1241
1297
|
// Cập nhật childData mới
|
|
1242
1298
|
const childData = parent?.children ? [...parent.children] : [];
|
|
@@ -1264,7 +1320,9 @@ const GridEdit = props => {
|
|
|
1264
1320
|
// Không vượt quá số cột
|
|
1265
1321
|
return;
|
|
1266
1322
|
}
|
|
1267
|
-
|
|
1323
|
+
const columnTarget = visibleCols[targetCol];
|
|
1324
|
+
const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(childData[targetRow]) : columnTarget.editEnable;
|
|
1325
|
+
if (isEdit) {
|
|
1268
1326
|
// @ts-ignore
|
|
1269
1327
|
const columnKey = visibleCols[targetCol].field;
|
|
1270
1328
|
|
|
@@ -1284,15 +1342,27 @@ const GridEdit = props => {
|
|
|
1284
1342
|
const newRowData = {
|
|
1285
1343
|
...parent,
|
|
1286
1344
|
children: childData
|
|
1287
|
-
};
|
|
1288
|
-
|
|
1289
|
-
|
|
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
|
+
|
|
1360
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
|
|
1290
1361
|
}
|
|
1291
1362
|
};
|
|
1292
1363
|
const handlePaste = (record, indexCol, rowNumber, e) => {
|
|
1293
1364
|
// const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
|
|
1294
1365
|
const pasteData = e.clipboardData.getData("text/plain");
|
|
1295
|
-
console.log('pasteData', pasteData);
|
|
1296
1366
|
|
|
1297
1367
|
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
1298
1368
|
const rowsPasted = pasteData.split("\n").map(row =>
|
|
@@ -1326,131 +1396,8 @@ const GridEdit = props => {
|
|
|
1326
1396
|
// ),
|
|
1327
1397
|
});
|
|
1328
1398
|
} else {
|
|
1329
|
-
console.log('5555');
|
|
1330
1399
|
handlePasted(record, indexCol, rowNumber, rowsPasted);
|
|
1331
1400
|
}
|
|
1332
|
-
|
|
1333
|
-
// const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
|
|
1334
|
-
//
|
|
1335
|
-
//
|
|
1336
|
-
// if (!record?.parentId ) {
|
|
1337
|
-
//
|
|
1338
|
-
// // Cập nhật data mới
|
|
1339
|
-
// const newData = [...dataSource];
|
|
1340
|
-
//
|
|
1341
|
-
// // @ts-ignore
|
|
1342
|
-
// const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
|
|
1343
|
-
//
|
|
1344
|
-
// // Lấy vị trí bắt đầu
|
|
1345
|
-
// // const { row: startRow, col: startCol } = selectedCell;
|
|
1346
|
-
// const startRow = indexRows
|
|
1347
|
-
// const startCol = indexCol
|
|
1348
|
-
//
|
|
1349
|
-
//
|
|
1350
|
-
//
|
|
1351
|
-
// // const flattData = flattenArray(newData);
|
|
1352
|
-
//
|
|
1353
|
-
// const pastedRows: RecordType[] = [];
|
|
1354
|
-
// const pastedColumns = new Set()
|
|
1355
|
-
//
|
|
1356
|
-
//
|
|
1357
|
-
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
1358
|
-
// const targetRow = startRow + rowIndex;
|
|
1359
|
-
//
|
|
1360
|
-
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1361
|
-
// if (targetRow >= newData.length) {
|
|
1362
|
-
// // @ts-ignore
|
|
1363
|
-
// // newData.push({ id: newGuid()});
|
|
1364
|
-
// newData.push({ id: undefined, rowId: newGuid()});
|
|
1365
|
-
// }
|
|
1366
|
-
//
|
|
1367
|
-
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
1368
|
-
// const targetCol = startCol + colIndex;
|
|
1369
|
-
// if (targetCol >= columns.length) { // Không vượt quá số cột
|
|
1370
|
-
// return
|
|
1371
|
-
// }
|
|
1372
|
-
//
|
|
1373
|
-
// if (columns[targetCol].editEnable) {
|
|
1374
|
-
// // @ts-ignore
|
|
1375
|
-
// const columnKey = columns[targetCol].field;
|
|
1376
|
-
//
|
|
1377
|
-
// // @ts-ignore
|
|
1378
|
-
// newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
|
|
1379
|
-
// pastedColumns.add(columnKey);
|
|
1380
|
-
// }
|
|
1381
|
-
//
|
|
1382
|
-
// });
|
|
1383
|
-
//
|
|
1384
|
-
// // Lưu dòng được paste
|
|
1385
|
-
// pastedRows.push(newData[targetRow]);
|
|
1386
|
-
//
|
|
1387
|
-
// });
|
|
1388
|
-
//
|
|
1389
|
-
// const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1390
|
-
//
|
|
1391
|
-
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
|
|
1392
|
-
//
|
|
1393
|
-
//
|
|
1394
|
-
// } else {
|
|
1395
|
-
//
|
|
1396
|
-
// // Cập nhật data mới
|
|
1397
|
-
// const newData = [...dataSource];
|
|
1398
|
-
//
|
|
1399
|
-
// const parent = findItemByKey(newData, rowKey as any, record.parentId)
|
|
1400
|
-
//
|
|
1401
|
-
// // Cập nhật childData mới
|
|
1402
|
-
// const childData: any[] = parent?.children ? [...parent.children] : []
|
|
1403
|
-
//
|
|
1404
|
-
//
|
|
1405
|
-
// // Lấy vị trí bắt đầu
|
|
1406
|
-
// // const { row: startRow, col: startCol } = selectedCell;
|
|
1407
|
-
// const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
|
|
1408
|
-
// const startCol = indexCol
|
|
1409
|
-
//
|
|
1410
|
-
// const pastedRows: RecordType[] = []
|
|
1411
|
-
// const pastedColumns = new Set()
|
|
1412
|
-
//
|
|
1413
|
-
//
|
|
1414
|
-
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
1415
|
-
// const targetRow = startRow + rowIndex
|
|
1416
|
-
//
|
|
1417
|
-
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1418
|
-
// if (targetRow >= childData.length) {
|
|
1419
|
-
//
|
|
1420
|
-
// childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
|
|
1421
|
-
// }
|
|
1422
|
-
//
|
|
1423
|
-
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
1424
|
-
// const targetCol = startCol + colIndex
|
|
1425
|
-
// if (targetCol >= columns.length) { // Không vượt quá số cột
|
|
1426
|
-
// return
|
|
1427
|
-
// }
|
|
1428
|
-
//
|
|
1429
|
-
// if (columns[targetCol].editEnable) {
|
|
1430
|
-
//
|
|
1431
|
-
// // @ts-ignore
|
|
1432
|
-
// const columnKey = columns[targetCol].field
|
|
1433
|
-
//
|
|
1434
|
-
// // @ts-ignore
|
|
1435
|
-
// childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
|
|
1436
|
-
// pastedColumns.add(columnKey)
|
|
1437
|
-
// }
|
|
1438
|
-
//
|
|
1439
|
-
// })
|
|
1440
|
-
//
|
|
1441
|
-
// // Lưu dòng được paste
|
|
1442
|
-
// pastedRows.push(childData[targetRow])
|
|
1443
|
-
//
|
|
1444
|
-
// })
|
|
1445
|
-
//
|
|
1446
|
-
// const pastedColumnsArray = Array.from(pastedColumns) ?? []
|
|
1447
|
-
//
|
|
1448
|
-
// const newRowData = {...parent, children: childData}
|
|
1449
|
-
//
|
|
1450
|
-
// const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
|
|
1451
|
-
//
|
|
1452
|
-
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
|
|
1453
|
-
// }
|
|
1454
1401
|
};
|
|
1455
1402
|
const handlePointDoubleClick = e => {
|
|
1456
1403
|
// e.preventDefault()
|
|
@@ -1561,7 +1508,7 @@ const GridEdit = props => {
|
|
|
1561
1508
|
// nếu ctrlCell length > 0 thì set selectCells
|
|
1562
1509
|
|
|
1563
1510
|
if (pasteCells && pasteCells.current.size > 0) {
|
|
1564
|
-
triggerDragPaste(pasteCells.current);
|
|
1511
|
+
triggerDragPaste(pasteCells.current, e.ctrlKey);
|
|
1565
1512
|
} else {
|
|
1566
1513
|
setRangeCells(selectedCells.current);
|
|
1567
1514
|
const target = e.target;
|
|
@@ -1589,6 +1536,7 @@ const GridEdit = props => {
|
|
|
1589
1536
|
col: startCol
|
|
1590
1537
|
} = startCell.current;
|
|
1591
1538
|
if (e.ctrlKey) {
|
|
1539
|
+
|
|
1592
1540
|
// const newCtrlCells = new Set();
|
|
1593
1541
|
// for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
1594
1542
|
// for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
@@ -1598,7 +1546,7 @@ const GridEdit = props => {
|
|
|
1598
1546
|
|
|
1599
1547
|
// setCurrentCtrlCells(newCtrlCells)
|
|
1600
1548
|
|
|
1601
|
-
return
|
|
1549
|
+
// return
|
|
1602
1550
|
}
|
|
1603
1551
|
if (!isPasteDragging) {
|
|
1604
1552
|
// chọn vùng copy
|
|
@@ -1703,10 +1651,8 @@ const GridEdit = props => {
|
|
|
1703
1651
|
(0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
|
|
1704
1652
|
}
|
|
1705
1653
|
selectedCells.current = newSelectedCells;
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
// onAddBorderSelectedCell(newSelectedCells, id)
|
|
1709
|
-
|
|
1654
|
+
(0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
|
|
1655
|
+
(0, _hooks.onAddBorderSelectedCell)(newSelectedCells, id);
|
|
1710
1656
|
(0, _hooks.hideDraggingPoint)(selectedCells.current, id);
|
|
1711
1657
|
(0, _hooks.showDraggingPoint)(newSelectedCells, id);
|
|
1712
1658
|
};
|
|
@@ -1862,7 +1808,9 @@ const GridEdit = props => {
|
|
|
1862
1808
|
const row = {
|
|
1863
1809
|
...formData
|
|
1864
1810
|
};
|
|
1865
|
-
|
|
1811
|
+
|
|
1812
|
+
// const newData = [...dataSource]
|
|
1813
|
+
const newData = [...originData];
|
|
1866
1814
|
|
|
1867
1815
|
// @ts-ignore
|
|
1868
1816
|
const index = (0, _hooks.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
|
|
@@ -1906,7 +1854,8 @@ const GridEdit = props => {
|
|
|
1906
1854
|
indexRow,
|
|
1907
1855
|
rowData: record,
|
|
1908
1856
|
rowId: key,
|
|
1909
|
-
rowsData: [...dataSource],
|
|
1857
|
+
// rowsData: [...dataSource],
|
|
1858
|
+
rowsData: [...originData],
|
|
1910
1859
|
sumValue: []
|
|
1911
1860
|
}, handleChangeCallback);
|
|
1912
1861
|
} else {
|
|
@@ -1919,7 +1868,8 @@ const GridEdit = props => {
|
|
|
1919
1868
|
indexRow,
|
|
1920
1869
|
rowData: record,
|
|
1921
1870
|
rowId: key,
|
|
1922
|
-
rowsData: [...dataSource],
|
|
1871
|
+
// rowsData: [...dataSource],
|
|
1872
|
+
rowsData: [...originData],
|
|
1923
1873
|
sumValue: []
|
|
1924
1874
|
}, handleChangeCallback);
|
|
1925
1875
|
onSubmit(record);
|
|
@@ -1930,7 +1880,7 @@ const GridEdit = props => {
|
|
|
1930
1880
|
onSubmit(record);
|
|
1931
1881
|
}
|
|
1932
1882
|
};
|
|
1933
|
-
const handleEdit = (record, col, editType, e) => {
|
|
1883
|
+
const handleEdit = (record, col, editType, rowIndex, e) => {
|
|
1934
1884
|
(0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
|
|
1935
1885
|
setTooltipContent('');
|
|
1936
1886
|
|
|
@@ -1972,7 +1922,17 @@ const GridEdit = props => {
|
|
|
1972
1922
|
if (startSelectedCells.current && startSelectedCells.current.row !== undefined && startSelectedCells.current.col !== undefined) {
|
|
1973
1923
|
setTimeout(() => {
|
|
1974
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`);
|
|
1975
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
|
+
}
|
|
1976
1936
|
if (input) {
|
|
1977
1937
|
input.focus();
|
|
1978
1938
|
}
|
|
@@ -1982,7 +1942,7 @@ const GridEdit = props => {
|
|
|
1982
1942
|
// @ts-ignore
|
|
1983
1943
|
select.focus();
|
|
1984
1944
|
}
|
|
1985
|
-
},
|
|
1945
|
+
}, 20);
|
|
1986
1946
|
}
|
|
1987
1947
|
};
|
|
1988
1948
|
|
|
@@ -2153,6 +2113,31 @@ const GridEdit = props => {
|
|
|
2153
2113
|
}
|
|
2154
2114
|
return {
|
|
2155
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
|
+
}))),
|
|
2156
2141
|
onCell: (record, rowIndex) => {
|
|
2157
2142
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
2158
2143
|
return {
|
|
@@ -2165,7 +2150,7 @@ const GridEdit = props => {
|
|
|
2165
2150
|
// ~~ khi editingKey = ''
|
|
2166
2151
|
event.preventDefault();
|
|
2167
2152
|
event.stopPropagation();
|
|
2168
|
-
handleEdit(record, column, column.editType, event);
|
|
2153
|
+
handleEdit(record, column, column.editType, rowNumber, event);
|
|
2169
2154
|
|
|
2170
2155
|
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
2171
2156
|
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
@@ -2181,20 +2166,22 @@ const GridEdit = props => {
|
|
|
2181
2166
|
onTriggerExpand(record);
|
|
2182
2167
|
}
|
|
2183
2168
|
} else {
|
|
2184
|
-
if (event.key === 'Enter') {
|
|
2185
|
-
event.
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
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
|
+
}
|
|
2198
2185
|
}
|
|
2199
2186
|
}
|
|
2200
2187
|
}
|
|
@@ -2250,7 +2237,6 @@ const GridEdit = props => {
|
|
|
2250
2237
|
}
|
|
2251
2238
|
},
|
|
2252
2239
|
onPaste: event => {
|
|
2253
|
-
console.log('aaaaaa');
|
|
2254
2240
|
if (editingKey.current === '') {
|
|
2255
2241
|
handlePaste(record, colIndex, rowNumber, event);
|
|
2256
2242
|
event.preventDefault();
|
|
@@ -2265,7 +2251,7 @@ const GridEdit = props => {
|
|
|
2265
2251
|
onDoubleClick: event => {
|
|
2266
2252
|
// if (!isEditing(record) && record[rowKey] !== editingKey.current && isEditable(column as any, record)) {
|
|
2267
2253
|
if (!(record[rowKey] === editingKey.current) && record[rowKey] !== editingKey.current && (0, _hooks.isEditable)(column, record)) {
|
|
2268
|
-
handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
|
|
2254
|
+
handleEdit(record, column, (0, _hooks.getEditType)(column, record), rowNumber, event);
|
|
2269
2255
|
|
|
2270
2256
|
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
2271
2257
|
// onRemoveBorderSelectedCell(selectedCells.current, id)
|
|
@@ -2276,17 +2262,21 @@ const GridEdit = props => {
|
|
|
2276
2262
|
// isSelecting.current = true;
|
|
2277
2263
|
// startCell.current = { row: rowNumber, col: colIndex };
|
|
2278
2264
|
|
|
2279
|
-
if (selectedCells.size === 0) {
|
|
2280
|
-
|
|
2281
|
-
|
|
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);
|
|
2282
2278
|
|
|
2283
|
-
|
|
2284
|
-
row: rowNumber,
|
|
2285
|
-
col: colIndex
|
|
2286
|
-
};
|
|
2287
|
-
selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
|
|
2288
|
-
rowsSelected.current = new Set();
|
|
2289
|
-
}
|
|
2279
|
+
// }
|
|
2290
2280
|
},
|
|
2291
2281
|
onClick: () => {
|
|
2292
2282
|
if (record[rowKey] !== editingKey.current && editingKey.current !== '') {
|
|
@@ -2312,7 +2302,7 @@ const GridEdit = props => {
|
|
|
2312
2302
|
dataIndex: column.dataIndex,
|
|
2313
2303
|
indexRow: rowNumber,
|
|
2314
2304
|
indexCol: colIndex,
|
|
2315
|
-
title: (0, _columns.getValueCell)(column, record[column.field], record, format),
|
|
2305
|
+
title: (0, _columns.getValueCell)(column, record[column.field], record, rowNumber, colIndex, format),
|
|
2316
2306
|
'data-col-index': colIndex,
|
|
2317
2307
|
'data-row-index': rowNumber,
|
|
2318
2308
|
// 'data-tooltip-id': "tooltip-cell-content",
|
|
@@ -2327,35 +2317,51 @@ const GridEdit = props => {
|
|
|
2327
2317
|
} : {}
|
|
2328
2318
|
};
|
|
2329
2319
|
},
|
|
2330
|
-
onHeaderCell: (data, index) => {
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
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
|
+
|
|
2353
2350
|
render: (value, record, rowIndex) => {
|
|
2354
2351
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
2355
2352
|
const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
|
|
2356
2353
|
const cellFormat = (0, _hooks.getFormat)(colFormat, format);
|
|
2357
2354
|
const rowError = dataErrors.find(it => it.index === rowNumber);
|
|
2358
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
|
+
};
|
|
2359
2365
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
2360
2366
|
className: (0, _classnames.default)('ui-rc_cell-content', {
|
|
2361
2367
|
isValid: column.field && rowError && rowError[column.field]?.field === column?.field
|
|
@@ -2364,6 +2370,8 @@ const GridEdit = props => {
|
|
|
2364
2370
|
onMouseEnter: event => {
|
|
2365
2371
|
setTooltipContent(cellError ? cellError.message : '');
|
|
2366
2372
|
handleMouseEnter(rowNumber, colIndex, event);
|
|
2373
|
+
|
|
2374
|
+
// hoveredRow.current = rowNumber
|
|
2367
2375
|
},
|
|
2368
2376
|
onMouseUp: handleMouseUp,
|
|
2369
2377
|
onMouseMove: () => {
|
|
@@ -2373,8 +2381,10 @@ const GridEdit = props => {
|
|
|
2373
2381
|
}
|
|
2374
2382
|
}
|
|
2375
2383
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
2376
|
-
className: 'ui-rc_content'
|
|
2377
|
-
|
|
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", {
|
|
2378
2388
|
className: 'dragging-point hidden',
|
|
2379
2389
|
onMouseDown: e => {
|
|
2380
2390
|
// e.stopPropagation()
|
|
@@ -2580,6 +2590,7 @@ const GridEdit = props => {
|
|
|
2580
2590
|
...components,
|
|
2581
2591
|
body: {
|
|
2582
2592
|
cell: _EditableCell.default
|
|
2593
|
+
// row: RowComponent
|
|
2583
2594
|
}
|
|
2584
2595
|
},
|
|
2585
2596
|
className: (0, _classnames.default)(className, 'grid-editable'),
|
|
@@ -2641,8 +2652,6 @@ const GridEdit = props => {
|
|
|
2641
2652
|
} : undefined,
|
|
2642
2653
|
triggerChangeColumns: triggerChangeColumns,
|
|
2643
2654
|
clickHeaderToSort: false,
|
|
2644
|
-
isFilter: isFilter,
|
|
2645
|
-
setIsFilter: setIsFilter,
|
|
2646
2655
|
contextMenuItems: contextMenuItems,
|
|
2647
2656
|
contextMenuClick: contextMenuClick,
|
|
2648
2657
|
onScroll: () => {
|