es-grid-template 1.7.23 → 1.7.24
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/index.d.ts +1 -0
- package/es/index.js +3 -1
- package/es/table-component/ColumnsChoose.d.ts +10 -0
- package/es/table-component/ColumnsChoose.js +557 -0
- package/es/table-component/ContextMenu.d.ts +20 -0
- package/es/table-component/ContextMenu.js +75 -0
- package/es/table-component/InternalTable.d.ts +9 -0
- package/es/table-component/InternalTable.js +295 -0
- package/es/table-component/TableContainer.d.ts +22 -0
- package/es/table-component/TableContainer.js +130 -0
- package/es/table-component/TableContainerEdit.d.ts +28 -0
- package/es/table-component/TableContainerEdit.js +1211 -0
- package/es/table-component/body/EditableCell.d.ts +16 -0
- package/es/table-component/body/EditableCell.js +1036 -0
- package/es/table-component/body/TableBody.d.ts +19 -0
- package/es/table-component/body/TableBody.js +64 -0
- package/es/table-component/body/TableBodyCell.d.ts +10 -0
- package/es/table-component/body/TableBodyCell.js +139 -0
- package/es/table-component/body/TableBodyCellEdit.d.ts +15 -0
- package/es/table-component/body/TableBodyCellEdit.js +814 -0
- package/es/table-component/body/TableBodyRow.d.ts +21 -0
- package/es/table-component/body/TableBodyRow.js +146 -0
- package/es/table-component/components/ControlCheckbox.d.ts +13 -0
- package/es/table-component/components/ControlCheckbox.js +87 -0
- package/es/table-component/components/EditForm/EditForm.d.ts +27 -0
- package/es/table-component/components/EditForm/EditForm.js +395 -0
- package/es/table-component/components/EditForm/index.d.ts +1 -0
- package/es/table-component/components/EditForm/index.js +1 -0
- package/es/table-component/components/InputControl/InputControl.d.ts +27 -0
- package/es/table-component/components/InputControl/InputControl.js +121 -0
- package/es/table-component/components/InputControl/index.d.ts +1 -0
- package/es/table-component/components/InputControl/index.js +1 -0
- package/es/table-component/components/async-select/index.d.ts +11 -0
- package/es/table-component/components/async-select/index.js +41 -0
- package/es/table-component/components/async-table-select/index.d.ts +11 -0
- package/es/table-component/components/async-table-select/index.js +43 -0
- package/es/table-component/components/checkbox-control/index.d.ts +13 -0
- package/es/table-component/components/checkbox-control/index.js +40 -0
- package/es/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/es/table-component/components/checkbox-filter/CheckboxFilter.js +240 -0
- package/es/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/es/table-component/components/checkbox-filter/FilterSearch.js +36 -0
- package/es/table-component/components/command/Command.d.ts +9 -0
- package/es/table-component/components/command/Command.js +28 -0
- package/es/table-component/components/number/index.d.ts +10 -0
- package/es/table-component/components/number/index.js +42 -0
- package/es/table-component/components/number-range/index.d.ts +11 -0
- package/es/table-component/components/number-range/index.js +66 -0
- package/es/table-component/features/operator.d.ts +24 -0
- package/es/table-component/features/operator.js +62 -0
- package/es/table-component/footer/TableFooter.d.ts +13 -0
- package/es/table-component/footer/TableFooter.js +33 -0
- package/es/table-component/footer/TableFooterCell.d.ts +10 -0
- package/es/table-component/footer/TableFooterCell.js +24 -0
- package/es/table-component/footer/TableFooterRow.d.ts +14 -0
- package/es/table-component/footer/TableFooterRow.js +71 -0
- package/es/table-component/header/TableHead.d.ts +14 -0
- package/es/table-component/header/TableHead.js +60 -0
- package/es/table-component/header/TableHeadCell.d.ts +14 -0
- package/es/table-component/header/TableHeadCell.js +324 -0
- package/es/table-component/header/TableHeadRow.d.ts +16 -0
- package/es/table-component/header/TableHeadRow.js +86 -0
- package/es/table-component/header/renderFilter.d.ts +20 -0
- package/es/table-component/header/renderFilter.js +281 -0
- package/es/table-component/hook/constant.d.ts +73 -0
- package/es/table-component/hook/constant.js +240 -0
- package/es/table-component/hook/useColumns.d.ts +11 -0
- package/es/table-component/hook/useColumns.js +209 -0
- package/es/table-component/hook/useFilterOperator.d.ts +7 -0
- package/es/table-component/hook/useFilterOperator.js +33 -0
- package/es/table-component/hook/utils.d.ts +121 -0
- package/es/table-component/hook/utils.js +1727 -0
- package/es/table-component/index.d.ts +5 -0
- package/es/table-component/index.js +2 -0
- package/es/table-component/style.scss +1083 -0
- package/es/table-component/table/Grid.d.ts +23 -0
- package/es/table-component/table/Grid.js +310 -0
- package/es/table-component/table/GridEdit.d.ts +23 -0
- package/es/table-component/table/GridEdit.js +282 -0
- package/es/table-component/type.d.ts +482 -0
- package/es/table-component/type.js +1 -0
- package/es/table-component/useContext.d.ts +119 -0
- package/es/table-component/useContext.js +61 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -1
- package/lib/table-component/ColumnsChoose.d.ts +10 -0
- package/lib/table-component/ColumnsChoose.js +568 -0
- package/lib/table-component/ContextMenu.d.ts +20 -0
- package/lib/table-component/ContextMenu.js +85 -0
- package/lib/table-component/InternalTable.d.ts +9 -0
- package/lib/table-component/InternalTable.js +299 -0
- package/lib/table-component/TableContainer.d.ts +22 -0
- package/lib/table-component/TableContainer.js +137 -0
- package/lib/table-component/TableContainerEdit.d.ts +28 -0
- package/lib/table-component/TableContainerEdit.js +1220 -0
- package/lib/table-component/body/EditableCell.d.ts +16 -0
- package/lib/table-component/body/EditableCell.js +1038 -0
- package/lib/table-component/body/TableBody.d.ts +19 -0
- package/lib/table-component/body/TableBody.js +72 -0
- package/lib/table-component/body/TableBodyCell.d.ts +10 -0
- package/lib/table-component/body/TableBodyCell.js +148 -0
- package/lib/table-component/body/TableBodyCellEdit.d.ts +15 -0
- package/lib/table-component/body/TableBodyCellEdit.js +821 -0
- package/lib/table-component/body/TableBodyRow.d.ts +21 -0
- package/lib/table-component/body/TableBodyRow.js +153 -0
- package/lib/table-component/components/ControlCheckbox.d.ts +13 -0
- package/lib/table-component/components/ControlCheckbox.js +95 -0
- package/lib/table-component/components/EditForm/EditForm.d.ts +27 -0
- package/lib/table-component/components/EditForm/EditForm.js +406 -0
- package/lib/table-component/components/EditForm/index.d.ts +1 -0
- package/lib/table-component/components/EditForm/index.js +16 -0
- package/lib/table-component/components/InputControl/InputControl.d.ts +27 -0
- package/lib/table-component/components/InputControl/InputControl.js +131 -0
- package/lib/table-component/components/InputControl/index.d.ts +1 -0
- package/lib/table-component/components/InputControl/index.js +16 -0
- package/lib/table-component/components/async-select/index.d.ts +11 -0
- package/lib/table-component/components/async-select/index.js +49 -0
- package/lib/table-component/components/async-table-select/index.d.ts +11 -0
- package/lib/table-component/components/async-table-select/index.js +51 -0
- package/lib/table-component/components/checkbox-control/index.d.ts +13 -0
- package/lib/table-component/components/checkbox-control/index.js +48 -0
- package/lib/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/lib/table-component/components/checkbox-filter/CheckboxFilter.js +249 -0
- package/lib/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/lib/table-component/components/checkbox-filter/FilterSearch.js +44 -0
- package/lib/table-component/components/command/Command.d.ts +9 -0
- package/lib/table-component/components/command/Command.js +37 -0
- package/lib/table-component/components/number/index.d.ts +10 -0
- package/lib/table-component/components/number/index.js +50 -0
- package/lib/table-component/components/number-range/index.d.ts +11 -0
- package/lib/table-component/components/number-range/index.js +74 -0
- package/lib/table-component/features/operator.d.ts +24 -0
- package/lib/table-component/features/operator.js +67 -0
- package/lib/table-component/footer/TableFooter.d.ts +13 -0
- package/lib/table-component/footer/TableFooter.js +42 -0
- package/lib/table-component/footer/TableFooterCell.d.ts +10 -0
- package/lib/table-component/footer/TableFooterCell.js +32 -0
- package/lib/table-component/footer/TableFooterRow.d.ts +14 -0
- package/lib/table-component/footer/TableFooterRow.js +79 -0
- package/lib/table-component/header/TableHead.d.ts +14 -0
- package/lib/table-component/header/TableHead.js +69 -0
- package/lib/table-component/header/TableHeadCell.d.ts +14 -0
- package/lib/table-component/header/TableHeadCell.js +333 -0
- package/lib/table-component/header/TableHeadRow.d.ts +16 -0
- package/lib/table-component/header/TableHeadRow.js +94 -0
- package/lib/table-component/header/renderFilter.d.ts +20 -0
- package/lib/table-component/header/renderFilter.js +291 -0
- package/lib/table-component/hook/constant.d.ts +73 -0
- package/lib/table-component/hook/constant.js +247 -0
- package/lib/table-component/hook/useColumns.d.ts +11 -0
- package/lib/table-component/hook/useColumns.js +220 -0
- package/lib/table-component/hook/useFilterOperator.d.ts +7 -0
- package/lib/table-component/hook/useFilterOperator.js +40 -0
- package/lib/table-component/hook/utils.d.ts +121 -0
- package/lib/table-component/hook/utils.js +1817 -0
- package/lib/table-component/index.d.ts +5 -0
- package/lib/table-component/index.js +9 -0
- package/lib/table-component/style.scss +1083 -0
- package/lib/table-component/table/Grid.d.ts +23 -0
- package/lib/table-component/table/Grid.js +313 -0
- package/lib/table-component/table/GridEdit.d.ts +23 -0
- package/lib/table-component/table/GridEdit.js +284 -0
- package/lib/table-component/type.d.ts +482 -0
- package/lib/table-component/type.js +5 -0
- package/lib/table-component/useContext.d.ts +119 -0
- package/lib/table-component/useContext.js +67 -0
- package/package.json +3 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
import React, { Fragment, useState } from 'react';
|
|
4
|
+
import 'react-resizable/css/styles.css';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
import 'dayjs/locale/es';
|
|
7
|
+
import 'dayjs/locale/vi';
|
|
8
|
+
|
|
9
|
+
// import en from "rc-master-ui/es/date-picker/locale/en_US"
|
|
10
|
+
// import vi from "rc-master-ui/es/date-picker/locale/vi_VN"
|
|
11
|
+
|
|
12
|
+
// import enDr from "rc-master-ui/es/locales/en_US"
|
|
13
|
+
// import viDr from "rc-master-ui/es/locales/vi_VN"
|
|
14
|
+
|
|
15
|
+
// import type { PickerLocale } from "rc-master-ui/es/date-picker/generatePicker"
|
|
16
|
+
|
|
17
|
+
import "./style.scss";
|
|
18
|
+
|
|
19
|
+
// import Swal from "sweetalert2"
|
|
20
|
+
// import withReactContent from "sweetalert2-react-content"
|
|
21
|
+
// import { Tooltip } from "react-tooltip"
|
|
22
|
+
|
|
23
|
+
import { faker } from '@faker-js/faker';
|
|
24
|
+
import useMergedState from "rc-util/es/hooks/useMergedState";
|
|
25
|
+
// import InfiniteTable from './table/InfiniteTable'
|
|
26
|
+
// import GridEdit from './table/GridEdit'
|
|
27
|
+
import Grid from "./table/Grid";
|
|
28
|
+
// import { Group } from 'becoxy-icons'
|
|
29
|
+
|
|
30
|
+
import { Tooltip } from 'react-tooltip';
|
|
31
|
+
import ContextMenu from "./ContextMenu";
|
|
32
|
+
import { addRowIdArray,
|
|
33
|
+
// convertFilters,
|
|
34
|
+
filterDataByColumns,
|
|
35
|
+
// filterDataByColumns,
|
|
36
|
+
getAllRowKey, getFixedFields, getInvisibleColumns, groupArrayByColumns } from "./hook/utils";
|
|
37
|
+
import GridEdit from "./table/GridEdit";
|
|
38
|
+
import { convertToTanStackColumns } from "./hook/useColumns";
|
|
39
|
+
dayjs.extend(customParseFormat);
|
|
40
|
+
|
|
41
|
+
// const MySwal = withReactContent(Swal)
|
|
42
|
+
|
|
43
|
+
// const ASCEND = 'ascend'
|
|
44
|
+
// const DESCEND = 'descend'
|
|
45
|
+
|
|
46
|
+
export const SELECTION_COLUMN = {};
|
|
47
|
+
const InternalTable = props => {
|
|
48
|
+
const {
|
|
49
|
+
t,
|
|
50
|
+
// columns: propsColumns,
|
|
51
|
+
columns,
|
|
52
|
+
lang,
|
|
53
|
+
locale,
|
|
54
|
+
dataSource,
|
|
55
|
+
editAble,
|
|
56
|
+
format,
|
|
57
|
+
groupAble,
|
|
58
|
+
groupSetting,
|
|
59
|
+
groupColumns,
|
|
60
|
+
infiniteScroll,
|
|
61
|
+
// wrapSettings,
|
|
62
|
+
// onFilter,
|
|
63
|
+
expandable,
|
|
64
|
+
contextMenuItems: propContextMenuItems,
|
|
65
|
+
contextMenuHidden,
|
|
66
|
+
contextMenuClick,
|
|
67
|
+
contextMenuOpen,
|
|
68
|
+
...rest
|
|
69
|
+
} = props;
|
|
70
|
+
const id = React.useMemo(() => {
|
|
71
|
+
return faker.string.alpha(20);
|
|
72
|
+
}, []);
|
|
73
|
+
const rowKey = 'rowId';
|
|
74
|
+
const prefix = 'ui-rc';
|
|
75
|
+
const getWindowSize = () => {
|
|
76
|
+
const {
|
|
77
|
+
innerWidth,
|
|
78
|
+
innerHeight
|
|
79
|
+
} = window;
|
|
80
|
+
return {
|
|
81
|
+
innerWidth,
|
|
82
|
+
innerHeight
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
const [windowSize, setWindowSize] = useState(getWindowSize());
|
|
86
|
+
React.useEffect(() => {
|
|
87
|
+
const handleWindowResize = () => {
|
|
88
|
+
setWindowSize(getWindowSize());
|
|
89
|
+
};
|
|
90
|
+
window.addEventListener('resize', handleWindowResize);
|
|
91
|
+
return () => {
|
|
92
|
+
window.removeEventListener('resize', handleWindowResize);
|
|
93
|
+
};
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
// const local = lang && lang === 'en' ? en : vi
|
|
97
|
+
// const dateRangeLocale = lang && lang === 'en' ? enDr : viDr
|
|
98
|
+
|
|
99
|
+
// const buddhistLocale: PickerLocale = {
|
|
100
|
+
// ...local,
|
|
101
|
+
// lang: {
|
|
102
|
+
// ...local.lang
|
|
103
|
+
// }
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
const menuRef = React.useRef(null);
|
|
107
|
+
const viewportWidth = windowSize.innerWidth;
|
|
108
|
+
const viewportHeight = windowSize.innerHeight;
|
|
109
|
+
const [menuVisible, setMenuVisible] = React.useState(false);
|
|
110
|
+
const [selectedRowData, setSelectedRowData] = React.useState(null);
|
|
111
|
+
const [position, setPosition] = React.useState({
|
|
112
|
+
x: 0,
|
|
113
|
+
y: 0,
|
|
114
|
+
viewportWidth,
|
|
115
|
+
viewportHeight
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// const [tooltipContent, setTooltipContent] = useState<any>('')
|
|
119
|
+
|
|
120
|
+
const [filterStates, setFilterState] = React.useState(null);
|
|
121
|
+
const [sorterStates, setSorterStates] = React.useState([]);
|
|
122
|
+
|
|
123
|
+
// const [isFullScreen, setIsFullScreen] = React.useState<boolean>(false)
|
|
124
|
+
|
|
125
|
+
const [expanded, setExpanded] = React.useState({});
|
|
126
|
+
const convertData = React.useMemo(() => {
|
|
127
|
+
if (groupAble && groupSetting && groupSetting.client !== false) {
|
|
128
|
+
return groupArrayByColumns(dataSource, groupColumns);
|
|
129
|
+
}
|
|
130
|
+
return addRowIdArray(dataSource);
|
|
131
|
+
}, [dataSource, groupAble, groupColumns, groupSetting]);
|
|
132
|
+
const mergedColumns = React.useMemo(() => {
|
|
133
|
+
return convertToTanStackColumns({
|
|
134
|
+
columns,
|
|
135
|
+
expanded,
|
|
136
|
+
setExpanded,
|
|
137
|
+
expandable,
|
|
138
|
+
format,
|
|
139
|
+
editAble
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// return convertToTanStackColumns<RecordType>(columns, expanded, setExpanded, expandable)
|
|
143
|
+
}, [columns, expanded, expandable, format, editAble]);
|
|
144
|
+
const columnPinning = React.useMemo(() => {
|
|
145
|
+
return {
|
|
146
|
+
left: getFixedFields(columns, 'left'),
|
|
147
|
+
right: getFixedFields(columns, 'right')
|
|
148
|
+
};
|
|
149
|
+
}, [columns]);
|
|
150
|
+
|
|
151
|
+
// ========================= Keys =========================
|
|
152
|
+
const [mergedFilterKeys, setMergedFilterKeys] = useMergedState(getAllRowKey(convertData), {
|
|
153
|
+
value: undefined
|
|
154
|
+
});
|
|
155
|
+
const mergedData = React.useMemo(() => {
|
|
156
|
+
return filterDataByColumns(convertData, filterStates, sorterStates, mergedFilterKeys);
|
|
157
|
+
}, [convertData, filterStates, mergedFilterKeys, sorterStates]);
|
|
158
|
+
const columnVisibility = React.useMemo(() => {
|
|
159
|
+
return getInvisibleColumns(columns);
|
|
160
|
+
}, [columns]);
|
|
161
|
+
const contextMenuItems = React.useMemo(() => {
|
|
162
|
+
if (typeof contextMenuHidden === 'function' && propContextMenuItems && selectedRowData) {
|
|
163
|
+
const hiddenItems = contextMenuHidden({
|
|
164
|
+
rowInfo: {
|
|
165
|
+
rowData: selectedRowData
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
return propContextMenuItems.filter(item => !hiddenItems.includes(item?.key));
|
|
169
|
+
}
|
|
170
|
+
if (contextMenuHidden && typeof contextMenuHidden !== 'function' && propContextMenuItems) {
|
|
171
|
+
return propContextMenuItems.filter(item => !contextMenuHidden.includes(item?.key));
|
|
172
|
+
}
|
|
173
|
+
return propContextMenuItems;
|
|
174
|
+
}, [propContextMenuItems, contextMenuHidden, selectedRowData]);
|
|
175
|
+
|
|
176
|
+
// const [columns, setColumns] = React.useState<any[]>([])
|
|
177
|
+
|
|
178
|
+
// React.useEffect(() => {
|
|
179
|
+
// setColumns(propsColumns)
|
|
180
|
+
// }, [propsColumns])
|
|
181
|
+
|
|
182
|
+
// const triggerFilter = (queries: any[]) => {
|
|
183
|
+
|
|
184
|
+
// if (onFilter) {
|
|
185
|
+
// onFilter?.(convertFilters(queries))
|
|
186
|
+
// } else {
|
|
187
|
+
|
|
188
|
+
// setFilterState(convertFilters(queries))
|
|
189
|
+
|
|
190
|
+
// const b = filterDataByColumns(convertData, convertFilters(queries), [], [])
|
|
191
|
+
|
|
192
|
+
// setMergedFilterKeys(getAllRowKey(b))
|
|
193
|
+
|
|
194
|
+
// }
|
|
195
|
+
// }
|
|
196
|
+
|
|
197
|
+
const onContextMenu = data => event => {
|
|
198
|
+
event.preventDefault(); // Ngăn chặn menu mặc định của trình duyệt
|
|
199
|
+
|
|
200
|
+
setSelectedRowData(data);
|
|
201
|
+
contextMenuOpen?.({
|
|
202
|
+
rowInfo: {
|
|
203
|
+
rowData: data
|
|
204
|
+
},
|
|
205
|
+
event
|
|
206
|
+
});
|
|
207
|
+
setMenuVisible(true);
|
|
208
|
+
|
|
209
|
+
// Đợi DOM cập nhật và lấy kích thước menu
|
|
210
|
+
setTimeout(() => {
|
|
211
|
+
const menuElement = menuRef.current; // Lấy menu từ DOM
|
|
212
|
+
const menuWidth = menuElement?.offsetWidth || 200; // Mặc định 200px nếu chưa render
|
|
213
|
+
const menuHeight = menuElement?.offsetHeight; // Mặc định 450px nếu chưa render
|
|
214
|
+
|
|
215
|
+
// Điều chỉnh vị trí menu
|
|
216
|
+
let x = event.clientX;
|
|
217
|
+
let y = event.clientY;
|
|
218
|
+
if (x + menuWidth > viewportWidth) {
|
|
219
|
+
x = x - menuWidth - 10; // Cách cạnh phải 10px
|
|
220
|
+
}
|
|
221
|
+
if (y + menuHeight > viewportHeight) {
|
|
222
|
+
if (y < menuHeight) {
|
|
223
|
+
y = 10;
|
|
224
|
+
} else {
|
|
225
|
+
y = y - 10 - menuHeight; // Cách cạnh dưới 10px
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
setPosition(prevState => ({
|
|
229
|
+
...prevState,
|
|
230
|
+
x,
|
|
231
|
+
y
|
|
232
|
+
}));
|
|
233
|
+
}, 100);
|
|
234
|
+
if (!menuVisible) {
|
|
235
|
+
document.addEventListener(`click`, function onClickOutside(e) {
|
|
236
|
+
const element = e.target;
|
|
237
|
+
const menuContainer = document.querySelector('.popup-context-menu');
|
|
238
|
+
const isInsideContainer = element.closest('.popup-context-menu') && menuContainer;
|
|
239
|
+
if (isInsideContainer) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
setMenuVisible(false);
|
|
243
|
+
setPosition(prevState => ({
|
|
244
|
+
...prevState,
|
|
245
|
+
x: undefined,
|
|
246
|
+
y: undefined
|
|
247
|
+
}));
|
|
248
|
+
document.removeEventListener(`click`, onClickOutside);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// const TableComponent = infiniteScroll ? InfiniteTable : (groupAble ? Group : editAble ? GridEdit : Grid)
|
|
254
|
+
const TableComponent = editAble ? GridEdit : Grid;
|
|
255
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(TableComponent, _extends({}, rest, {
|
|
256
|
+
t: t,
|
|
257
|
+
id: id,
|
|
258
|
+
prefix: prefix,
|
|
259
|
+
originData: convertData,
|
|
260
|
+
dataSource: mergedData,
|
|
261
|
+
locale: locale,
|
|
262
|
+
format: format,
|
|
263
|
+
columns: mergedColumns,
|
|
264
|
+
propsColumns: columns,
|
|
265
|
+
rowKey: rowKey,
|
|
266
|
+
groupSetting: groupSetting,
|
|
267
|
+
groupAble: groupAble,
|
|
268
|
+
groupColumns: groupColumns,
|
|
269
|
+
isFullScreen: false,
|
|
270
|
+
columnPinning: columnPinning,
|
|
271
|
+
columnVisibility: columnVisibility,
|
|
272
|
+
triggerFilter: setFilterState,
|
|
273
|
+
triggerSorter: setSorterStates,
|
|
274
|
+
setMergedFilterKeys: setMergedFilterKeys,
|
|
275
|
+
mergedFilterKeys: mergedFilterKeys,
|
|
276
|
+
expanded: expanded,
|
|
277
|
+
onContextMenu: onContextMenu,
|
|
278
|
+
contextMenuItems: contextMenuItems,
|
|
279
|
+
editAble: editAble
|
|
280
|
+
})), menuVisible && /*#__PURE__*/React.createElement(ContextMenu, {
|
|
281
|
+
open: menuVisible,
|
|
282
|
+
pos: position,
|
|
283
|
+
setOpen: setMenuVisible,
|
|
284
|
+
menuRef: menuRef,
|
|
285
|
+
contextMenuItems: contextMenuItems,
|
|
286
|
+
contextMenuClick: contextMenuClick,
|
|
287
|
+
rowData: selectedRowData
|
|
288
|
+
}), /*#__PURE__*/React.createElement(Tooltip, {
|
|
289
|
+
id: `${id}-tooltip-header-trigger`,
|
|
290
|
+
style: {
|
|
291
|
+
zIndex: 1999
|
|
292
|
+
}
|
|
293
|
+
}));
|
|
294
|
+
};
|
|
295
|
+
export default InternalTable;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { Table } from '@tanstack/react-table';
|
|
4
|
+
import type { TableProps } from './type';
|
|
5
|
+
type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
|
+
table: Table<T>;
|
|
7
|
+
prefix: string;
|
|
8
|
+
id: string;
|
|
9
|
+
rowKey: any;
|
|
10
|
+
originData: T[];
|
|
11
|
+
setIsSelectionChange: Dispatch<SetStateAction<{
|
|
12
|
+
isChange: boolean;
|
|
13
|
+
type: string;
|
|
14
|
+
rowData: T;
|
|
15
|
+
}>>;
|
|
16
|
+
setSorterChange: Dispatch<SetStateAction<boolean>>;
|
|
17
|
+
setFilterChange: Dispatch<SetStateAction<boolean>>;
|
|
18
|
+
onContextMenu?: (data: T) => (event: any) => void;
|
|
19
|
+
tableHeight?: number;
|
|
20
|
+
};
|
|
21
|
+
declare const TableContainer: <RecordType extends object>(props: TableContainerProps<RecordType>) => React.JSX.Element;
|
|
22
|
+
export default TableContainer;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// import type { Dispatch, SetStateAction } from "react";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import TableHead from "./header/TableHead";
|
|
5
|
+
import { sumSize } from "./hook/utils";
|
|
6
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
import TableBody from "./body/TableBody";
|
|
9
|
+
import { TableContext } from "./useContext";
|
|
10
|
+
const TableContainer = props => {
|
|
11
|
+
const {
|
|
12
|
+
// t,
|
|
13
|
+
table,
|
|
14
|
+
id,
|
|
15
|
+
prefix,
|
|
16
|
+
commandClick,
|
|
17
|
+
editAble,
|
|
18
|
+
rowKey,
|
|
19
|
+
format,
|
|
20
|
+
dataSource,
|
|
21
|
+
originData,
|
|
22
|
+
expandable,
|
|
23
|
+
wrapSettings,
|
|
24
|
+
recordDoubleClick,
|
|
25
|
+
// triggerFilter,
|
|
26
|
+
selectionSettings,
|
|
27
|
+
setIsSelectionChange,
|
|
28
|
+
onContextMenu,
|
|
29
|
+
contextMenuItems,
|
|
30
|
+
setSorterChange,
|
|
31
|
+
setFilterChange,
|
|
32
|
+
tableHeight
|
|
33
|
+
} = props;
|
|
34
|
+
const tableContainerRef = React.useRef(null);
|
|
35
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
36
|
+
const fixedLeftColumns = table.getState().columnPinning.left ? visibleColumns.filter(vc => table.getState().columnPinning.left?.includes(vc.id)) : [];
|
|
37
|
+
const fixedRightColumns = table.getState().columnPinning.right ? visibleColumns.filter(vc => table.getState().columnPinning.right?.includes(vc.id)) : [];
|
|
38
|
+
const columnVirtualizer = useVirtualizer({
|
|
39
|
+
count: visibleColumns.length,
|
|
40
|
+
estimateSize: index => visibleColumns[index].getSize(),
|
|
41
|
+
getScrollElement: () => tableContainerRef.current,
|
|
42
|
+
horizontal: true,
|
|
43
|
+
measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element?.getBoundingClientRect().height : undefined,
|
|
44
|
+
overscan: 3 //how many columns to render on each side off screen each way (adjust this for performance)
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// const columnSizingState = table.getState().columnSizing
|
|
48
|
+
|
|
49
|
+
// React.useEffect(() => {
|
|
50
|
+
// requestAnimationFrame(() => {
|
|
51
|
+
// columnVirtualizer.measure()
|
|
52
|
+
// })
|
|
53
|
+
// }, [columnSizingState, columnVirtualizer])
|
|
54
|
+
|
|
55
|
+
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
56
|
+
const cacheColumns = columnVirtualizer.measurementsCache;
|
|
57
|
+
const rightCols = table.getState().columnPinning.right?.length ? [...cacheColumns].slice(-(table.getState().columnPinning.right?.length ?? 0)) : [];
|
|
58
|
+
const leftCols = [...cacheColumns].slice(0, table.getState().columnPinning.left?.length ?? 0);
|
|
59
|
+
const rightWidth = sumSize(rightCols);
|
|
60
|
+
const leftWidth = sumSize(leftCols);
|
|
61
|
+
|
|
62
|
+
//different virtualization strategy for columns - instead of absolute and translateY, we add empty columns to the left and right
|
|
63
|
+
let virtualPaddingLeft;
|
|
64
|
+
let virtualPaddingRight;
|
|
65
|
+
const pdRight = columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0);
|
|
66
|
+
if (columnVirtualizer && virtualColumns?.length) {
|
|
67
|
+
virtualPaddingLeft = fixedLeftColumns && fixedLeftColumns.length > 0 ? (virtualColumns[0]?.start ?? 0) - leftWidth > 0 ? (virtualColumns[0]?.start ?? 0) - leftWidth : 0 : virtualColumns[0]?.start ?? 0;
|
|
68
|
+
virtualPaddingRight = fixedRightColumns && fixedRightColumns.length > 0 ? pdRight - rightWidth > 0 ? pdRight - rightWidth : 0 : pdRight;
|
|
69
|
+
}
|
|
70
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
71
|
+
className: classNames(`${prefix}-grid-container`, {
|
|
72
|
+
'ui-rc-table-ping-right': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) >= 0 && (tableContainerRef.current?.scrollLeft ?? 0) + (tableContainerRef.current?.clientWidth ?? 0) < (tableContainerRef.current?.scrollWidth ?? 0),
|
|
73
|
+
'ui-rc-table-ping-left': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) > 0
|
|
74
|
+
}),
|
|
75
|
+
id: id,
|
|
76
|
+
ref: tableContainerRef,
|
|
77
|
+
style: {
|
|
78
|
+
overflow: 'auto',
|
|
79
|
+
//our scrollable table container
|
|
80
|
+
position: 'relative',
|
|
81
|
+
//needed for sticky header
|
|
82
|
+
height: tableHeight ?? '500px' //should be a fixed height
|
|
83
|
+
// minWidth: table.getTotalSize()
|
|
84
|
+
}
|
|
85
|
+
}, /*#__PURE__*/React.createElement(TableContext.Provider, {
|
|
86
|
+
value: {
|
|
87
|
+
prefix,
|
|
88
|
+
id,
|
|
89
|
+
rowKey,
|
|
90
|
+
format,
|
|
91
|
+
expandable,
|
|
92
|
+
dataSource,
|
|
93
|
+
originData,
|
|
94
|
+
// triggerFilter,
|
|
95
|
+
wrapSettings,
|
|
96
|
+
recordDoubleClick,
|
|
97
|
+
selectionSettings,
|
|
98
|
+
setIsSelectionChange,
|
|
99
|
+
onContextMenu,
|
|
100
|
+
setSorterChange,
|
|
101
|
+
setFilterChange
|
|
102
|
+
}
|
|
103
|
+
}, /*#__PURE__*/React.createElement("table", {
|
|
104
|
+
style: {
|
|
105
|
+
display: 'grid',
|
|
106
|
+
minWidth: table.getTotalSize()
|
|
107
|
+
}
|
|
108
|
+
}, /*#__PURE__*/React.createElement(TableHead, {
|
|
109
|
+
tableContainerRef: tableContainerRef,
|
|
110
|
+
columnVirtualizer: columnVirtualizer,
|
|
111
|
+
table: table,
|
|
112
|
+
virtualPaddingLeft: virtualPaddingLeft,
|
|
113
|
+
virtualPaddingRight: virtualPaddingRight,
|
|
114
|
+
fixedLeftColumns: fixedLeftColumns,
|
|
115
|
+
fixedRightColumns: fixedRightColumns
|
|
116
|
+
}), /*#__PURE__*/React.createElement(TableBody, {
|
|
117
|
+
tableId: id,
|
|
118
|
+
columnVirtualizer: columnVirtualizer,
|
|
119
|
+
table: table,
|
|
120
|
+
tableContainerRef: tableContainerRef,
|
|
121
|
+
virtualPaddingLeft: virtualPaddingLeft,
|
|
122
|
+
virtualPaddingRight: virtualPaddingRight,
|
|
123
|
+
fixedLeftColumns: fixedLeftColumns,
|
|
124
|
+
fixedRightColumns: fixedRightColumns,
|
|
125
|
+
commandClick: commandClick,
|
|
126
|
+
editAble: editAble,
|
|
127
|
+
contextMenuItems: contextMenuItems
|
|
128
|
+
}))));
|
|
129
|
+
};
|
|
130
|
+
export default TableContainer;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import type { Table } from "@tanstack/react-table";
|
|
4
|
+
import type { TableProps } from "./type";
|
|
5
|
+
type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
|
+
table: Table<T>;
|
|
7
|
+
prefix: string;
|
|
8
|
+
id: string;
|
|
9
|
+
rowKey: any;
|
|
10
|
+
originData: T[];
|
|
11
|
+
setIsSelectionChange: Dispatch<SetStateAction<{
|
|
12
|
+
isChange: boolean;
|
|
13
|
+
type: string;
|
|
14
|
+
rowData: T;
|
|
15
|
+
}>>;
|
|
16
|
+
setSorterChange: Dispatch<SetStateAction<boolean>>;
|
|
17
|
+
setFilterChange: Dispatch<SetStateAction<boolean>>;
|
|
18
|
+
onContextMenu?: (data: T) => (event: any) => void;
|
|
19
|
+
tableHeight?: number;
|
|
20
|
+
triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
|
|
21
|
+
triggerChangeData?: (newData: T[], type: string) => void;
|
|
22
|
+
mergedFilterKeys: any;
|
|
23
|
+
setMergedFilterKeys: any;
|
|
24
|
+
setExpanded: any;
|
|
25
|
+
expanded: any;
|
|
26
|
+
};
|
|
27
|
+
declare const TableContainerEdit: <RecordType extends object>(props: TableContainerProps<RecordType>) => React.JSX.Element;
|
|
28
|
+
export default TableContainerEdit;
|