es-grid-template 1.7.42 → 1.7.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/table-component/TableContainerEdit.d.ts +5 -1
- package/es/table-component/TableContainerEdit.js +173 -13
- package/es/table-component/body/EditableCell.js +6 -3
- package/es/table-component/body/TableBodyCellEdit.js +37 -2
- package/es/table-component/header/TableHeadCell.js +2 -2
- package/es/table-component/style.scss +1 -1
- package/es/table-component/table/Grid.js +30 -18
- package/es/table-component/type.d.ts +4 -0
- package/lib/table-component/TableContainerEdit.d.ts +5 -1
- package/lib/table-component/TableContainerEdit.js +172 -12
- package/lib/table-component/body/EditableCell.js +6 -3
- package/lib/table-component/body/TableBodyCellEdit.js +37 -2
- package/lib/table-component/header/TableHeadCell.js +2 -2
- package/lib/table-component/style.scss +1 -1
- package/lib/table-component/table/Grid.js +29 -17
- package/lib/table-component/type.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Dispatch, SetStateAction } from "react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import type { ColumnDef, Table } from "@tanstack/react-table";
|
|
3
|
+
import type { ColumnDef, ColumnSizingInfoState, ColumnSizingState, Table } from "@tanstack/react-table";
|
|
4
4
|
import type { ColumnsTable, TableProps } from "./type";
|
|
5
5
|
type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
6
|
table: Table<T>;
|
|
@@ -32,6 +32,10 @@ type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
|
32
32
|
columnHidden: any;
|
|
33
33
|
isFullScreen: boolean;
|
|
34
34
|
setIsFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
35
|
+
setColumnSizing: Dispatch<SetStateAction<any>>;
|
|
36
|
+
setColumns: Dispatch<SetStateAction<any>>;
|
|
37
|
+
columnSizingInfo: ColumnSizingInfoState;
|
|
38
|
+
columnSizing: ColumnSizingState;
|
|
35
39
|
};
|
|
36
40
|
declare const TableContainerEdit: <RecordType extends object>(props: TableContainerProps<RecordType>) => React.JSX.Element;
|
|
37
41
|
export default TableContainerEdit;
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import React, { Fragment } from "react";
|
|
3
3
|
import { checkDecimalSeparator, checkThousandSeparator, detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween, getDefaultValue, getFormat, getRowIdsBetween, getSelectedCellMatrix, isEditable, isFormattedNumber, newGuid, sumSize,
|
|
4
4
|
// sumSize,
|
|
5
|
-
unFlattenData, updateArrayByKey, updateOrInsert } from "./hook/utils";
|
|
5
|
+
unFlattenData, updateArrayByKey, updateColumnWidthsRecursive, updateOrInsert } from "./hook/utils";
|
|
6
6
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
7
7
|
import { useForm } from 'react-hook-form';
|
|
8
8
|
import { Button, Modal, Typography, Dropdown } from "antd";
|
|
@@ -117,7 +117,11 @@ const TableContainerEdit = props => {
|
|
|
117
117
|
showDefaultContext,
|
|
118
118
|
commandSettings,
|
|
119
119
|
isDataTree,
|
|
120
|
-
onCellClick
|
|
120
|
+
onCellClick,
|
|
121
|
+
// setColumnSizing,
|
|
122
|
+
setColumns,
|
|
123
|
+
columnSizing,
|
|
124
|
+
columnSizingInfo
|
|
121
125
|
} = props;
|
|
122
126
|
const containerRef = React.useRef(null);
|
|
123
127
|
const bottomToolbarRef = React.useRef(null);
|
|
@@ -352,7 +356,9 @@ const TableContainerEdit = props => {
|
|
|
352
356
|
return startCell && endCell ? getRowIdsBetween(table, startCell.rowId, endCell.rowId) : [];
|
|
353
357
|
}, [endCell, startCell, table]);
|
|
354
358
|
const copySelectionToClipboard = React.useCallback(() => {
|
|
355
|
-
if (!startCell || !endCell)
|
|
359
|
+
if (!startCell || !endCell) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
356
362
|
|
|
357
363
|
// const allRows = table.getRowModel().rows;
|
|
358
364
|
const allRows = table.getRowModel().flatRows;
|
|
@@ -660,24 +666,178 @@ const TableContainerEdit = props => {
|
|
|
660
666
|
}, [dataSource, editingKey, id, onBlur]);
|
|
661
667
|
const columnSizingState = table.getState().columnSizing;
|
|
662
668
|
React.useEffect(() => {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
669
|
+
|
|
670
|
+
// requestAnimationFrame(() => {
|
|
671
|
+
|
|
672
|
+
// columnVirtualizer.measure()
|
|
673
|
+
// })
|
|
666
674
|
}, [columnSizingState, columnVirtualizer]);
|
|
667
675
|
React.useEffect(() => {
|
|
668
|
-
if (!
|
|
669
|
-
|
|
676
|
+
if (!tableContainerRef.current) {
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
const containerWidth = tableContainerRef.current.offsetWidth;
|
|
670
680
|
const totalWidth = table.getTotalSize();
|
|
671
|
-
if (totalWidth && totalWidth
|
|
681
|
+
if (totalWidth && totalWidth <= containerWidth) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (columnSizingInfo.isResizingColumn === false) {
|
|
685
|
+
const aa = updateColumnWidthsRecursive(propsColumns, columnSizing);
|
|
686
|
+
setColumns(aa);
|
|
687
|
+
requestAnimationFrame(() => {
|
|
688
|
+
columnVirtualizer.measure();
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}, [columnSizingInfo]);
|
|
692
|
+
React.useEffect(() => {
|
|
693
|
+
// if (!containerRef.current || !tableContainerRef.current) {
|
|
694
|
+
if (!tableContainerRef.current) {
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// const containerWidth = containerRef.current.offsetWidth - 1
|
|
699
|
+
// const containerWidth = tableContainerRef.current.offsetWidth
|
|
700
|
+
const containerWidth = tableContainerRef.current.offsetWidth - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0);
|
|
701
|
+
const totalWidth = table.getTotalSize() - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0);
|
|
702
|
+
if (totalWidth && totalWidth > 0 && totalWidth < containerWidth) {
|
|
672
703
|
const factor = containerWidth / totalWidth;
|
|
673
|
-
table.
|
|
674
|
-
|
|
704
|
+
const visibleCols = table.getVisibleLeafColumns();
|
|
705
|
+
const baseSizes = visibleCols.map(col => col.getSize() || col.columnDef.size || 150);
|
|
706
|
+
const scaledSizes = baseSizes.map(size => size * factor);
|
|
707
|
+
const roundedSizes = scaledSizes.map(size => Math.floor(size));
|
|
708
|
+
let diff = containerWidth - roundedSizes.reduce((a, b) => a + b, 0);
|
|
709
|
+
|
|
710
|
+
// phân bổ diff cho các cột từ trái qua phải
|
|
711
|
+
for (let i = 0; diff > 0; i = (i + 1) % roundedSizes.length) {
|
|
712
|
+
roundedSizes[i]++;
|
|
713
|
+
diff--;
|
|
714
|
+
}
|
|
715
|
+
const aaa = visibleCols.reduce((acc, col, idx) => {
|
|
716
|
+
acc[col.id] = roundedSizes[idx];
|
|
675
717
|
return acc;
|
|
676
|
-
}, {})
|
|
718
|
+
}, {});
|
|
719
|
+
const aa = updateColumnWidthsRecursive(propsColumns, aaa);
|
|
720
|
+
setColumns(aa);
|
|
721
|
+
table.setColumnSizing(aaa);
|
|
722
|
+
requestAnimationFrame(() => {
|
|
723
|
+
columnVirtualizer.measure();
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
// setColumnSizing?.(aaa)
|
|
727
|
+
} else {
|
|
728
|
+
if (columnHidden) {
|
|
729
|
+
const abb = table.getVisibleLeafColumns()?.[0];
|
|
730
|
+
if (abb && Object.keys(columnSizingInfo).length === 0) {
|
|
731
|
+
// setColumnSizing({ "#": abb.getSize() })
|
|
732
|
+
table.setColumnSizing({
|
|
733
|
+
"#": abb.getSize()
|
|
734
|
+
});
|
|
735
|
+
requestAnimationFrame(() => {
|
|
736
|
+
columnVirtualizer.measure();
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
}
|
|
677
740
|
}
|
|
678
|
-
}, [table.getTotalSize(), windowSize.innerWidth,
|
|
741
|
+
}, [table.getTotalSize(), dataSource.length, windowSize.innerWidth, columnVirtualizer]);
|
|
679
742
|
// }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
|
|
680
743
|
|
|
744
|
+
// React.useEffect(() => {
|
|
745
|
+
|
|
746
|
+
// if (!tableContainerRef.current) {
|
|
747
|
+
// return
|
|
748
|
+
// }
|
|
749
|
+
|
|
750
|
+
// const containerWidth = tableContainerRef.current.offsetWidth
|
|
751
|
+
// const totalWidth = table.getTotalSize()
|
|
752
|
+
|
|
753
|
+
// if (totalWidth && totalWidth <= containerWidth) {
|
|
754
|
+
|
|
755
|
+
// return
|
|
756
|
+
|
|
757
|
+
// }
|
|
758
|
+
|
|
759
|
+
// if (columnSizingInfo.isResizingColumn === false) {
|
|
760
|
+
|
|
761
|
+
// const aa = updateColumnWidthsRecursive(propsColumns, columnSizing)
|
|
762
|
+
// setColumns(aa)
|
|
763
|
+
|
|
764
|
+
// }
|
|
765
|
+
|
|
766
|
+
// }, [columnSizing, columnSizingInfo, propsColumns, setColumns])
|
|
767
|
+
|
|
768
|
+
// React.useEffect(() => {
|
|
769
|
+
|
|
770
|
+
// // if (!containerRef.current || !tableContainerRef.current) {
|
|
771
|
+
// if (!tableContainerRef.current) {
|
|
772
|
+
// return
|
|
773
|
+
// }
|
|
774
|
+
|
|
775
|
+
// // const containerWidth = containerRef.current.offsetWidth - 1
|
|
776
|
+
// const containerWidth = tableContainerRef.current.offsetWidth - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0 )
|
|
777
|
+
|
|
778
|
+
// const totalWidth = table.getTotalSize()
|
|
779
|
+
|
|
780
|
+
// if (totalWidth && totalWidth < containerWidth) {
|
|
781
|
+
|
|
782
|
+
// const factor = containerWidth / totalWidth
|
|
783
|
+
|
|
784
|
+
// const visibleCols = table.getVisibleLeafColumns()
|
|
785
|
+
|
|
786
|
+
// const baseSizes = visibleCols.map(
|
|
787
|
+
// (col) => col.getSize() || col.columnDef.size || 150
|
|
788
|
+
// )
|
|
789
|
+
|
|
790
|
+
// const scaledSizes = baseSizes.map((size) => size * factor)
|
|
791
|
+
// const roundedSizes = scaledSizes.map((size) => Math.floor(size))
|
|
792
|
+
|
|
793
|
+
// let diff = containerWidth - roundedSizes.reduce((a, b) => a + b, 0)
|
|
794
|
+
|
|
795
|
+
// // phân bổ diff cho các cột từ trái qua phải
|
|
796
|
+
// for (let i = 0; diff > 0; i = (i + 1) % roundedSizes.length) {
|
|
797
|
+
// roundedSizes[i]++
|
|
798
|
+
// diff--
|
|
799
|
+
// }
|
|
800
|
+
|
|
801
|
+
// const aaa = visibleCols.reduce((acc, col, idx) => {
|
|
802
|
+
// acc[col.id] = roundedSizes[idx]
|
|
803
|
+
// return acc
|
|
804
|
+
// }, {} as Record<string, number>)
|
|
805
|
+
|
|
806
|
+
// const aa = updateColumnWidthsRecursive(propsColumns, aaa)
|
|
807
|
+
|
|
808
|
+
// // setColumns(aa)
|
|
809
|
+
|
|
810
|
+
// table.setColumnSizing(aaa)
|
|
811
|
+
|
|
812
|
+
// // setColumnSizing?.(aaa)
|
|
813
|
+
// }
|
|
814
|
+
|
|
815
|
+
// }, [windowSize.innerWidth, tableContainerRef, propsColumns, table.getState().columnSizing])
|
|
816
|
+
// // }, [windowSize.innerWidth, tableContainerRef, propsColumns, table.getState().columnSizing, dataSource.length])
|
|
817
|
+
// // }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
|
|
818
|
+
|
|
819
|
+
// React.useEffect(() => {
|
|
820
|
+
|
|
821
|
+
// if (!containerRef.current) return;
|
|
822
|
+
|
|
823
|
+
// const containerWidth = containerRef.current.offsetWidth - 1;
|
|
824
|
+
// const totalWidth = table.getTotalSize();
|
|
825
|
+
|
|
826
|
+
// if (totalWidth && totalWidth < containerWidth) {
|
|
827
|
+
|
|
828
|
+
// const factor = containerWidth / totalWidth;
|
|
829
|
+
|
|
830
|
+
// table.setColumnSizing(
|
|
831
|
+
// table.getVisibleLeafColumns().reduce((acc, col) => {
|
|
832
|
+
// acc[col.id] = ((col.getSize() || col.columnDef.size || 150) * factor);
|
|
833
|
+
// return acc;
|
|
834
|
+
// }, {} as Record<string, number>)
|
|
835
|
+
// );
|
|
836
|
+
// }
|
|
837
|
+
|
|
838
|
+
// }, [table.getTotalSize(), windowSize.innerWidth, table.getState().columnSizing])
|
|
839
|
+
// // }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
|
|
840
|
+
|
|
681
841
|
React.useEffect(() => {
|
|
682
842
|
const totalHeight = minHeight ?? height;
|
|
683
843
|
if (totalHeight) {
|
|
@@ -425,7 +425,8 @@ const EditableCell = props => {
|
|
|
425
425
|
newState,
|
|
426
426
|
option: {
|
|
427
427
|
value: val,
|
|
428
|
-
label: val
|
|
428
|
+
label: val,
|
|
429
|
+
searchTextAsValue: true
|
|
429
430
|
},
|
|
430
431
|
indexCol,
|
|
431
432
|
indexRow,
|
|
@@ -511,7 +512,8 @@ const EditableCell = props => {
|
|
|
511
512
|
newState,
|
|
512
513
|
option: {
|
|
513
514
|
value: val,
|
|
514
|
-
label: val
|
|
515
|
+
label: val,
|
|
516
|
+
searchTextAsValue: true
|
|
515
517
|
},
|
|
516
518
|
indexCol,
|
|
517
519
|
indexRow,
|
|
@@ -636,7 +638,8 @@ const EditableCell = props => {
|
|
|
636
638
|
newState,
|
|
637
639
|
option: {
|
|
638
640
|
value: val,
|
|
639
|
-
label: val
|
|
641
|
+
label: val,
|
|
642
|
+
searchTextAsValue: true
|
|
640
643
|
},
|
|
641
644
|
indexCol,
|
|
642
645
|
indexRow,
|
|
@@ -691,7 +691,8 @@ const TableBodyCellEdit = props => {
|
|
|
691
691
|
}
|
|
692
692
|
}
|
|
693
693
|
const handleMouseDownIndex = rowId => {
|
|
694
|
-
|
|
694
|
+
setIsSelecting?.(true);
|
|
695
|
+
const allColumns = table.getVisibleLeafColumns().filter(it => !nonActionColumn.includes(it.id));
|
|
695
696
|
const firstCOl = findFirst(allColumns);
|
|
696
697
|
const startCol = allColumns[0].id;
|
|
697
698
|
const endCol = allColumns[allColumns.length - 1].id;
|
|
@@ -717,6 +718,31 @@ const TableBodyCellEdit = props => {
|
|
|
717
718
|
colId: endCol
|
|
718
719
|
}));
|
|
719
720
|
};
|
|
721
|
+
const handleMouseEnterIndex = rowId => {
|
|
722
|
+
if (isSelecting) {
|
|
723
|
+
const allColumns = table.getVisibleLeafColumns().filter(it => !nonActionColumn.includes(it.id));
|
|
724
|
+
|
|
725
|
+
// const firstCOl = findFirst(allColumns)
|
|
726
|
+
|
|
727
|
+
// const startCol = allColumns[0].id
|
|
728
|
+
const endCol = allColumns[allColumns.length - 1].id;
|
|
729
|
+
|
|
730
|
+
// setStartCell?.({ rowId, colId: startCol });
|
|
731
|
+
setEndCell?.({
|
|
732
|
+
rowId,
|
|
733
|
+
colId: endCol
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
const handleMouseUpIndex = () => {
|
|
738
|
+
setIsSelecting?.(false);
|
|
739
|
+
// setIsPasting?.(false);
|
|
740
|
+
|
|
741
|
+
const selectState = getSelectedCellMatrix(table, startCell, endCell);
|
|
742
|
+
if (!isObjEqual(rangeState, selectState)) {
|
|
743
|
+
setRangeState?.(selectState);
|
|
744
|
+
}
|
|
745
|
+
};
|
|
720
746
|
if (cell.column.id === "#") {
|
|
721
747
|
return /*#__PURE__*/React.createElement("td", {
|
|
722
748
|
key: cell.id,
|
|
@@ -756,7 +782,16 @@ const TableBodyCellEdit = props => {
|
|
|
756
782
|
|
|
757
783
|
// reset?.()
|
|
758
784
|
}
|
|
759
|
-
}
|
|
785
|
+
},
|
|
786
|
+
onMouseEnter: () => {
|
|
787
|
+
handleMouseEnterIndex(cell.row.id);
|
|
788
|
+
},
|
|
789
|
+
onMouseUp: handleMouseUpIndex
|
|
790
|
+
// onMouseUp={() => {
|
|
791
|
+
|
|
792
|
+
// handleMouseUpIndex()
|
|
793
|
+
|
|
794
|
+
// }}
|
|
760
795
|
}, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/React.createElement("div", {
|
|
761
796
|
className: "ui-rc-table-row-expand-trigger",
|
|
762
797
|
style: {
|
|
@@ -214,8 +214,8 @@ const TableHeadCell = props => {
|
|
|
214
214
|
[`${prefix}-grid-cell-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header'),
|
|
215
215
|
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
216
216
|
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
217
|
-
[`${prefix}-grid-cell-text-center`]: originalColumn?.headerTextAlign === 'center',
|
|
218
|
-
[`${prefix}-grid-cell-text-right`]: originalColumn?.headerTextAlign === 'right'
|
|
217
|
+
[`${prefix}-grid-cell-text-center`]: (originalColumn?.headerTextAlign ?? originalColumn?.textAlign) === 'center',
|
|
218
|
+
[`${prefix}-grid-cell-text-right`]: (originalColumn?.headerTextAlign ?? originalColumn.textAlign) === 'right'
|
|
219
219
|
}),
|
|
220
220
|
colSpan: colSpan,
|
|
221
221
|
rowSpan: rowSpan,
|
|
@@ -17,7 +17,7 @@ import { arrayMove } from '@dnd-kit/sortable';
|
|
|
17
17
|
import React from 'react';
|
|
18
18
|
import TableContainer from "../TableContainer";
|
|
19
19
|
import { OperatorFeature } from "../features/operator";
|
|
20
|
-
import { convertFilters, convertToObjTrue, filterDataByColumns, getAllRowKey
|
|
20
|
+
import { convertFilters, convertToObjTrue, filterDataByColumns, getAllRowKey } from "../hook/utils";
|
|
21
21
|
import TableContainerEdit from "../TableContainerEdit";
|
|
22
22
|
const Grid = props => {
|
|
23
23
|
const {
|
|
@@ -141,22 +141,30 @@ const Grid = props => {
|
|
|
141
141
|
|
|
142
142
|
// debugTable: true
|
|
143
143
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
144
|
+
|
|
145
|
+
// React.useEffect(() => {
|
|
146
|
+
// if (columnHidden) {
|
|
147
|
+
// const abb = table.getVisibleLeafColumns()?.[0]
|
|
148
|
+
|
|
149
|
+
// if (abb && Object.keys(columnSizingInfo).length === 0
|
|
150
|
+
// ) {
|
|
151
|
+
// setColumnSizing({ "#": abb.getSize() })
|
|
152
|
+
// }
|
|
153
|
+
// }
|
|
154
|
+
|
|
155
|
+
// }, [columnHidden, columnSizingInfo])
|
|
156
|
+
|
|
157
|
+
// React.useEffect(() => {
|
|
158
|
+
// if (columnSizingInfo.isResizingColumn === false) {
|
|
159
|
+
|
|
160
|
+
// const aa = updateColumnWidthsRecursive(propsColumns, columnSizing)
|
|
161
|
+
|
|
162
|
+
// setColumns(aa)
|
|
163
|
+
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// }, [columnSizingInfo])
|
|
167
|
+
|
|
160
168
|
React.useEffect(() => {
|
|
161
169
|
// if (!manualUpdate) {
|
|
162
170
|
if (Object.keys(rowSelection) !== Object.keys(mergedSelectedKeys)) {
|
|
@@ -276,7 +284,11 @@ const Grid = props => {
|
|
|
276
284
|
setExpanded: setExpanded,
|
|
277
285
|
expanded: expanded,
|
|
278
286
|
infiniteScroll: infiniteScroll,
|
|
279
|
-
setMergedFilterKeys: setMergedFilterKeys
|
|
287
|
+
setMergedFilterKeys: setMergedFilterKeys,
|
|
288
|
+
setColumnSizing: setColumnSizing,
|
|
289
|
+
setColumns: setColumns,
|
|
290
|
+
columnSizing: columnSizing,
|
|
291
|
+
columnSizingInfo: columnSizingInfo
|
|
280
292
|
}))));
|
|
281
293
|
};
|
|
282
294
|
export default Grid;
|
|
@@ -300,6 +300,10 @@ export type IEditSelectSettings = {
|
|
|
300
300
|
fieldLabel?: string;
|
|
301
301
|
/** cho phép nhập giá trị - onBlur: giá trị search được set thành value **/
|
|
302
302
|
searchTextAsValue?: boolean;
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated Please use `allowSorter` instead.
|
|
305
|
+
* @since 1.7.25
|
|
306
|
+
*/
|
|
303
307
|
inputKey?: string;
|
|
304
308
|
filterKey?: string[];
|
|
305
309
|
selectMode?: SelectMode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Dispatch, SetStateAction } from "react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import type { ColumnDef, Table } from "@tanstack/react-table";
|
|
3
|
+
import type { ColumnDef, ColumnSizingInfoState, ColumnSizingState, Table } from "@tanstack/react-table";
|
|
4
4
|
import type { ColumnsTable, TableProps } from "./type";
|
|
5
5
|
type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
6
|
table: Table<T>;
|
|
@@ -32,6 +32,10 @@ type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
|
32
32
|
columnHidden: any;
|
|
33
33
|
isFullScreen: boolean;
|
|
34
34
|
setIsFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
35
|
+
setColumnSizing: Dispatch<SetStateAction<any>>;
|
|
36
|
+
setColumns: Dispatch<SetStateAction<any>>;
|
|
37
|
+
columnSizingInfo: ColumnSizingInfoState;
|
|
38
|
+
columnSizing: ColumnSizingState;
|
|
35
39
|
};
|
|
36
40
|
declare const TableContainerEdit: <RecordType extends object>(props: TableContainerProps<RecordType>) => React.JSX.Element;
|
|
37
41
|
export default TableContainerEdit;
|
|
@@ -124,7 +124,11 @@ const TableContainerEdit = props => {
|
|
|
124
124
|
showDefaultContext,
|
|
125
125
|
commandSettings,
|
|
126
126
|
isDataTree,
|
|
127
|
-
onCellClick
|
|
127
|
+
onCellClick,
|
|
128
|
+
// setColumnSizing,
|
|
129
|
+
setColumns,
|
|
130
|
+
columnSizing,
|
|
131
|
+
columnSizingInfo
|
|
128
132
|
} = props;
|
|
129
133
|
const containerRef = _react.default.useRef(null);
|
|
130
134
|
const bottomToolbarRef = _react.default.useRef(null);
|
|
@@ -359,7 +363,9 @@ const TableContainerEdit = props => {
|
|
|
359
363
|
return startCell && endCell ? (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId) : [];
|
|
360
364
|
}, [endCell, startCell, table]);
|
|
361
365
|
const copySelectionToClipboard = _react.default.useCallback(() => {
|
|
362
|
-
if (!startCell || !endCell)
|
|
366
|
+
if (!startCell || !endCell) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
363
369
|
|
|
364
370
|
// const allRows = table.getRowModel().rows;
|
|
365
371
|
const allRows = table.getRowModel().flatRows;
|
|
@@ -667,24 +673,178 @@ const TableContainerEdit = props => {
|
|
|
667
673
|
}, [dataSource, editingKey, id, onBlur]);
|
|
668
674
|
const columnSizingState = table.getState().columnSizing;
|
|
669
675
|
_react.default.useEffect(() => {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
676
|
+
|
|
677
|
+
// requestAnimationFrame(() => {
|
|
678
|
+
|
|
679
|
+
// columnVirtualizer.measure()
|
|
680
|
+
// })
|
|
673
681
|
}, [columnSizingState, columnVirtualizer]);
|
|
674
682
|
_react.default.useEffect(() => {
|
|
675
|
-
if (!
|
|
676
|
-
|
|
683
|
+
if (!tableContainerRef.current) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
const containerWidth = tableContainerRef.current.offsetWidth;
|
|
677
687
|
const totalWidth = table.getTotalSize();
|
|
678
|
-
if (totalWidth && totalWidth
|
|
688
|
+
if (totalWidth && totalWidth <= containerWidth) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
if (columnSizingInfo.isResizingColumn === false) {
|
|
692
|
+
const aa = (0, _utils.updateColumnWidthsRecursive)(propsColumns, columnSizing);
|
|
693
|
+
setColumns(aa);
|
|
694
|
+
requestAnimationFrame(() => {
|
|
695
|
+
columnVirtualizer.measure();
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}, [columnSizingInfo]);
|
|
699
|
+
_react.default.useEffect(() => {
|
|
700
|
+
// if (!containerRef.current || !tableContainerRef.current) {
|
|
701
|
+
if (!tableContainerRef.current) {
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// const containerWidth = containerRef.current.offsetWidth - 1
|
|
706
|
+
// const containerWidth = tableContainerRef.current.offsetWidth
|
|
707
|
+
const containerWidth = tableContainerRef.current.offsetWidth - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0);
|
|
708
|
+
const totalWidth = table.getTotalSize() - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0);
|
|
709
|
+
if (totalWidth && totalWidth > 0 && totalWidth < containerWidth) {
|
|
679
710
|
const factor = containerWidth / totalWidth;
|
|
680
|
-
table.
|
|
681
|
-
|
|
711
|
+
const visibleCols = table.getVisibleLeafColumns();
|
|
712
|
+
const baseSizes = visibleCols.map(col => col.getSize() || col.columnDef.size || 150);
|
|
713
|
+
const scaledSizes = baseSizes.map(size => size * factor);
|
|
714
|
+
const roundedSizes = scaledSizes.map(size => Math.floor(size));
|
|
715
|
+
let diff = containerWidth - roundedSizes.reduce((a, b) => a + b, 0);
|
|
716
|
+
|
|
717
|
+
// phân bổ diff cho các cột từ trái qua phải
|
|
718
|
+
for (let i = 0; diff > 0; i = (i + 1) % roundedSizes.length) {
|
|
719
|
+
roundedSizes[i]++;
|
|
720
|
+
diff--;
|
|
721
|
+
}
|
|
722
|
+
const aaa = visibleCols.reduce((acc, col, idx) => {
|
|
723
|
+
acc[col.id] = roundedSizes[idx];
|
|
682
724
|
return acc;
|
|
683
|
-
}, {})
|
|
725
|
+
}, {});
|
|
726
|
+
const aa = (0, _utils.updateColumnWidthsRecursive)(propsColumns, aaa);
|
|
727
|
+
setColumns(aa);
|
|
728
|
+
table.setColumnSizing(aaa);
|
|
729
|
+
requestAnimationFrame(() => {
|
|
730
|
+
columnVirtualizer.measure();
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
// setColumnSizing?.(aaa)
|
|
734
|
+
} else {
|
|
735
|
+
if (columnHidden) {
|
|
736
|
+
const abb = table.getVisibleLeafColumns()?.[0];
|
|
737
|
+
if (abb && Object.keys(columnSizingInfo).length === 0) {
|
|
738
|
+
// setColumnSizing({ "#": abb.getSize() })
|
|
739
|
+
table.setColumnSizing({
|
|
740
|
+
"#": abb.getSize()
|
|
741
|
+
});
|
|
742
|
+
requestAnimationFrame(() => {
|
|
743
|
+
columnVirtualizer.measure();
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
}
|
|
684
747
|
}
|
|
685
|
-
}, [table.getTotalSize(), windowSize.innerWidth,
|
|
748
|
+
}, [table.getTotalSize(), dataSource.length, windowSize.innerWidth, columnVirtualizer]);
|
|
686
749
|
// }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
|
|
687
750
|
|
|
751
|
+
// React.useEffect(() => {
|
|
752
|
+
|
|
753
|
+
// if (!tableContainerRef.current) {
|
|
754
|
+
// return
|
|
755
|
+
// }
|
|
756
|
+
|
|
757
|
+
// const containerWidth = tableContainerRef.current.offsetWidth
|
|
758
|
+
// const totalWidth = table.getTotalSize()
|
|
759
|
+
|
|
760
|
+
// if (totalWidth && totalWidth <= containerWidth) {
|
|
761
|
+
|
|
762
|
+
// return
|
|
763
|
+
|
|
764
|
+
// }
|
|
765
|
+
|
|
766
|
+
// if (columnSizingInfo.isResizingColumn === false) {
|
|
767
|
+
|
|
768
|
+
// const aa = updateColumnWidthsRecursive(propsColumns, columnSizing)
|
|
769
|
+
// setColumns(aa)
|
|
770
|
+
|
|
771
|
+
// }
|
|
772
|
+
|
|
773
|
+
// }, [columnSizing, columnSizingInfo, propsColumns, setColumns])
|
|
774
|
+
|
|
775
|
+
// React.useEffect(() => {
|
|
776
|
+
|
|
777
|
+
// // if (!containerRef.current || !tableContainerRef.current) {
|
|
778
|
+
// if (!tableContainerRef.current) {
|
|
779
|
+
// return
|
|
780
|
+
// }
|
|
781
|
+
|
|
782
|
+
// // const containerWidth = containerRef.current.offsetWidth - 1
|
|
783
|
+
// const containerWidth = tableContainerRef.current.offsetWidth - (tableContainerRef.current.scrollHeight > tableContainerRef.current.offsetHeight ? 15 : 0 )
|
|
784
|
+
|
|
785
|
+
// const totalWidth = table.getTotalSize()
|
|
786
|
+
|
|
787
|
+
// if (totalWidth && totalWidth < containerWidth) {
|
|
788
|
+
|
|
789
|
+
// const factor = containerWidth / totalWidth
|
|
790
|
+
|
|
791
|
+
// const visibleCols = table.getVisibleLeafColumns()
|
|
792
|
+
|
|
793
|
+
// const baseSizes = visibleCols.map(
|
|
794
|
+
// (col) => col.getSize() || col.columnDef.size || 150
|
|
795
|
+
// )
|
|
796
|
+
|
|
797
|
+
// const scaledSizes = baseSizes.map((size) => size * factor)
|
|
798
|
+
// const roundedSizes = scaledSizes.map((size) => Math.floor(size))
|
|
799
|
+
|
|
800
|
+
// let diff = containerWidth - roundedSizes.reduce((a, b) => a + b, 0)
|
|
801
|
+
|
|
802
|
+
// // phân bổ diff cho các cột từ trái qua phải
|
|
803
|
+
// for (let i = 0; diff > 0; i = (i + 1) % roundedSizes.length) {
|
|
804
|
+
// roundedSizes[i]++
|
|
805
|
+
// diff--
|
|
806
|
+
// }
|
|
807
|
+
|
|
808
|
+
// const aaa = visibleCols.reduce((acc, col, idx) => {
|
|
809
|
+
// acc[col.id] = roundedSizes[idx]
|
|
810
|
+
// return acc
|
|
811
|
+
// }, {} as Record<string, number>)
|
|
812
|
+
|
|
813
|
+
// const aa = updateColumnWidthsRecursive(propsColumns, aaa)
|
|
814
|
+
|
|
815
|
+
// // setColumns(aa)
|
|
816
|
+
|
|
817
|
+
// table.setColumnSizing(aaa)
|
|
818
|
+
|
|
819
|
+
// // setColumnSizing?.(aaa)
|
|
820
|
+
// }
|
|
821
|
+
|
|
822
|
+
// }, [windowSize.innerWidth, tableContainerRef, propsColumns, table.getState().columnSizing])
|
|
823
|
+
// // }, [windowSize.innerWidth, tableContainerRef, propsColumns, table.getState().columnSizing, dataSource.length])
|
|
824
|
+
// // }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
|
|
825
|
+
|
|
826
|
+
// React.useEffect(() => {
|
|
827
|
+
|
|
828
|
+
// if (!containerRef.current) return;
|
|
829
|
+
|
|
830
|
+
// const containerWidth = containerRef.current.offsetWidth - 1;
|
|
831
|
+
// const totalWidth = table.getTotalSize();
|
|
832
|
+
|
|
833
|
+
// if (totalWidth && totalWidth < containerWidth) {
|
|
834
|
+
|
|
835
|
+
// const factor = containerWidth / totalWidth;
|
|
836
|
+
|
|
837
|
+
// table.setColumnSizing(
|
|
838
|
+
// table.getVisibleLeafColumns().reduce((acc, col) => {
|
|
839
|
+
// acc[col.id] = ((col.getSize() || col.columnDef.size || 150) * factor);
|
|
840
|
+
// return acc;
|
|
841
|
+
// }, {} as Record<string, number>)
|
|
842
|
+
// );
|
|
843
|
+
// }
|
|
844
|
+
|
|
845
|
+
// }, [table.getTotalSize(), windowSize.innerWidth, table.getState().columnSizing])
|
|
846
|
+
// // }, [table.getState().columnSizing, table.getTotalSize(), containerRef])
|
|
847
|
+
|
|
688
848
|
_react.default.useEffect(() => {
|
|
689
849
|
const totalHeight = minHeight ?? height;
|
|
690
850
|
if (totalHeight) {
|
|
@@ -427,7 +427,8 @@ const EditableCell = props => {
|
|
|
427
427
|
newState,
|
|
428
428
|
option: {
|
|
429
429
|
value: val,
|
|
430
|
-
label: val
|
|
430
|
+
label: val,
|
|
431
|
+
searchTextAsValue: true
|
|
431
432
|
},
|
|
432
433
|
indexCol,
|
|
433
434
|
indexRow,
|
|
@@ -513,7 +514,8 @@ const EditableCell = props => {
|
|
|
513
514
|
newState,
|
|
514
515
|
option: {
|
|
515
516
|
value: val,
|
|
516
|
-
label: val
|
|
517
|
+
label: val,
|
|
518
|
+
searchTextAsValue: true
|
|
517
519
|
},
|
|
518
520
|
indexCol,
|
|
519
521
|
indexRow,
|
|
@@ -638,7 +640,8 @@ const EditableCell = props => {
|
|
|
638
640
|
newState,
|
|
639
641
|
option: {
|
|
640
642
|
value: val,
|
|
641
|
-
label: val
|
|
643
|
+
label: val,
|
|
644
|
+
searchTextAsValue: true
|
|
642
645
|
},
|
|
643
646
|
indexCol,
|
|
644
647
|
indexRow,
|
|
@@ -697,7 +697,8 @@ const TableBodyCellEdit = props => {
|
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
699
|
const handleMouseDownIndex = rowId => {
|
|
700
|
-
|
|
700
|
+
setIsSelecting?.(true);
|
|
701
|
+
const allColumns = table.getVisibleLeafColumns().filter(it => !_constant.nonActionColumn.includes(it.id));
|
|
701
702
|
const firstCOl = (0, _utils.findFirst)(allColumns);
|
|
702
703
|
const startCol = allColumns[0].id;
|
|
703
704
|
const endCol = allColumns[allColumns.length - 1].id;
|
|
@@ -723,6 +724,31 @@ const TableBodyCellEdit = props => {
|
|
|
723
724
|
colId: endCol
|
|
724
725
|
}));
|
|
725
726
|
};
|
|
727
|
+
const handleMouseEnterIndex = rowId => {
|
|
728
|
+
if (isSelecting) {
|
|
729
|
+
const allColumns = table.getVisibleLeafColumns().filter(it => !_constant.nonActionColumn.includes(it.id));
|
|
730
|
+
|
|
731
|
+
// const firstCOl = findFirst(allColumns)
|
|
732
|
+
|
|
733
|
+
// const startCol = allColumns[0].id
|
|
734
|
+
const endCol = allColumns[allColumns.length - 1].id;
|
|
735
|
+
|
|
736
|
+
// setStartCell?.({ rowId, colId: startCol });
|
|
737
|
+
setEndCell?.({
|
|
738
|
+
rowId,
|
|
739
|
+
colId: endCol
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
const handleMouseUpIndex = () => {
|
|
744
|
+
setIsSelecting?.(false);
|
|
745
|
+
// setIsPasting?.(false);
|
|
746
|
+
|
|
747
|
+
const selectState = (0, _utils.getSelectedCellMatrix)(table, startCell, endCell);
|
|
748
|
+
if (!(0, _utils.isObjEqual)(rangeState, selectState)) {
|
|
749
|
+
setRangeState?.(selectState);
|
|
750
|
+
}
|
|
751
|
+
};
|
|
726
752
|
if (cell.column.id === "#") {
|
|
727
753
|
return /*#__PURE__*/_react.default.createElement("td", {
|
|
728
754
|
key: cell.id,
|
|
@@ -762,7 +788,16 @@ const TableBodyCellEdit = props => {
|
|
|
762
788
|
|
|
763
789
|
// reset?.()
|
|
764
790
|
}
|
|
765
|
-
}
|
|
791
|
+
},
|
|
792
|
+
onMouseEnter: () => {
|
|
793
|
+
handleMouseEnterIndex(cell.row.id);
|
|
794
|
+
},
|
|
795
|
+
onMouseUp: handleMouseUpIndex
|
|
796
|
+
// onMouseUp={() => {
|
|
797
|
+
|
|
798
|
+
// handleMouseUpIndex()
|
|
799
|
+
|
|
800
|
+
// }}
|
|
766
801
|
}, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/_react.default.createElement("div", {
|
|
767
802
|
className: "ui-rc-table-row-expand-trigger",
|
|
768
803
|
style: {
|
|
@@ -223,8 +223,8 @@ const TableHeadCell = props => {
|
|
|
223
223
|
[`${prefix}-grid-cell-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header'),
|
|
224
224
|
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
225
225
|
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
226
|
-
[`${prefix}-grid-cell-text-center`]: originalColumn?.headerTextAlign === 'center',
|
|
227
|
-
[`${prefix}-grid-cell-text-right`]: originalColumn?.headerTextAlign === 'right'
|
|
226
|
+
[`${prefix}-grid-cell-text-center`]: (originalColumn?.headerTextAlign ?? originalColumn?.textAlign) === 'center',
|
|
227
|
+
[`${prefix}-grid-cell-text-right`]: (originalColumn?.headerTextAlign ?? originalColumn.textAlign) === 'right'
|
|
228
228
|
}),
|
|
229
229
|
colSpan: colSpan,
|
|
230
230
|
rowSpan: rowSpan,
|
|
@@ -143,22 +143,30 @@ const Grid = props => {
|
|
|
143
143
|
|
|
144
144
|
// debugTable: true
|
|
145
145
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
146
|
+
|
|
147
|
+
// React.useEffect(() => {
|
|
148
|
+
// if (columnHidden) {
|
|
149
|
+
// const abb = table.getVisibleLeafColumns()?.[0]
|
|
150
|
+
|
|
151
|
+
// if (abb && Object.keys(columnSizingInfo).length === 0
|
|
152
|
+
// ) {
|
|
153
|
+
// setColumnSizing({ "#": abb.getSize() })
|
|
154
|
+
// }
|
|
155
|
+
// }
|
|
156
|
+
|
|
157
|
+
// }, [columnHidden, columnSizingInfo])
|
|
158
|
+
|
|
159
|
+
// React.useEffect(() => {
|
|
160
|
+
// if (columnSizingInfo.isResizingColumn === false) {
|
|
161
|
+
|
|
162
|
+
// const aa = updateColumnWidthsRecursive(propsColumns, columnSizing)
|
|
163
|
+
|
|
164
|
+
// setColumns(aa)
|
|
165
|
+
|
|
166
|
+
// }
|
|
167
|
+
|
|
168
|
+
// }, [columnSizingInfo])
|
|
169
|
+
|
|
162
170
|
_react.default.useEffect(() => {
|
|
163
171
|
// if (!manualUpdate) {
|
|
164
172
|
if (Object.keys(rowSelection) !== Object.keys(mergedSelectedKeys)) {
|
|
@@ -278,7 +286,11 @@ const Grid = props => {
|
|
|
278
286
|
setExpanded: setExpanded,
|
|
279
287
|
expanded: expanded,
|
|
280
288
|
infiniteScroll: infiniteScroll,
|
|
281
|
-
setMergedFilterKeys: setMergedFilterKeys
|
|
289
|
+
setMergedFilterKeys: setMergedFilterKeys,
|
|
290
|
+
setColumnSizing: setColumnSizing,
|
|
291
|
+
setColumns: setColumns,
|
|
292
|
+
columnSizing: columnSizing,
|
|
293
|
+
columnSizingInfo: columnSizingInfo
|
|
282
294
|
}))));
|
|
283
295
|
};
|
|
284
296
|
var _default = exports.default = Grid;
|
|
@@ -300,6 +300,10 @@ export type IEditSelectSettings = {
|
|
|
300
300
|
fieldLabel?: string;
|
|
301
301
|
/** cho phép nhập giá trị - onBlur: giá trị search được set thành value **/
|
|
302
302
|
searchTextAsValue?: boolean;
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated Please use `allowSorter` instead.
|
|
305
|
+
* @since 1.7.25
|
|
306
|
+
*/
|
|
303
307
|
inputKey?: string;
|
|
304
308
|
filterKey?: string[];
|
|
305
309
|
selectMode?: SelectMode;
|