es-grid-template 1.7.27 → 1.7.29
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/InternalTable.js +31 -36
- package/es/grid-component/TempTable.d.ts +4 -0
- package/es/grid-component/TempTable.js +21 -0
- package/es/grid-component/hooks/columns/index.js +3 -1
- package/es/grid-component/index.d.ts +2 -2
- package/es/grid-component/index.js +6 -4
- package/es/grid-component/styles.scss +0 -1
- package/es/grid-component/table/GridEdit.js +112 -96
- package/es/grid-component/type.d.ts +7 -1
- package/es/table-component/InternalTable.js +100 -127
- package/es/table-component/TableContainer.d.ts +6 -1
- package/es/table-component/TableContainer.js +82 -74
- package/es/table-component/TableContainerEdit.d.ts +4 -0
- package/es/table-component/TableContainerEdit.js +370 -85
- package/es/table-component/body/TableBody.d.ts +2 -8
- package/es/table-component/body/TableBody.js +1 -0
- package/es/table-component/body/TableBodyCell.d.ts +1 -1
- package/es/table-component/body/TableBodyCell.js +25 -12
- package/es/table-component/body/TableBodyCellEdit.d.ts +1 -1
- package/es/table-component/body/TableBodyCellEdit.js +44 -19
- package/es/table-component/body/TableBodyRow.d.ts +3 -3
- package/es/table-component/body/TableBodyRow.js +4 -6
- package/es/table-component/footer/TableFooter.d.ts +2 -8
- package/es/table-component/footer/TableFooter.js +14 -13
- package/es/table-component/footer/TableFooterCell.d.ts +3 -6
- package/es/table-component/footer/TableFooterCell.js +12 -10
- package/es/table-component/footer/TableFooterRow.d.ts +2 -8
- package/es/table-component/footer/TableFooterRow.js +23 -48
- package/es/table-component/header/TableHead.d.ts +4 -3
- package/es/table-component/header/TableHead.js +3 -61
- package/es/table-component/header/TableHeadCell.d.ts +0 -3
- package/es/table-component/header/TableHeadCell.js +11 -9
- package/es/table-component/header/TableHeadRow.d.ts +6 -6
- package/es/table-component/header/TableHeadRow.js +10 -32
- package/es/table-component/hook/utils.js +1 -1
- package/es/table-component/style.scss +26 -2
- package/es/table-component/table/Grid.d.ts +1 -0
- package/es/table-component/table/Grid.js +12 -6
- package/es/table-component/table/TableWrapper.d.ts +33 -0
- package/es/table-component/table/TableWrapper.js +245 -0
- package/es/table-component/type.d.ts +5 -4
- package/es/table-component/useContext.d.ts +4 -0
- package/es/table-component/useContext.js +4 -0
- package/lib/grid-component/InternalTable.js +30 -35
- package/lib/grid-component/TempTable.d.ts +4 -0
- package/lib/grid-component/TempTable.js +30 -0
- package/lib/grid-component/hooks/columns/index.js +3 -1
- package/lib/grid-component/index.d.ts +2 -2
- package/lib/grid-component/index.js +5 -3
- package/lib/grid-component/styles.scss +0 -1
- package/lib/grid-component/table/GridEdit.js +112 -96
- package/lib/grid-component/type.d.ts +7 -1
- package/lib/table-component/InternalTable.js +101 -127
- package/lib/table-component/TableContainer.d.ts +6 -1
- package/lib/table-component/TableContainer.js +84 -74
- package/lib/table-component/TableContainerEdit.d.ts +4 -0
- package/lib/table-component/TableContainerEdit.js +366 -83
- package/lib/table-component/body/TableBody.d.ts +2 -8
- package/lib/table-component/body/TableBody.js +2 -0
- package/lib/table-component/body/TableBodyCell.d.ts +1 -1
- package/lib/table-component/body/TableBodyCell.js +25 -12
- package/lib/table-component/body/TableBodyCellEdit.d.ts +1 -1
- package/lib/table-component/body/TableBodyCellEdit.js +43 -19
- package/lib/table-component/body/TableBodyRow.d.ts +3 -3
- package/lib/table-component/body/TableBodyRow.js +4 -6
- package/lib/table-component/footer/TableFooter.d.ts +2 -8
- package/lib/table-component/footer/TableFooter.js +15 -13
- package/lib/table-component/footer/TableFooterCell.d.ts +3 -6
- package/lib/table-component/footer/TableFooterCell.js +13 -10
- package/lib/table-component/footer/TableFooterRow.d.ts +2 -8
- package/lib/table-component/footer/TableFooterRow.js +23 -48
- package/lib/table-component/header/TableHead.d.ts +4 -3
- package/lib/table-component/header/TableHead.js +3 -61
- package/lib/table-component/header/TableHeadCell.d.ts +0 -3
- package/lib/table-component/header/TableHeadCell.js +11 -8
- package/lib/table-component/header/TableHeadRow.d.ts +6 -6
- package/lib/table-component/header/TableHeadRow.js +10 -32
- package/lib/table-component/hook/utils.js +1 -1
- package/lib/table-component/style.scss +26 -2
- package/lib/table-component/table/Grid.d.ts +1 -0
- package/lib/table-component/table/Grid.js +12 -6
- package/lib/table-component/table/TableWrapper.d.ts +33 -0
- package/lib/table-component/table/TableWrapper.js +254 -0
- package/lib/table-component/type.d.ts +5 -4
- package/lib/table-component/useContext.d.ts +4 -0
- package/lib/table-component/useContext.js +4 -0
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { flexRender } from '@tanstack/react-table';
|
|
4
4
|
import React, { useContext } from 'react';
|
|
5
5
|
// import { CSS } from '@dnd-kit/utilities'
|
|
6
|
-
|
|
6
|
+
// import type { Virtualizer } from '@tanstack/react-virtual'
|
|
7
7
|
import { Button, Space } from 'antd';
|
|
8
8
|
import { ArrowDown, ArrowUp, FilterFill, SortCancel } from 'becoxy-icons';
|
|
9
9
|
import classNames from 'classnames';
|
|
@@ -23,8 +23,8 @@ const TableHeadCell = props => {
|
|
|
23
23
|
getPopupContainer,
|
|
24
24
|
table,
|
|
25
25
|
t,
|
|
26
|
-
columnVirtualizer,
|
|
27
|
-
rowHeaderVirtualizer,
|
|
26
|
+
// columnVirtualizer,
|
|
27
|
+
// rowHeaderVirtualizer,
|
|
28
28
|
colSpan,
|
|
29
29
|
rowSpan
|
|
30
30
|
} = props;
|
|
@@ -218,6 +218,7 @@ const TableHeadCell = props => {
|
|
|
218
218
|
style: {
|
|
219
219
|
// display: 'flex',
|
|
220
220
|
width: header.getSize(),
|
|
221
|
+
// width: 'inherit',
|
|
221
222
|
minWidth: header.getSize(),
|
|
222
223
|
maxWidth: header.getSize(),
|
|
223
224
|
...getCommonPinningStyles(header.column),
|
|
@@ -300,12 +301,13 @@ const TableHeadCell = props => {
|
|
|
300
301
|
onDoubleClick: () => header.column.resetSize(),
|
|
301
302
|
onMouseDown: header.getResizeHandler(),
|
|
302
303
|
onTouchStart: header.getResizeHandler(),
|
|
303
|
-
onMouseUp: () => {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
},
|
|
304
|
+
// onMouseUp: () => {
|
|
305
|
+
// requestAnimationFrame(() => {
|
|
306
|
+
// columnVirtualizer.measure()
|
|
307
|
+
// rowHeaderVirtualizer.measure()
|
|
308
|
+
// })
|
|
309
|
+
// },
|
|
310
|
+
|
|
309
311
|
className: `resizer ${header.column.getIsResizing() ? 'isResizing' : ''}`
|
|
310
312
|
}));
|
|
311
313
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
1
|
+
import type { Column } from '@tanstack/react-table';
|
|
2
|
+
import { type HeaderGroup, type Table } from '@tanstack/react-table';
|
|
3
3
|
import React from 'react';
|
|
4
|
+
import type { Virtualizer } from '@tanstack/react-virtual';
|
|
4
5
|
interface TableHeadRowProps<T> {
|
|
5
|
-
columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
|
6
|
-
rowHeaderVirtualizer: Virtualizer<HTMLDivElement, HTMLTableRowElement>;
|
|
7
6
|
headerGroup: HeaderGroup<T>;
|
|
7
|
+
table: Table<T>;
|
|
8
|
+
columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
|
8
9
|
virtualPaddingLeft: number | undefined;
|
|
9
10
|
virtualPaddingRight: number | undefined;
|
|
10
|
-
table: Table<T>;
|
|
11
11
|
fixedLeftColumns: Column<T, unknown>[];
|
|
12
12
|
fixedRightColumns: Column<T, unknown>[];
|
|
13
13
|
}
|
|
14
|
-
declare const TableHeadRow: ({ table,
|
|
14
|
+
declare const TableHeadRow: ({ table, headerGroup, }: TableHeadRowProps<any>) => React.JSX.Element;
|
|
15
15
|
export default TableHeadRow;
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { horizontalListSortingStrategy, SortableContext } from '@dnd-kit/sortable';
|
|
2
|
-
import {
|
|
2
|
+
// import type { Virtualizer } from '@tanstack/react-virtual'
|
|
3
3
|
// import type { Person } from "../../tanstack-table/makeData"
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { TableContext } from "../useContext";
|
|
6
6
|
import TableHeadCell from "./TableHeadCell";
|
|
7
|
-
import { getCommonPinningStyles } from
|
|
7
|
+
// import { getCommonPinningStyles } from '../hook/utils'
|
|
8
|
+
|
|
8
9
|
const TableHeadRow = ({
|
|
9
10
|
table,
|
|
10
|
-
columnVirtualizer,
|
|
11
|
-
rowHeaderVirtualizer,
|
|
12
11
|
headerGroup
|
|
12
|
+
|
|
13
|
+
// columnVirtualizer,
|
|
13
14
|
// virtualPaddingLeft,
|
|
14
15
|
// virtualPaddingRight,
|
|
15
16
|
// fixedLeftColumns,
|
|
16
|
-
// fixedRightColumns
|
|
17
|
-
// rowHeaderVirtual
|
|
17
|
+
// fixedRightColumns
|
|
18
18
|
}) => {
|
|
19
19
|
const {
|
|
20
20
|
prefix
|
|
21
21
|
} = React.useContext(TableContext);
|
|
22
22
|
|
|
23
23
|
// const virtualColumns = columnVirtualizer.getVirtualItems()
|
|
24
|
-
// const virtualColumns = columnVirtualizer.measurementsCache
|
|
25
24
|
|
|
26
25
|
const columnOrder = table.getState().columnOrder;
|
|
27
26
|
return /*#__PURE__*/React.createElement("tr", {
|
|
@@ -54,34 +53,13 @@ const TableHeadRow = ({
|
|
|
54
53
|
return /*#__PURE__*/React.createElement(TableHeadCell, {
|
|
55
54
|
key: header.id,
|
|
56
55
|
header: header,
|
|
57
|
-
table: table
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
table: table
|
|
57
|
+
// columnVirtualizer={columnVirtualizer}
|
|
58
|
+
// rowHeaderVirtualizer={rowHeaderVirtualizer}
|
|
59
|
+
,
|
|
60
60
|
colSpan: header.colSpan,
|
|
61
61
|
rowSpan: rowSpan
|
|
62
62
|
});
|
|
63
|
-
return /*#__PURE__*/React.createElement("th", {
|
|
64
|
-
key: header.id,
|
|
65
|
-
colSpan: header.colSpan,
|
|
66
|
-
rowSpan: rowSpan,
|
|
67
|
-
style: {
|
|
68
|
-
padding: '12px',
|
|
69
|
-
textAlign: 'left',
|
|
70
|
-
fontSize: '0.75rem',
|
|
71
|
-
fontWeight: 'medium',
|
|
72
|
-
color: '#6b7280',
|
|
73
|
-
textTransform: 'uppercase',
|
|
74
|
-
letterSpacing: '0.05em',
|
|
75
|
-
// backgroundColor: '#f9fafb',
|
|
76
|
-
// border: '1px solid #e5e7eb',
|
|
77
|
-
borderLeft: 0,
|
|
78
|
-
width: header.getSize(),
|
|
79
|
-
minWidth: header.getSize(),
|
|
80
|
-
maxWidth: header.getSize(),
|
|
81
|
-
// overflow: 'hidden',
|
|
82
|
-
...getCommonPinningStyles(header.column)
|
|
83
|
-
}
|
|
84
|
-
}, flexRender(header.column.columnDef.header, header.getContext()));
|
|
85
63
|
})));
|
|
86
64
|
};
|
|
87
65
|
export default TableHeadRow;
|
|
@@ -42,7 +42,7 @@ export const getCommonPinningStyles = column => {
|
|
|
42
42
|
// opacity: isPinned ? 0.5 : 1,
|
|
43
43
|
opacity: 1,
|
|
44
44
|
position: isPinned ? "sticky" : "relative",
|
|
45
|
-
width: column.getSize(),
|
|
45
|
+
// width: column.getSize(),
|
|
46
46
|
zIndex: isPinned ? 2 : 0
|
|
47
47
|
// border: '1px solid #e5e7eb',
|
|
48
48
|
// borderTop: 0,
|
|
@@ -53,16 +53,17 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
|
|
|
53
53
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
&.#{$prefix}-grid-cell-text-right {
|
|
57
57
|
justify-content: flex-end;
|
|
58
58
|
text-align: right;
|
|
59
59
|
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
&.#{$prefix}-grid-cell-ellipsis {
|
|
65
65
|
|
|
66
|
+
|
|
66
67
|
.ui-rc_cell-content {
|
|
67
68
|
width: 100%;
|
|
68
69
|
overflow: hidden;
|
|
@@ -98,6 +99,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
|
|
|
98
99
|
|
|
99
100
|
}
|
|
100
101
|
|
|
102
|
+
|
|
101
103
|
|
|
102
104
|
&.#{$prefix}-grid-cell-wrap {
|
|
103
105
|
white-space: normal;
|
|
@@ -122,6 +124,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
|
|
|
122
124
|
|
|
123
125
|
|
|
124
126
|
.#{$prefix}-grid-thead {
|
|
127
|
+
background-color: #ffffff;
|
|
125
128
|
|
|
126
129
|
.#{$prefix}-grid-cell {
|
|
127
130
|
|
|
@@ -258,6 +261,16 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
|
|
|
258
261
|
|
|
259
262
|
background-color: $body-color;
|
|
260
263
|
|
|
264
|
+
&.#{$prefix}-grid-cell-ellipsis:not(:has(>.ui-rc_cell-content)) {
|
|
265
|
+
overflow: hidden;
|
|
266
|
+
white-space: nowrap;
|
|
267
|
+
text-overflow: ellipsis;
|
|
268
|
+
word-break: keep-all;
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
261
274
|
&.cell-editable {
|
|
262
275
|
|
|
263
276
|
// padding: 0;
|
|
@@ -525,6 +538,7 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
|
|
|
525
538
|
}
|
|
526
539
|
|
|
527
540
|
.#{$prefix}-grid-tfoot {
|
|
541
|
+
background-color: rgb(250, 250, 250);
|
|
528
542
|
.#{$prefix}-grid-cell {
|
|
529
543
|
background-color: $body-color;
|
|
530
544
|
border-inline-end: 1px solid $tableBorderColor;
|
|
@@ -775,6 +789,16 @@ $fontFamily: "Montserrat", Helvetica, Arial, serif !default;
|
|
|
775
789
|
}
|
|
776
790
|
}
|
|
777
791
|
|
|
792
|
+
.spinner-loading {
|
|
793
|
+
position: absolute;
|
|
794
|
+
top: 0;
|
|
795
|
+
left: 0;
|
|
796
|
+
width: 100%;
|
|
797
|
+
height: 100%;
|
|
798
|
+
z-index: 4;
|
|
799
|
+
background-color: #ffffff80;
|
|
800
|
+
}
|
|
801
|
+
|
|
778
802
|
|
|
779
803
|
|
|
780
804
|
}
|
|
@@ -21,6 +21,7 @@ type Props<T> = Omit<TableProps<T>, 'columns'> & {
|
|
|
21
21
|
triggerSorter: Dispatch<SetStateAction<Sorter[]>>;
|
|
22
22
|
onContextMenu?: (data: T) => (event: any) => void;
|
|
23
23
|
triggerChangeColumns?: (args: any, keys: any) => void;
|
|
24
|
+
windowSize: any;
|
|
24
25
|
};
|
|
25
26
|
declare const Grid: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
26
27
|
export default Grid;
|
|
@@ -42,9 +42,12 @@ const Grid = props => {
|
|
|
42
42
|
onSorter,
|
|
43
43
|
onFilter,
|
|
44
44
|
groupColumns,
|
|
45
|
-
height
|
|
45
|
+
// height= 700,
|
|
46
|
+
height,
|
|
47
|
+
minHeight,
|
|
46
48
|
editAble,
|
|
47
49
|
triggerChangeColumns,
|
|
50
|
+
infiniteScroll,
|
|
48
51
|
...rest
|
|
49
52
|
} = props;
|
|
50
53
|
const [columnResizeMode] = React.useState('onChange');
|
|
@@ -78,7 +81,8 @@ const Grid = props => {
|
|
|
78
81
|
expanded,
|
|
79
82
|
columnPinning,
|
|
80
83
|
columnVisibility: columnHidden,
|
|
81
|
-
pagination: pagination ? paginationState : undefined,
|
|
84
|
+
pagination: pagination && !infiniteScroll ? paginationState : undefined,
|
|
85
|
+
// pagination: pagination ? paginationState : undefined,
|
|
82
86
|
grouping,
|
|
83
87
|
columnSizing,
|
|
84
88
|
columnOrder,
|
|
@@ -120,7 +124,7 @@ const Grid = props => {
|
|
|
120
124
|
getGroupedRowModel: getGroupedRowModel(),
|
|
121
125
|
// onExpandedChange: setExpanded,
|
|
122
126
|
getExpandedRowModel: getExpandedRowModel(),
|
|
123
|
-
getPaginationRowModel: pagination ? getPaginationRowModel() : undefined,
|
|
127
|
+
getPaginationRowModel: pagination && !infiniteScroll ? getPaginationRowModel() : undefined,
|
|
124
128
|
onPaginationChange: setPagination
|
|
125
129
|
|
|
126
130
|
// onColumnVisibilityChange: setColumnVisibility,
|
|
@@ -204,7 +208,7 @@ const Grid = props => {
|
|
|
204
208
|
return /*#__PURE__*/React.createElement("div", {
|
|
205
209
|
className: `${prefix}-grid`,
|
|
206
210
|
style: {
|
|
207
|
-
|
|
211
|
+
minHeight: minHeight ?? undefined,
|
|
208
212
|
maxHeight: height ?? undefined
|
|
209
213
|
}
|
|
210
214
|
}, /*#__PURE__*/React.createElement(DndContext, {
|
|
@@ -223,14 +227,16 @@ const Grid = props => {
|
|
|
223
227
|
setIsSelectionChange: setIsSelectionChange,
|
|
224
228
|
setSorterChange: setSorterChange,
|
|
225
229
|
setFilterChange: setFilterChange,
|
|
226
|
-
height: height,
|
|
230
|
+
height: minHeight ?? height ?? 700,
|
|
231
|
+
minHeight: minHeight,
|
|
227
232
|
pagination: pagination,
|
|
228
233
|
columns: columns,
|
|
229
234
|
propsColumns: propsColumns,
|
|
230
235
|
triggerChangeColumns: triggerChangeColumns,
|
|
231
236
|
columnHidden: columnHidden,
|
|
232
237
|
setExpanded: setExpanded,
|
|
233
|
-
expanded: expanded
|
|
238
|
+
expanded: expanded,
|
|
239
|
+
infiniteScroll: infiniteScroll
|
|
234
240
|
}))));
|
|
235
241
|
};
|
|
236
242
|
export default Grid;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Table } from "@tanstack/react-table";
|
|
2
|
+
import type { CommandClick, ContextInfo, ContextMenuItem, PaginationConfig } from "../type";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import type { Virtualizer } from "@tanstack/react-virtual";
|
|
5
|
+
import type { Column } from "@tanstack/react-table";
|
|
6
|
+
type Props<T> = {
|
|
7
|
+
prefix: string;
|
|
8
|
+
id: string;
|
|
9
|
+
tableContainerRef: React.RefObject<HTMLDivElement>;
|
|
10
|
+
height: number;
|
|
11
|
+
minHeight?: number;
|
|
12
|
+
table: Table<T>;
|
|
13
|
+
summary?: boolean;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
commandClick?: (args: Omit<CommandClick<T>, 'rows'>) => void;
|
|
16
|
+
editAble?: boolean;
|
|
17
|
+
contextMenuItems?: ContextMenuItem[];
|
|
18
|
+
showEmptyText?: boolean;
|
|
19
|
+
contextMenuClick?: any;
|
|
20
|
+
contextMenuOpen?: (args: Omit<ContextInfo<T>, 'item'>) => void;
|
|
21
|
+
contextMenuHidden?: string[] | ((args?: Omit<ContextInfo<T>, 'item' | 'event'>) => string[]);
|
|
22
|
+
next?: () => void;
|
|
23
|
+
dataSource: T[];
|
|
24
|
+
pagination?: false | PaginationConfig;
|
|
25
|
+
infiniteScroll?: boolean;
|
|
26
|
+
columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
|
27
|
+
virtualPaddingLeft: number | undefined;
|
|
28
|
+
virtualPaddingRight: number | undefined;
|
|
29
|
+
fixedLeftColumns: Column<T, unknown>[];
|
|
30
|
+
fixedRightColumns: Column<T, unknown>[];
|
|
31
|
+
};
|
|
32
|
+
declare const TableWrapper: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
33
|
+
export default TableWrapper;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import classNames from "classnames";
|
|
2
|
+
import TableHead from "../header/TableHead";
|
|
3
|
+
import TableBody from "../body/TableBody";
|
|
4
|
+
import TableFooter from "../footer/TableFooter";
|
|
5
|
+
import ComponentSpinner from "../../grid-component/LoadingSpinner";
|
|
6
|
+
import { Tooltip } from "react-tooltip";
|
|
7
|
+
import ContextMenu from "../ContextMenu";
|
|
8
|
+
import React, { useContext } from "react";
|
|
9
|
+
import { TableContext } from "../useContext";
|
|
10
|
+
const TableWrapper = props => {
|
|
11
|
+
const {
|
|
12
|
+
id,
|
|
13
|
+
prefix,
|
|
14
|
+
tableContainerRef,
|
|
15
|
+
height,
|
|
16
|
+
minHeight,
|
|
17
|
+
summary,
|
|
18
|
+
table,
|
|
19
|
+
loading,
|
|
20
|
+
commandClick,
|
|
21
|
+
editAble,
|
|
22
|
+
contextMenuItems: propContextMenuItems,
|
|
23
|
+
contextMenuHidden,
|
|
24
|
+
showEmptyText,
|
|
25
|
+
contextMenuClick,
|
|
26
|
+
contextMenuOpen,
|
|
27
|
+
next,
|
|
28
|
+
dataSource,
|
|
29
|
+
pagination,
|
|
30
|
+
infiniteScroll,
|
|
31
|
+
columnVirtualizer,
|
|
32
|
+
fixedLeftColumns,
|
|
33
|
+
fixedRightColumns,
|
|
34
|
+
virtualPaddingLeft,
|
|
35
|
+
virtualPaddingRight
|
|
36
|
+
} = props;
|
|
37
|
+
const menuRef = React.useRef(null);
|
|
38
|
+
const loadingRef = React.useRef(false);
|
|
39
|
+
const hasMoreRef = React.useRef(true);
|
|
40
|
+
const {
|
|
41
|
+
windowSize
|
|
42
|
+
} = useContext(TableContext);
|
|
43
|
+
const {
|
|
44
|
+
currentPage,
|
|
45
|
+
pageSize,
|
|
46
|
+
total
|
|
47
|
+
} = pagination ?? {};
|
|
48
|
+
const [menuVisible, setMenuVisible] = React.useState(false);
|
|
49
|
+
const [selectedRowData, setSelectedRowData] = React.useState(null);
|
|
50
|
+
const [position, setPosition] = React.useState({
|
|
51
|
+
x: 0,
|
|
52
|
+
y: 0,
|
|
53
|
+
viewportWidth: windowSize.innerWidth,
|
|
54
|
+
viewportHeight: windowSize.innerHeight
|
|
55
|
+
});
|
|
56
|
+
const contextMenuItems = React.useMemo(() => {
|
|
57
|
+
if (typeof contextMenuHidden === 'function' && propContextMenuItems && selectedRowData) {
|
|
58
|
+
const hiddenItems = contextMenuHidden({
|
|
59
|
+
rowInfo: {
|
|
60
|
+
rowData: selectedRowData
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return propContextMenuItems.filter(item => !hiddenItems.includes(item?.key));
|
|
64
|
+
}
|
|
65
|
+
if (contextMenuHidden && typeof contextMenuHidden !== 'function' && propContextMenuItems) {
|
|
66
|
+
return propContextMenuItems.filter(item => !contextMenuHidden.includes(item?.key));
|
|
67
|
+
}
|
|
68
|
+
return propContextMenuItems;
|
|
69
|
+
}, [propContextMenuItems, contextMenuHidden, selectedRowData]);
|
|
70
|
+
const loadData = page => {
|
|
71
|
+
if (!hasMoreRef.current || loadingRef.current || loading) return;
|
|
72
|
+
loadingRef.current = true;
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
next?.();
|
|
75
|
+
if (page * pageSize >= total) {
|
|
76
|
+
hasMoreRef.current = false;
|
|
77
|
+
}
|
|
78
|
+
loadingRef.current = false;
|
|
79
|
+
}, 10);
|
|
80
|
+
};
|
|
81
|
+
const handleNext = () => {
|
|
82
|
+
loadData(currentPage + 1);
|
|
83
|
+
};
|
|
84
|
+
const handleScroll = e => {
|
|
85
|
+
if (infiniteScroll) {
|
|
86
|
+
if (loadingRef.current || loading || dataSource?.length === 0) {
|
|
87
|
+
e.stopPropagation();
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const {
|
|
92
|
+
scrollHeight: tbScrollHeight,
|
|
93
|
+
scrollTop,
|
|
94
|
+
clientHeight
|
|
95
|
+
} = e.currentTarget;
|
|
96
|
+
const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
|
|
97
|
+
if (isEnd && !loadingRef.current && hasMoreRef.current && dataSource?.length > 0) {
|
|
98
|
+
handleNext();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (e.target.scrollLeft >= 0 && e.target.scrollLeft + e.target.clientWidth < e.target.scrollWidth) {
|
|
102
|
+
e.target.classList.add('ui-rc-table-ping-right');
|
|
103
|
+
} else {
|
|
104
|
+
e.target.classList.remove('ui-rc-table-ping-right');
|
|
105
|
+
}
|
|
106
|
+
if ((e.target.scrollLeft ?? 0) > 0) {
|
|
107
|
+
e.target.classList.add('ui-rc-table-ping-left');
|
|
108
|
+
} else {
|
|
109
|
+
e.target.classList.remove('ui-rc-table-ping-left');
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const onContextMenu = data => event => {
|
|
113
|
+
event.preventDefault(); // Ngăn chặn menu mặc định của trình duyệt
|
|
114
|
+
|
|
115
|
+
setSelectedRowData(data);
|
|
116
|
+
contextMenuOpen?.({
|
|
117
|
+
rowInfo: {
|
|
118
|
+
rowData: data
|
|
119
|
+
},
|
|
120
|
+
event
|
|
121
|
+
});
|
|
122
|
+
setMenuVisible(true);
|
|
123
|
+
|
|
124
|
+
// Đợi DOM cập nhật và lấy kích thước menu
|
|
125
|
+
setTimeout(() => {
|
|
126
|
+
const menuElement = menuRef.current; // Lấy menu từ DOM
|
|
127
|
+
const menuWidth = menuElement?.offsetWidth || 200; // Mặc định 200px nếu chưa render
|
|
128
|
+
const menuHeight = menuElement?.offsetHeight; // Mặc định 450px nếu chưa render
|
|
129
|
+
|
|
130
|
+
// Điều chỉnh vị trí menu
|
|
131
|
+
let x = event.clientX;
|
|
132
|
+
let y = event.clientY;
|
|
133
|
+
if (x + menuWidth > windowSize.innerWidth) {
|
|
134
|
+
x = x - menuWidth - 10; // Cách cạnh phải 10px
|
|
135
|
+
}
|
|
136
|
+
if (y + menuHeight > windowSize.innerHeight) {
|
|
137
|
+
if (y < menuHeight) {
|
|
138
|
+
y = 10;
|
|
139
|
+
} else {
|
|
140
|
+
y = y - 10 - menuHeight; // Cách cạnh dưới 10px
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
setPosition(prevState => ({
|
|
144
|
+
...prevState,
|
|
145
|
+
x,
|
|
146
|
+
y
|
|
147
|
+
}));
|
|
148
|
+
}, 100);
|
|
149
|
+
if (!menuVisible) {
|
|
150
|
+
document.addEventListener(`click`, function onClickOutside(e) {
|
|
151
|
+
const element = e.target;
|
|
152
|
+
const menuContainer = document.querySelector('.popup-context-menu');
|
|
153
|
+
const isInsideContainer = element.closest('.popup-context-menu') && menuContainer;
|
|
154
|
+
if (isInsideContainer) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
setMenuVisible(false);
|
|
158
|
+
setPosition(prevState => ({
|
|
159
|
+
...prevState,
|
|
160
|
+
x: undefined,
|
|
161
|
+
y: undefined
|
|
162
|
+
}));
|
|
163
|
+
document.removeEventListener(`click`, onClickOutside);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
168
|
+
style: {
|
|
169
|
+
position: 'relative'
|
|
170
|
+
}
|
|
171
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
172
|
+
className: classNames(`${prefix}-grid-container`, {
|
|
173
|
+
'ui-rc-table-ping-right': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) >= 0 && (tableContainerRef.current?.scrollLeft ?? 0) + (tableContainerRef.current?.clientWidth ?? 0) < (tableContainerRef.current?.scrollWidth ?? 0),
|
|
174
|
+
'ui-rc-table-ping-left': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) > 0
|
|
175
|
+
}),
|
|
176
|
+
id: id,
|
|
177
|
+
ref: tableContainerRef,
|
|
178
|
+
style: {
|
|
179
|
+
overflow: 'auto',
|
|
180
|
+
//our scrollable table container
|
|
181
|
+
position: 'relative',
|
|
182
|
+
//needed for sticky header
|
|
183
|
+
// height: tableHeight ?? '500px' //should be a fixed height
|
|
184
|
+
maxHeight: height,
|
|
185
|
+
//should be a fixed height
|
|
186
|
+
height: minHeight ? height : undefined //should be a fixed height
|
|
187
|
+
// minWidth: table.getTotalSize()
|
|
188
|
+
}
|
|
189
|
+
// onScroll={infiniteScroll ? handleScroll : undefined}
|
|
190
|
+
,
|
|
191
|
+
onScroll: handleScroll
|
|
192
|
+
}, /*#__PURE__*/React.createElement("table", {
|
|
193
|
+
style: {
|
|
194
|
+
display: 'grid'
|
|
195
|
+
// minWidth: table.getTotalSize()
|
|
196
|
+
}
|
|
197
|
+
}, /*#__PURE__*/React.createElement(TableHead, {
|
|
198
|
+
tableContainerRef: tableContainerRef,
|
|
199
|
+
table: table,
|
|
200
|
+
columnVirtualizer: columnVirtualizer,
|
|
201
|
+
virtualPaddingLeft: virtualPaddingLeft,
|
|
202
|
+
virtualPaddingRight: virtualPaddingRight,
|
|
203
|
+
fixedLeftColumns: fixedLeftColumns,
|
|
204
|
+
fixedRightColumns: fixedRightColumns
|
|
205
|
+
}), /*#__PURE__*/React.createElement(TableBody, {
|
|
206
|
+
tableId: id,
|
|
207
|
+
table: table,
|
|
208
|
+
tableContainerRef: tableContainerRef,
|
|
209
|
+
commandClick: commandClick,
|
|
210
|
+
editAble: editAble,
|
|
211
|
+
contextMenuItems: contextMenuItems,
|
|
212
|
+
showEmptyText: showEmptyText,
|
|
213
|
+
onContextMenu: onContextMenu,
|
|
214
|
+
columnVirtualizer: columnVirtualizer,
|
|
215
|
+
virtualPaddingLeft: virtualPaddingLeft,
|
|
216
|
+
virtualPaddingRight: virtualPaddingRight,
|
|
217
|
+
fixedLeftColumns: fixedLeftColumns,
|
|
218
|
+
fixedRightColumns: fixedRightColumns
|
|
219
|
+
}), summary && /*#__PURE__*/React.createElement(TableFooter
|
|
220
|
+
// columnVirtualizer={columnVirtualizer}
|
|
221
|
+
, {
|
|
222
|
+
table: table
|
|
223
|
+
// virtualPaddingLeft={virtualPaddingLeft}
|
|
224
|
+
// virtualPaddingRight={virtualPaddingRight}
|
|
225
|
+
// fixedLeftColumns={fixedLeftColumns}
|
|
226
|
+
// fixedRightColumns={fixedRightColumns}
|
|
227
|
+
}))), loading && /*#__PURE__*/React.createElement("div", {
|
|
228
|
+
className: "spinner-loading"
|
|
229
|
+
}, /*#__PURE__*/React.createElement(ComponentSpinner, null)), /*#__PURE__*/React.createElement(Tooltip, {
|
|
230
|
+
id: `${id}-tooltip-content`,
|
|
231
|
+
style: {
|
|
232
|
+
zIndex: 1999,
|
|
233
|
+
maxWidth: 450
|
|
234
|
+
}
|
|
235
|
+
}), menuVisible && /*#__PURE__*/React.createElement(ContextMenu, {
|
|
236
|
+
open: menuVisible,
|
|
237
|
+
pos: position,
|
|
238
|
+
setOpen: setMenuVisible,
|
|
239
|
+
menuRef: menuRef,
|
|
240
|
+
contextMenuItems: contextMenuItems,
|
|
241
|
+
contextMenuClick: contextMenuClick,
|
|
242
|
+
rowData: selectedRowData
|
|
243
|
+
}));
|
|
244
|
+
};
|
|
245
|
+
export default TableWrapper;
|
|
@@ -186,6 +186,7 @@ export type TableProps<RecordType = AnyObject> = {
|
|
|
186
186
|
dataSource: RecordType[];
|
|
187
187
|
columns: ColumnsTable<RecordType>;
|
|
188
188
|
height?: number;
|
|
189
|
+
minHeight?: number;
|
|
189
190
|
format?: IFormat;
|
|
190
191
|
t?: any;
|
|
191
192
|
lang?: string;
|
|
@@ -220,7 +221,7 @@ export type TableProps<RecordType = AnyObject> = {
|
|
|
220
221
|
showToolbar?: boolean;
|
|
221
222
|
onDataChange?: (data: RecordType[]) => void;
|
|
222
223
|
defaultValue?: AnyObject | (() => AnyObject);
|
|
223
|
-
summary?: boolean
|
|
224
|
+
summary?: boolean;
|
|
224
225
|
showEmptyText?: boolean;
|
|
225
226
|
commandSettings?: CommandSettings;
|
|
226
227
|
onCellPaste?: ICellPasteModel<RecordType>;
|
|
@@ -236,7 +237,7 @@ export type TableProps<RecordType = AnyObject> = {
|
|
|
236
237
|
}) => void;
|
|
237
238
|
wrapSettings?: IWrapSettings;
|
|
238
239
|
actionTemplate?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
|
|
239
|
-
commandClick?: (args: CommandClick) => void;
|
|
240
|
+
commandClick?: (args: CommandClick<RecordType>) => void;
|
|
240
241
|
expandable?: ExpandableConfig<RecordType>;
|
|
241
242
|
fullScreen?: boolean;
|
|
242
243
|
};
|
|
@@ -270,12 +271,12 @@ export interface RenderExpandIconProps<RecordType> {
|
|
|
270
271
|
export type TriggerEventHandler<RecordType> = (record: RecordType, event: React.MouseEvent<HTMLElement>) => void;
|
|
271
272
|
export type RowClassName<RecordType> = (record: RecordType, index: number, indent: number) => string;
|
|
272
273
|
export type ExpandedRowRender<ValueType> = (record: ValueType, index: number, indent: number, expanded: boolean) => React.ReactNode;
|
|
273
|
-
export type CommandClick = {
|
|
274
|
+
export type CommandClick<T> = {
|
|
274
275
|
id: string;
|
|
275
276
|
rowId: string;
|
|
276
277
|
rowData: any;
|
|
277
278
|
index: number;
|
|
278
|
-
rows
|
|
279
|
+
rows: T[];
|
|
279
280
|
};
|
|
280
281
|
export type IEditSelectSettings = {
|
|
281
282
|
fieldKey?: string;
|
|
@@ -27,6 +27,10 @@ export interface IContext<T> {
|
|
|
27
27
|
setFilterChange: Dispatch<SetStateAction<boolean>>;
|
|
28
28
|
onContextMenu?: (data: T) => (event: any) => void;
|
|
29
29
|
locale?: Locale;
|
|
30
|
+
windowSize: {
|
|
31
|
+
innerHeight: number;
|
|
32
|
+
innerWidth: number;
|
|
33
|
+
};
|
|
30
34
|
control?: any;
|
|
31
35
|
errors?: any;
|
|
32
36
|
handleSubmit?: any;
|