es-grid-template 1.9.72 → 1.9.73
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/ali-table/utils/utility.js +3 -0
- package/es/grid-component/hooks/constant.js +4 -0
- package/es/group-component/hook/useColumns.js +2 -2
- package/es/group-component/hook/utils.d.ts +3 -3
- package/es/group-component/hook/utils.js +3 -0
- package/es/table-component/ColumnsConfig.js +6 -4
- package/es/table-component/TableContainer.js +1 -0
- package/es/table-component/TableContainerEdit.js +1 -0
- package/es/table-component/hook/utils.js +3 -0
- package/es/table-component/table/Grid.js +2 -2
- package/es/table-component/table/TableWrapper.js +97 -33
- package/es/table-virtuoso/hook/utils.js +3 -0
- package/lib/ali-table/utils/utility.js +3 -0
- package/lib/grid-component/hooks/constant.js +4 -0
- package/lib/group-component/hook/useColumns.js +2 -2
- package/lib/group-component/hook/utils.js +3 -0
- package/lib/table-component/ColumnsConfig.js +6 -4
- package/lib/table-component/TableContainer.js +1 -0
- package/lib/table-component/TableContainerEdit.js +1 -0
- package/lib/table-component/hook/utils.js +3 -0
- package/lib/table-component/table/Grid.js +2 -2
- package/lib/table-component/table/TableWrapper.js +97 -33
- package/lib/table-virtuoso/hook/utils.js +3 -0
- package/package.json +1 -1
|
@@ -94,6 +94,9 @@ export const shouldIncludeOptimized = (item, queries, ignoreAccents = true) => {
|
|
|
94
94
|
case 'contains':
|
|
95
95
|
condition = ignoreAccents === false ? itemValue?.includes(value) : itemStr.includes(compareValue);
|
|
96
96
|
break;
|
|
97
|
+
case 'notcontains':
|
|
98
|
+
condition = ignoreAccents === false ? !itemValue?.includes(value) : !itemStr.includes(compareValue);
|
|
99
|
+
break;
|
|
97
100
|
case 'startswith':
|
|
98
101
|
condition = ignoreAccents === false ? itemValue?.startsWith(value) : itemStr.startsWith(compareValue);
|
|
99
102
|
break;
|
|
@@ -204,12 +204,12 @@ export const toggleRowSelection = props => {
|
|
|
204
204
|
} else {
|
|
205
205
|
// chưa selected
|
|
206
206
|
|
|
207
|
-
const checkedRows = [...prevSelected, row];
|
|
207
|
+
const checkedRows = [...prevSelected, row.original];
|
|
208
208
|
setIsSelectionChange({
|
|
209
209
|
isChange: true,
|
|
210
210
|
type: 'rowSelected',
|
|
211
211
|
rowData: row.original,
|
|
212
|
-
rowsData: selectionSettings?.type === 'single' ? [row] : checkedRows
|
|
212
|
+
rowsData: selectionSettings?.type === 'single' ? [row.original] : checkedRows
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
return;
|
|
@@ -196,10 +196,10 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
|
|
|
196
196
|
value: any;
|
|
197
197
|
rowData: RecordType;
|
|
198
198
|
}) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
|
|
199
|
-
onCellStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
200
|
-
onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
199
|
+
onCellStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
|
|
200
|
+
onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
|
|
201
201
|
onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
|
|
202
|
-
onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
202
|
+
onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
|
|
203
203
|
getValue?: (row: any, rowIndex: number) => any;
|
|
204
204
|
getCellProps?: (value: any, row: any, rowIndex: number) => import("./../../grid-component/type").CellProps;
|
|
205
205
|
headerCellProps?: import("./../../grid-component/type").CellProps;
|
|
@@ -801,6 +801,9 @@ export const shouldInclude = (item, queries) => {
|
|
|
801
801
|
case "contains":
|
|
802
802
|
condition = itemStr?.includes(queryStr);
|
|
803
803
|
break;
|
|
804
|
+
case "notcontains":
|
|
805
|
+
condition = !itemStr?.includes(queryStr);
|
|
806
|
+
break;
|
|
804
807
|
case "startswith":
|
|
805
808
|
condition = itemStr?.startsWith(queryStr);
|
|
806
809
|
break;
|
|
@@ -60,6 +60,7 @@ export const ColumnsConfig = props => {
|
|
|
60
60
|
};
|
|
61
61
|
const handleAccept = () => {
|
|
62
62
|
triggerChangeColumns?.(tmpColumn, [], 'columnChoose');
|
|
63
|
+
setCurrentRow('');
|
|
63
64
|
onClose();
|
|
64
65
|
};
|
|
65
66
|
const handleChange = newElemt => {
|
|
@@ -109,10 +110,11 @@ export const ColumnsConfig = props => {
|
|
|
109
110
|
return /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Input, {
|
|
110
111
|
defaultValue: value,
|
|
111
112
|
allowClear: true,
|
|
113
|
+
autoFocus: true,
|
|
112
114
|
onBlur: e => {
|
|
113
115
|
const newData = {
|
|
114
116
|
...rowData,
|
|
115
|
-
|
|
117
|
+
headerText: e.target.value
|
|
116
118
|
};
|
|
117
119
|
handleChange(newData);
|
|
118
120
|
}
|
|
@@ -209,7 +211,7 @@ export const ColumnsConfig = props => {
|
|
|
209
211
|
} = args;
|
|
210
212
|
if (currentRow === rowData.field) {
|
|
211
213
|
return /*#__PURE__*/React.createElement(InputNumber, {
|
|
212
|
-
defaultValue: value,
|
|
214
|
+
defaultValue: value ?? 150,
|
|
213
215
|
style: {
|
|
214
216
|
width: '100%'
|
|
215
217
|
},
|
|
@@ -217,13 +219,13 @@ export const ColumnsConfig = props => {
|
|
|
217
219
|
onBlur: e => {
|
|
218
220
|
const newData = {
|
|
219
221
|
...rowData,
|
|
220
|
-
|
|
222
|
+
width: e.target.value ? Number(e.target.value) : 150
|
|
221
223
|
};
|
|
222
224
|
handleChange(newData);
|
|
223
225
|
}
|
|
224
226
|
});
|
|
225
227
|
}
|
|
226
|
-
return /*#__PURE__*/React.createElement("span", null, value);
|
|
228
|
+
return /*#__PURE__*/React.createElement("span", null, value ?? 150, "px");
|
|
227
229
|
}
|
|
228
230
|
}];
|
|
229
231
|
const handleReset = () => {
|
|
@@ -1069,6 +1069,9 @@ export const shouldInclude = (item, queries, ignoreAccents) => {
|
|
|
1069
1069
|
case "contains":
|
|
1070
1070
|
condition = ignoreAccents === false ? itemValue?.includes(value) : itemStr?.includes(queryStr);
|
|
1071
1071
|
break;
|
|
1072
|
+
case "notcontains":
|
|
1073
|
+
condition = ignoreAccents === false ? !itemValue?.includes(value) : !itemStr?.includes(queryStr);
|
|
1074
|
+
break;
|
|
1072
1075
|
case "startswith":
|
|
1073
1076
|
condition = ignoreAccents === false ? itemValue?.startsWith(value) : itemStr?.startsWith(queryStr);
|
|
1074
1077
|
break;
|
|
@@ -64,8 +64,8 @@ const Grid = props => {
|
|
|
64
64
|
const [columnResizeMode] = React.useState('onChange');
|
|
65
65
|
const [columnResizeDirection] = React.useState('ltr');
|
|
66
66
|
const [paginationState, setPagination] = React.useState({
|
|
67
|
-
pageIndex: pagination && pagination
|
|
68
|
-
pageSize: pagination && pagination
|
|
67
|
+
pageIndex: pagination && pagination?.currentPage ? pagination.currentPage - 1 : 0,
|
|
68
|
+
pageSize: pagination && pagination?.pageSize ? pagination.pageSize : 20
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
// const [rowSelection, setRowSelection] = React.useState<RowSelectionState>({})
|
|
@@ -7,7 +7,6 @@ import { Tooltip } from "react-tooltip";
|
|
|
7
7
|
import ContextMenu from "../ContextMenu";
|
|
8
8
|
import React, { useContext } from "react";
|
|
9
9
|
import { TableContext } from "../useContext";
|
|
10
|
-
import { isNullOrUndefined } from "../hook/utils";
|
|
11
10
|
const TableWrapper = props => {
|
|
12
11
|
const {
|
|
13
12
|
id,
|
|
@@ -40,6 +39,12 @@ const TableWrapper = props => {
|
|
|
40
39
|
const menuRef = React.useRef(null);
|
|
41
40
|
const loadingRef = React.useRef(false);
|
|
42
41
|
const hasMoreRef = React.useRef(true);
|
|
42
|
+
const pendingPageRef = React.useRef(null);
|
|
43
|
+
const pendingDataLengthRef = React.useRef(0);
|
|
44
|
+
const sawLoadingRef = React.useRef(false);
|
|
45
|
+
const lastScrollTopRef = React.useRef(0);
|
|
46
|
+
// const directionRef = React.useRef<'up' | 'down' | null>(null);
|
|
47
|
+
|
|
43
48
|
const {
|
|
44
49
|
windowSize
|
|
45
50
|
} = useContext(TableContext);
|
|
@@ -48,6 +53,23 @@ const TableWrapper = props => {
|
|
|
48
53
|
pageSize,
|
|
49
54
|
total
|
|
50
55
|
} = pagination ?? {};
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
if (pendingPageRef.current === null) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (loading) {
|
|
61
|
+
sawLoadingRef.current = true;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const pageLoaded = currentPage >= pendingPageRef.current;
|
|
65
|
+
const dataLoaded = dataSource.length !== pendingDataLengthRef.current;
|
|
66
|
+
const requestFinished = sawLoadingRef.current;
|
|
67
|
+
if (pageLoaded || dataLoaded || requestFinished) {
|
|
68
|
+
loadingRef.current = false;
|
|
69
|
+
pendingPageRef.current = null;
|
|
70
|
+
sawLoadingRef.current = false;
|
|
71
|
+
}
|
|
72
|
+
}, [currentPage, dataSource.length, loading]);
|
|
51
73
|
const [menuVisible, setMenuVisible] = React.useState(false);
|
|
52
74
|
const [selectedRowData, setSelectedRowData] = React.useState(undefined);
|
|
53
75
|
const [position, setPosition] = React.useState({
|
|
@@ -74,46 +96,88 @@ const TableWrapper = props => {
|
|
|
74
96
|
const loadData = page => {
|
|
75
97
|
if (!hasMoreRef.current || loadingRef.current || loading) return;
|
|
76
98
|
loadingRef.current = true;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}, 10);
|
|
99
|
+
pendingPageRef.current = page;
|
|
100
|
+
pendingDataLengthRef.current = dataSource.length;
|
|
101
|
+
next?.();
|
|
102
|
+
if (pageSize && total && page * pageSize >= total) {
|
|
103
|
+
hasMoreRef.current = false;
|
|
104
|
+
}
|
|
84
105
|
};
|
|
85
106
|
const handleNext = () => {
|
|
86
107
|
loadData(currentPage + 1);
|
|
87
108
|
};
|
|
88
109
|
const handleScroll = e => {
|
|
89
|
-
if (infiniteScroll) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
e.preventDefault();
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const {
|
|
96
|
-
scrollHeight: tbScrollHeight,
|
|
97
|
-
scrollTop,
|
|
98
|
-
clientHeight
|
|
99
|
-
} = e.currentTarget;
|
|
100
|
-
const abc = clientHeight * (isNullOrUndefined(onEndReachedThreshold) ? 0.1 : onEndReachedThreshold ?? 0);
|
|
110
|
+
// if (infiniteScroll) {
|
|
111
|
+
// const current = e.currentTarget.scrollTop;
|
|
112
|
+
// const last = lastScrollTopRef.current;
|
|
101
113
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
// if (loadingRef.current || loading || dataSource?.length === 0 || current === last) {
|
|
115
|
+
|
|
116
|
+
// e.stopPropagation()
|
|
117
|
+
// e.preventDefault()
|
|
118
|
+
// return
|
|
119
|
+
// }
|
|
120
|
+
|
|
121
|
+
// const { scrollHeight: tbScrollHeight, scrollTop, clientHeight } = e.currentTarget;
|
|
122
|
+
|
|
123
|
+
// const abc = clientHeight * (isNullOrUndefined(onEndReachedThreshold) ? 0.1 : onEndReachedThreshold ?? 0)
|
|
124
|
+
|
|
125
|
+
// // const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
|
|
126
|
+
// const isEnd = scrollTop + clientHeight >= tbScrollHeight - abc;
|
|
127
|
+
|
|
128
|
+
// if (isEnd && !loadingRef.current && hasMoreRef.current && dataSource?.length > 0) {
|
|
129
|
+
|
|
130
|
+
// handleNext()
|
|
131
|
+
|
|
132
|
+
// }
|
|
133
|
+
// }
|
|
134
|
+
|
|
135
|
+
// if (e.target.scrollLeft >= 0 && e.target.scrollLeft + e.target.clientWidth < e.target.scrollWidth) {
|
|
136
|
+
// e.target.classList.add('ui-rc-table-ping-right')
|
|
137
|
+
// } else {
|
|
138
|
+
// e.target.classList.remove('ui-rc-table-ping-right')
|
|
139
|
+
// }
|
|
140
|
+
|
|
141
|
+
// if ((e.target.scrollLeft ?? 0) > 0) {
|
|
142
|
+
// e.target.classList.add('ui-rc-table-ping-left')
|
|
143
|
+
// } else {
|
|
144
|
+
// e.target.classList.remove('ui-rc-table-ping-left')
|
|
145
|
+
// }
|
|
146
|
+
|
|
147
|
+
const target = e.currentTarget;
|
|
148
|
+
|
|
149
|
+
// Horizontal scroll
|
|
150
|
+
const {
|
|
151
|
+
scrollLeft,
|
|
152
|
+
clientWidth,
|
|
153
|
+
scrollWidth,
|
|
154
|
+
clientHeight
|
|
155
|
+
} = target;
|
|
156
|
+
target.classList.toggle('ui-rc-table-ping-left', scrollLeft > 0);
|
|
157
|
+
target.classList.toggle('ui-rc-table-ping-right', scrollLeft + clientWidth < scrollWidth);
|
|
158
|
+
if (!infiniteScroll) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const {
|
|
162
|
+
scrollTop,
|
|
163
|
+
scrollHeight
|
|
164
|
+
} = target;
|
|
165
|
+
const last = lastScrollTopRef.current;
|
|
166
|
+
|
|
167
|
+
// Update ngay
|
|
168
|
+
lastScrollTopRef.current = scrollTop;
|
|
169
|
+
|
|
170
|
+
// Chỉ xử lý khi scroll DOWN
|
|
171
|
+
if (scrollTop <= last) {
|
|
172
|
+
return;
|
|
107
173
|
}
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
} else {
|
|
111
|
-
e.target.classList.remove('ui-rc-table-ping-right');
|
|
174
|
+
if (loadingRef.current || loading || !dataSource?.length || !hasMoreRef.current) {
|
|
175
|
+
return;
|
|
112
176
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
177
|
+
const thresholdRatio = onEndReachedThreshold ?? 0.1;
|
|
178
|
+
const threshold = clientHeight * thresholdRatio;
|
|
179
|
+
if (scrollTop + clientHeight >= scrollHeight - threshold) {
|
|
180
|
+
handleNext();
|
|
117
181
|
}
|
|
118
182
|
};
|
|
119
183
|
const onContextMenu = args => event => {
|
|
@@ -849,6 +849,9 @@ export const shouldInclude = (item, queries) => {
|
|
|
849
849
|
case "contains":
|
|
850
850
|
condition = itemStr?.includes(queryStr);
|
|
851
851
|
break;
|
|
852
|
+
case "notcontains":
|
|
853
|
+
condition = !itemStr?.includes(queryStr);
|
|
854
|
+
break;
|
|
852
855
|
case "startswith":
|
|
853
856
|
condition = itemStr?.startsWith(queryStr);
|
|
854
857
|
break;
|
|
@@ -111,6 +111,9 @@ const shouldIncludeOptimized = (item, queries, ignoreAccents = true) => {
|
|
|
111
111
|
case 'contains':
|
|
112
112
|
condition = ignoreAccents === false ? itemValue?.includes(value) : itemStr.includes(compareValue);
|
|
113
113
|
break;
|
|
114
|
+
case 'notcontains':
|
|
115
|
+
condition = ignoreAccents === false ? !itemValue?.includes(value) : !itemStr.includes(compareValue);
|
|
116
|
+
break;
|
|
114
117
|
case 'startswith':
|
|
115
118
|
condition = ignoreAccents === false ? itemValue?.startsWith(value) : itemStr.startsWith(compareValue);
|
|
116
119
|
break;
|
|
@@ -215,12 +215,12 @@ const toggleRowSelection = props => {
|
|
|
215
215
|
} else {
|
|
216
216
|
// chưa selected
|
|
217
217
|
|
|
218
|
-
const checkedRows = [...prevSelected, row];
|
|
218
|
+
const checkedRows = [...prevSelected, row.original];
|
|
219
219
|
setIsSelectionChange({
|
|
220
220
|
isChange: true,
|
|
221
221
|
type: 'rowSelected',
|
|
222
222
|
rowData: row.original,
|
|
223
|
-
rowsData: selectionSettings?.type === 'single' ? [row] : checkedRows
|
|
223
|
+
rowsData: selectionSettings?.type === 'single' ? [row.original] : checkedRows
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
return;
|
|
@@ -893,6 +893,9 @@ const shouldInclude = (item, queries) => {
|
|
|
893
893
|
case "contains":
|
|
894
894
|
condition = itemStr?.includes(queryStr);
|
|
895
895
|
break;
|
|
896
|
+
case "notcontains":
|
|
897
|
+
condition = !itemStr?.includes(queryStr);
|
|
898
|
+
break;
|
|
896
899
|
case "startswith":
|
|
897
900
|
condition = itemStr?.startsWith(queryStr);
|
|
898
901
|
break;
|
|
@@ -69,6 +69,7 @@ const ColumnsConfig = props => {
|
|
|
69
69
|
};
|
|
70
70
|
const handleAccept = () => {
|
|
71
71
|
triggerChangeColumns?.(tmpColumn, [], 'columnChoose');
|
|
72
|
+
setCurrentRow('');
|
|
72
73
|
onClose();
|
|
73
74
|
};
|
|
74
75
|
const handleChange = newElemt => {
|
|
@@ -118,10 +119,11 @@ const ColumnsConfig = props => {
|
|
|
118
119
|
return /*#__PURE__*/_react.default.createElement("span", null, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Input, {
|
|
119
120
|
defaultValue: value,
|
|
120
121
|
allowClear: true,
|
|
122
|
+
autoFocus: true,
|
|
121
123
|
onBlur: e => {
|
|
122
124
|
const newData = {
|
|
123
125
|
...rowData,
|
|
124
|
-
|
|
126
|
+
headerText: e.target.value
|
|
125
127
|
};
|
|
126
128
|
handleChange(newData);
|
|
127
129
|
}
|
|
@@ -218,7 +220,7 @@ const ColumnsConfig = props => {
|
|
|
218
220
|
} = args;
|
|
219
221
|
if (currentRow === rowData.field) {
|
|
220
222
|
return /*#__PURE__*/_react.default.createElement(_rcMasterUi.InputNumber, {
|
|
221
|
-
defaultValue: value,
|
|
223
|
+
defaultValue: value ?? 150,
|
|
222
224
|
style: {
|
|
223
225
|
width: '100%'
|
|
224
226
|
},
|
|
@@ -226,13 +228,13 @@ const ColumnsConfig = props => {
|
|
|
226
228
|
onBlur: e => {
|
|
227
229
|
const newData = {
|
|
228
230
|
...rowData,
|
|
229
|
-
|
|
231
|
+
width: e.target.value ? Number(e.target.value) : 150
|
|
230
232
|
};
|
|
231
233
|
handleChange(newData);
|
|
232
234
|
}
|
|
233
235
|
});
|
|
234
236
|
}
|
|
235
|
-
return /*#__PURE__*/_react.default.createElement("span", null, value);
|
|
237
|
+
return /*#__PURE__*/_react.default.createElement("span", null, value ?? 150, "px");
|
|
236
238
|
}
|
|
237
239
|
}];
|
|
238
240
|
const handleReset = () => {
|
|
@@ -1183,6 +1183,9 @@ const shouldInclude = (item, queries, ignoreAccents) => {
|
|
|
1183
1183
|
case "contains":
|
|
1184
1184
|
condition = ignoreAccents === false ? itemValue?.includes(value) : itemStr?.includes(queryStr);
|
|
1185
1185
|
break;
|
|
1186
|
+
case "notcontains":
|
|
1187
|
+
condition = ignoreAccents === false ? !itemValue?.includes(value) : !itemStr?.includes(queryStr);
|
|
1188
|
+
break;
|
|
1186
1189
|
case "startswith":
|
|
1187
1190
|
condition = ignoreAccents === false ? itemValue?.startsWith(value) : itemStr?.startsWith(queryStr);
|
|
1188
1191
|
break;
|
|
@@ -69,8 +69,8 @@ const Grid = props => {
|
|
|
69
69
|
const [columnResizeMode] = _react.default.useState('onChange');
|
|
70
70
|
const [columnResizeDirection] = _react.default.useState('ltr');
|
|
71
71
|
const [paginationState, setPagination] = _react.default.useState({
|
|
72
|
-
pageIndex: pagination && pagination
|
|
73
|
-
pageSize: pagination && pagination
|
|
72
|
+
pageIndex: pagination && pagination?.currentPage ? pagination.currentPage - 1 : 0,
|
|
73
|
+
pageSize: pagination && pagination?.pageSize ? pagination.pageSize : 20
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
// const [rowSelection, setRowSelection] = React.useState<RowSelectionState>({})
|
|
@@ -14,7 +14,6 @@ var _reactTooltip = require("react-tooltip");
|
|
|
14
14
|
var _ContextMenu = _interopRequireDefault(require("../ContextMenu"));
|
|
15
15
|
var _react = _interopRequireWildcard(require("react"));
|
|
16
16
|
var _useContext = require("../useContext");
|
|
17
|
-
var _utils = require("../hook/utils");
|
|
18
17
|
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); }
|
|
19
18
|
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; }
|
|
20
19
|
const TableWrapper = props => {
|
|
@@ -49,6 +48,12 @@ const TableWrapper = props => {
|
|
|
49
48
|
const menuRef = _react.default.useRef(null);
|
|
50
49
|
const loadingRef = _react.default.useRef(false);
|
|
51
50
|
const hasMoreRef = _react.default.useRef(true);
|
|
51
|
+
const pendingPageRef = _react.default.useRef(null);
|
|
52
|
+
const pendingDataLengthRef = _react.default.useRef(0);
|
|
53
|
+
const sawLoadingRef = _react.default.useRef(false);
|
|
54
|
+
const lastScrollTopRef = _react.default.useRef(0);
|
|
55
|
+
// const directionRef = React.useRef<'up' | 'down' | null>(null);
|
|
56
|
+
|
|
52
57
|
const {
|
|
53
58
|
windowSize
|
|
54
59
|
} = (0, _react.useContext)(_useContext.TableContext);
|
|
@@ -57,6 +62,23 @@ const TableWrapper = props => {
|
|
|
57
62
|
pageSize,
|
|
58
63
|
total
|
|
59
64
|
} = pagination ?? {};
|
|
65
|
+
_react.default.useEffect(() => {
|
|
66
|
+
if (pendingPageRef.current === null) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (loading) {
|
|
70
|
+
sawLoadingRef.current = true;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const pageLoaded = currentPage >= pendingPageRef.current;
|
|
74
|
+
const dataLoaded = dataSource.length !== pendingDataLengthRef.current;
|
|
75
|
+
const requestFinished = sawLoadingRef.current;
|
|
76
|
+
if (pageLoaded || dataLoaded || requestFinished) {
|
|
77
|
+
loadingRef.current = false;
|
|
78
|
+
pendingPageRef.current = null;
|
|
79
|
+
sawLoadingRef.current = false;
|
|
80
|
+
}
|
|
81
|
+
}, [currentPage, dataSource.length, loading]);
|
|
60
82
|
const [menuVisible, setMenuVisible] = _react.default.useState(false);
|
|
61
83
|
const [selectedRowData, setSelectedRowData] = _react.default.useState(undefined);
|
|
62
84
|
const [position, setPosition] = _react.default.useState({
|
|
@@ -83,46 +105,88 @@ const TableWrapper = props => {
|
|
|
83
105
|
const loadData = page => {
|
|
84
106
|
if (!hasMoreRef.current || loadingRef.current || loading) return;
|
|
85
107
|
loadingRef.current = true;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}, 10);
|
|
108
|
+
pendingPageRef.current = page;
|
|
109
|
+
pendingDataLengthRef.current = dataSource.length;
|
|
110
|
+
next?.();
|
|
111
|
+
if (pageSize && total && page * pageSize >= total) {
|
|
112
|
+
hasMoreRef.current = false;
|
|
113
|
+
}
|
|
93
114
|
};
|
|
94
115
|
const handleNext = () => {
|
|
95
116
|
loadData(currentPage + 1);
|
|
96
117
|
};
|
|
97
118
|
const handleScroll = e => {
|
|
98
|
-
if (infiniteScroll) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
e.preventDefault();
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const {
|
|
105
|
-
scrollHeight: tbScrollHeight,
|
|
106
|
-
scrollTop,
|
|
107
|
-
clientHeight
|
|
108
|
-
} = e.currentTarget;
|
|
109
|
-
const abc = clientHeight * ((0, _utils.isNullOrUndefined)(onEndReachedThreshold) ? 0.1 : onEndReachedThreshold ?? 0);
|
|
119
|
+
// if (infiniteScroll) {
|
|
120
|
+
// const current = e.currentTarget.scrollTop;
|
|
121
|
+
// const last = lastScrollTopRef.current;
|
|
110
122
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
// if (loadingRef.current || loading || dataSource?.length === 0 || current === last) {
|
|
124
|
+
|
|
125
|
+
// e.stopPropagation()
|
|
126
|
+
// e.preventDefault()
|
|
127
|
+
// return
|
|
128
|
+
// }
|
|
129
|
+
|
|
130
|
+
// const { scrollHeight: tbScrollHeight, scrollTop, clientHeight } = e.currentTarget;
|
|
131
|
+
|
|
132
|
+
// const abc = clientHeight * (isNullOrUndefined(onEndReachedThreshold) ? 0.1 : onEndReachedThreshold ?? 0)
|
|
133
|
+
|
|
134
|
+
// // const isEnd = scrollTop + clientHeight >= tbScrollHeight - 50;
|
|
135
|
+
// const isEnd = scrollTop + clientHeight >= tbScrollHeight - abc;
|
|
136
|
+
|
|
137
|
+
// if (isEnd && !loadingRef.current && hasMoreRef.current && dataSource?.length > 0) {
|
|
138
|
+
|
|
139
|
+
// handleNext()
|
|
140
|
+
|
|
141
|
+
// }
|
|
142
|
+
// }
|
|
143
|
+
|
|
144
|
+
// if (e.target.scrollLeft >= 0 && e.target.scrollLeft + e.target.clientWidth < e.target.scrollWidth) {
|
|
145
|
+
// e.target.classList.add('ui-rc-table-ping-right')
|
|
146
|
+
// } else {
|
|
147
|
+
// e.target.classList.remove('ui-rc-table-ping-right')
|
|
148
|
+
// }
|
|
149
|
+
|
|
150
|
+
// if ((e.target.scrollLeft ?? 0) > 0) {
|
|
151
|
+
// e.target.classList.add('ui-rc-table-ping-left')
|
|
152
|
+
// } else {
|
|
153
|
+
// e.target.classList.remove('ui-rc-table-ping-left')
|
|
154
|
+
// }
|
|
155
|
+
|
|
156
|
+
const target = e.currentTarget;
|
|
157
|
+
|
|
158
|
+
// Horizontal scroll
|
|
159
|
+
const {
|
|
160
|
+
scrollLeft,
|
|
161
|
+
clientWidth,
|
|
162
|
+
scrollWidth,
|
|
163
|
+
clientHeight
|
|
164
|
+
} = target;
|
|
165
|
+
target.classList.toggle('ui-rc-table-ping-left', scrollLeft > 0);
|
|
166
|
+
target.classList.toggle('ui-rc-table-ping-right', scrollLeft + clientWidth < scrollWidth);
|
|
167
|
+
if (!infiniteScroll) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const {
|
|
171
|
+
scrollTop,
|
|
172
|
+
scrollHeight
|
|
173
|
+
} = target;
|
|
174
|
+
const last = lastScrollTopRef.current;
|
|
175
|
+
|
|
176
|
+
// Update ngay
|
|
177
|
+
lastScrollTopRef.current = scrollTop;
|
|
178
|
+
|
|
179
|
+
// Chỉ xử lý khi scroll DOWN
|
|
180
|
+
if (scrollTop <= last) {
|
|
181
|
+
return;
|
|
116
182
|
}
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
} else {
|
|
120
|
-
e.target.classList.remove('ui-rc-table-ping-right');
|
|
183
|
+
if (loadingRef.current || loading || !dataSource?.length || !hasMoreRef.current) {
|
|
184
|
+
return;
|
|
121
185
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
186
|
+
const thresholdRatio = onEndReachedThreshold ?? 0.1;
|
|
187
|
+
const threshold = clientHeight * thresholdRatio;
|
|
188
|
+
if (scrollTop + clientHeight >= scrollHeight - threshold) {
|
|
189
|
+
handleNext();
|
|
126
190
|
}
|
|
127
191
|
};
|
|
128
192
|
const onContextMenu = args => event => {
|
|
@@ -948,6 +948,9 @@ const shouldInclude = (item, queries) => {
|
|
|
948
948
|
case "contains":
|
|
949
949
|
condition = itemStr?.includes(queryStr);
|
|
950
950
|
break;
|
|
951
|
+
case "notcontains":
|
|
952
|
+
condition = !itemStr?.includes(queryStr);
|
|
953
|
+
break;
|
|
951
954
|
case "startswith":
|
|
952
955
|
condition = itemStr?.startsWith(queryStr);
|
|
953
956
|
break;
|