es-grid-template 1.8.64 → 1.8.65
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/ColumnsGroup/ColumnsGroup.js +4 -1
- package/es/grid-component/TempTable.js +2 -2
- package/es/grid-component/hooks/utils.d.ts +2 -8
- package/es/grid-component/hooks/utils.js +175 -144
- package/es/grid-component/index.d.ts +1 -1
- package/es/grid-component/index.js +0 -4
- package/es/grid-component/type.d.ts +7 -0
- package/es/table-component/type.d.ts +8 -0
- package/es/table-virtuoso/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/es/table-virtuoso/ColumnsGroup/ColumnsGroup.js +232 -0
- package/es/table-virtuoso/ColumnsGroup/index.d.ts +1 -0
- package/es/table-virtuoso/ColumnsGroup/index.js +1 -0
- package/es/{grid-component → table-virtuoso}/InternalTable.d.ts +2 -3
- package/es/table-virtuoso/InternalTable.js +413 -0
- package/es/table-virtuoso/body/TableBody.d.ts +14 -0
- package/es/table-virtuoso/body/TableBody.js +84 -0
- package/es/table-virtuoso/body/TableBodyCell.d.ts +14 -0
- package/es/table-virtuoso/body/TableBodyCell.js +466 -0
- package/es/table-virtuoso/body/TableBodyRow.d.ts +13 -0
- package/es/table-virtuoso/body/TableBodyRow.js +116 -0
- package/es/table-virtuoso/footer/TableFooterCell.d.ts +7 -0
- package/es/table-virtuoso/footer/TableFooterCell.js +54 -0
- package/es/table-virtuoso/header/TableHeadCell.d.ts +14 -0
- package/es/table-virtuoso/header/TableHeadCell.js +265 -0
- package/es/table-virtuoso/header/renderFilter.d.ts +20 -0
- package/es/table-virtuoso/header/renderFilter.js +289 -0
- package/es/table-virtuoso/hook/constant.d.ts +73 -0
- package/es/table-virtuoso/hook/constant.js +240 -0
- package/es/table-virtuoso/hook/convert.d.ts +1 -0
- package/es/table-virtuoso/hook/convert.js +28 -0
- package/es/table-virtuoso/hook/useColumns.d.ts +28 -0
- package/es/table-virtuoso/hook/useColumns.js +302 -0
- package/es/table-virtuoso/hook/useFilterOperator.d.ts +7 -0
- package/es/table-virtuoso/hook/useFilterOperator.js +33 -0
- package/es/table-virtuoso/hook/utils.d.ts +159 -0
- package/es/table-virtuoso/hook/utils.js +2263 -0
- package/es/table-virtuoso/index.d.ts +2 -0
- package/es/table-virtuoso/index.js +2 -0
- package/es/table-virtuoso/style.d.ts +22 -0
- package/es/table-virtuoso/style.js +11 -0
- package/es/table-virtuoso/style.scss +1440 -0
- package/es/table-virtuoso/table/Grid.d.ts +37 -0
- package/es/table-virtuoso/table/Grid.js +302 -0
- package/es/table-virtuoso/table/TableContainer.d.ts +49 -0
- package/es/table-virtuoso/table/TableContainer.js +305 -0
- package/es/table-virtuoso/table/TableWrapper.d.ts +20 -0
- package/es/table-virtuoso/table/TableWrapper.js +158 -0
- package/es/table-virtuoso/type.d.ts +0 -0
- package/es/table-virtuoso/type.js +785 -0
- package/es/table-virtuoso/useContext.d.ts +97 -0
- package/es/table-virtuoso/useContext.js +21 -0
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +4 -1
- package/lib/grid-component/TempTable.js +2 -2
- package/lib/grid-component/hooks/utils.d.ts +2 -8
- package/lib/grid-component/hooks/utils.js +176 -152
- package/lib/grid-component/index.d.ts +1 -1
- package/lib/grid-component/index.js +0 -3
- package/lib/grid-component/type.d.ts +7 -0
- package/lib/table-component/type.d.ts +8 -0
- package/lib/table-virtuoso/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/lib/table-virtuoso/ColumnsGroup/ColumnsGroup.js +243 -0
- package/lib/table-virtuoso/ColumnsGroup/index.d.ts +1 -0
- package/lib/table-virtuoso/ColumnsGroup/index.js +16 -0
- package/lib/{grid-component → table-virtuoso}/InternalTable.d.ts +2 -3
- package/lib/table-virtuoso/InternalTable.js +422 -0
- package/lib/table-virtuoso/body/TableBody.d.ts +14 -0
- package/lib/table-virtuoso/body/TableBody.js +95 -0
- package/lib/table-virtuoso/body/TableBodyCell.d.ts +14 -0
- package/lib/table-virtuoso/body/TableBodyCell.js +473 -0
- package/lib/table-virtuoso/body/TableBodyRow.d.ts +13 -0
- package/lib/table-virtuoso/body/TableBodyRow.js +124 -0
- package/lib/table-virtuoso/footer/TableFooterCell.d.ts +7 -0
- package/lib/table-virtuoso/footer/TableFooterCell.js +63 -0
- package/lib/table-virtuoso/header/TableHeadCell.d.ts +14 -0
- package/lib/table-virtuoso/header/TableHeadCell.js +274 -0
- package/lib/table-virtuoso/header/renderFilter.d.ts +20 -0
- package/lib/table-virtuoso/header/renderFilter.js +299 -0
- package/lib/table-virtuoso/hook/constant.d.ts +73 -0
- package/lib/table-virtuoso/hook/constant.js +247 -0
- package/lib/table-virtuoso/hook/convert.d.ts +1 -0
- package/lib/table-virtuoso/hook/convert.js +34 -0
- package/lib/table-virtuoso/hook/useColumns.d.ts +28 -0
- package/lib/table-virtuoso/hook/useColumns.js +315 -0
- package/lib/table-virtuoso/hook/useFilterOperator.d.ts +7 -0
- package/lib/table-virtuoso/hook/useFilterOperator.js +40 -0
- package/lib/table-virtuoso/hook/utils.d.ts +159 -0
- package/lib/table-virtuoso/hook/utils.js +2389 -0
- package/lib/table-virtuoso/index.d.ts +2 -0
- package/lib/table-virtuoso/index.js +9 -0
- package/lib/table-virtuoso/style.d.ts +22 -0
- package/lib/table-virtuoso/style.js +18 -0
- package/lib/table-virtuoso/style.scss +1440 -0
- package/lib/table-virtuoso/table/Grid.d.ts +37 -0
- package/lib/table-virtuoso/table/Grid.js +311 -0
- package/lib/table-virtuoso/table/TableContainer.d.ts +49 -0
- package/lib/table-virtuoso/table/TableContainer.js +313 -0
- package/lib/table-virtuoso/table/TableWrapper.d.ts +20 -0
- package/lib/table-virtuoso/table/TableWrapper.js +164 -0
- package/lib/table-virtuoso/type.d.ts +0 -0
- package/lib/table-virtuoso/type.js +786 -0
- package/lib/table-virtuoso/useContext.d.ts +97 -0
- package/lib/table-virtuoso/useContext.js +27 -0
- package/package.json +2 -1
- package/es/grid-component/ConvertColumnTable.d.ts +0 -7
- package/es/grid-component/ConvertColumnTable.js +0 -144
- package/es/grid-component/InternalTable.js +0 -1170
- package/es/grid-component/table/Grid.d.ts +0 -23
- package/es/grid-component/table/Grid.js +0 -49
- package/es/grid-component/table/GridEdit.d.ts +0 -23
- package/es/grid-component/table/GridEdit.js +0 -2726
- package/es/grid-component/table/Group.d.ts +0 -21
- package/es/grid-component/table/Group.js +0 -195
- package/es/grid-component/table/InfiniteTable.d.ts +0 -23
- package/es/grid-component/table/InfiniteTable.js +0 -101
- package/lib/grid-component/ConvertColumnTable.d.ts +0 -7
- package/lib/grid-component/ConvertColumnTable.js +0 -153
- package/lib/grid-component/InternalTable.js +0 -1178
- package/lib/grid-component/table/Grid.d.ts +0 -23
- package/lib/grid-component/table/Grid.js +0 -58
- package/lib/grid-component/table/GridEdit.d.ts +0 -23
- package/lib/grid-component/table/GridEdit.js +0 -2723
- package/lib/grid-component/table/Group.d.ts +0 -21
- package/lib/grid-component/table/Group.js +0 -204
- package/lib/grid-component/table/InfiniteTable.d.ts +0 -23
- package/lib/grid-component/table/InfiniteTable.js +0 -109
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ColumnDef, ColumnFiltersState, ColumnPinningState, ColumnSizingInfoState, ColumnSizingState, ExpandedState, Table, VisibilityState } from '@tanstack/react-table';
|
|
2
|
+
import type { ColumnsTable, Sorter, TableProps } from '../../table-component/type';
|
|
3
|
+
import type { Dispatch, Key, SetStateAction } from 'react';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
type Props<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
|
+
id: string;
|
|
7
|
+
table: Table<T>;
|
|
8
|
+
rowKey: string;
|
|
9
|
+
prefix: string;
|
|
10
|
+
columns: ColumnDef<T>[];
|
|
11
|
+
propsColumns: ColumnsTable<T>;
|
|
12
|
+
setColumns: Dispatch<SetStateAction<ColumnsTable<T>>>;
|
|
13
|
+
columnHidden: VisibilityState;
|
|
14
|
+
expanded: ExpandedState;
|
|
15
|
+
setExpanded: any;
|
|
16
|
+
columnPinning: ColumnPinningState;
|
|
17
|
+
originData: T[];
|
|
18
|
+
mergedFilterKeys: any;
|
|
19
|
+
setMergedFilterKeys: any;
|
|
20
|
+
isFullScreen: boolean;
|
|
21
|
+
setIsFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
22
|
+
triggerFilter: (args: any) => void;
|
|
23
|
+
triggerSorter: (args: Sorter[]) => void;
|
|
24
|
+
onContextMenu?: (data: T) => (event: any) => void;
|
|
25
|
+
triggerChangeColumns?: (args: any, keys: any, type: string) => void;
|
|
26
|
+
triggerGroupColumns?: (groupedColumns: string[]) => void;
|
|
27
|
+
windowSize: any;
|
|
28
|
+
isDataTree: boolean;
|
|
29
|
+
mergedSelectedKeys: Key[];
|
|
30
|
+
setColumnSizing: Dispatch<SetStateAction<any>>;
|
|
31
|
+
columnSizingInfo: ColumnSizingInfoState;
|
|
32
|
+
columnSizing: ColumnSizingState;
|
|
33
|
+
columnFilters: ColumnFiltersState;
|
|
34
|
+
setColumnOrder?: Dispatch<SetStateAction<string[]>>;
|
|
35
|
+
};
|
|
36
|
+
declare const Grid: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
37
|
+
export default Grid;
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { Modal } from 'antd';
|
|
3
|
+
import { faker } from '@faker-js/faker';
|
|
4
|
+
import { DndContext, KeyboardSensor, MouseSensor, TouchSensor, closestCenter, useSensor, useSensors } from '@dnd-kit/core';
|
|
5
|
+
import { restrictToHorizontalAxis } from '@dnd-kit/modifiers';
|
|
6
|
+
import { arrayMove } from '@dnd-kit/sortable';
|
|
7
|
+
import React, { Fragment } from 'react';
|
|
8
|
+
import { convertFilters, filterByIds, filterDataByColumns, getAllRowKey } from "../hook/utils";
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import TableContainer from "./TableContainer";
|
|
11
|
+
import { GridStyle } from "../style";
|
|
12
|
+
const Grid = props => {
|
|
13
|
+
const {
|
|
14
|
+
theme,
|
|
15
|
+
t,
|
|
16
|
+
id,
|
|
17
|
+
prefix,
|
|
18
|
+
dataSource,
|
|
19
|
+
originData,
|
|
20
|
+
columns,
|
|
21
|
+
propsColumns,
|
|
22
|
+
setColumns,
|
|
23
|
+
pagination,
|
|
24
|
+
expanded,
|
|
25
|
+
setExpanded,
|
|
26
|
+
columnHidden,
|
|
27
|
+
columnPinning,
|
|
28
|
+
selectionSettings,
|
|
29
|
+
rowSelected,
|
|
30
|
+
sortMultiple,
|
|
31
|
+
triggerSorter,
|
|
32
|
+
triggerFilter,
|
|
33
|
+
setMergedFilterKeys,
|
|
34
|
+
onSorter,
|
|
35
|
+
onFilter,
|
|
36
|
+
allowFiltering,
|
|
37
|
+
allowSortering,
|
|
38
|
+
// groupColumns,
|
|
39
|
+
// height= 700,
|
|
40
|
+
height,
|
|
41
|
+
minHeight,
|
|
42
|
+
editAble,
|
|
43
|
+
triggerChangeColumns,
|
|
44
|
+
infiniteScroll,
|
|
45
|
+
mergedSelectedKeys,
|
|
46
|
+
allowResizing,
|
|
47
|
+
windowSize,
|
|
48
|
+
table,
|
|
49
|
+
columnSizing,
|
|
50
|
+
columnSizingInfo,
|
|
51
|
+
setColumnSizing,
|
|
52
|
+
columnFilters,
|
|
53
|
+
setColumnOrder,
|
|
54
|
+
rowSelection,
|
|
55
|
+
...rest
|
|
56
|
+
} = props;
|
|
57
|
+
|
|
58
|
+
// const [columnResizeMode] = React.useState<ColumnResizeMode>('onChange')
|
|
59
|
+
|
|
60
|
+
// const [columnResizeDirection] = React.useState<ColumnResizeDirection>('ltr')
|
|
61
|
+
|
|
62
|
+
// const [paginationState, setPagination] = React.useState<PaginationState>({
|
|
63
|
+
// pageIndex: pagination && pagination.currentPage ? pagination.currentPage - 1 : 0,
|
|
64
|
+
// pageSize: pagination && pagination.pageSize ? pagination.pageSize : 20
|
|
65
|
+
// })
|
|
66
|
+
|
|
67
|
+
// const [rowSelection, setRowSelection] = React.useState<RowSelectionState>({})
|
|
68
|
+
|
|
69
|
+
// const [grouping, setGrouping] = React.useState<GroupingState>([])
|
|
70
|
+
|
|
71
|
+
// const [columnSizing, setColumnSizing] = React.useState<ColumnSizingState>({})
|
|
72
|
+
// const [columnSizingInfo, setColumnSizingInfo] = React.useState<ColumnSizingInfoState>({} as ColumnSizingInfoState)
|
|
73
|
+
|
|
74
|
+
// const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([])
|
|
75
|
+
|
|
76
|
+
// const [operator, setOperator] = React.useState<ColumnOperatorState>([])
|
|
77
|
+
// const [sorting, setSorting] = React.useState<SortingState>([])
|
|
78
|
+
|
|
79
|
+
// const [columnOrder, setColumnOrder] = React.useState<string[]>(() => columns.map(c => c.id!))
|
|
80
|
+
|
|
81
|
+
const [isSelectionChange, setIsSelectionChange] = React.useState({
|
|
82
|
+
isChange: false,
|
|
83
|
+
type: '',
|
|
84
|
+
rowData: {},
|
|
85
|
+
rowsData: []
|
|
86
|
+
});
|
|
87
|
+
const [sorterChange, setSorterChange] = React.useState(false);
|
|
88
|
+
const [filterChange, setFilterChange] = React.useState(false);
|
|
89
|
+
const [isFullScreen, setIsFullScreen] = React.useState(false);
|
|
90
|
+
|
|
91
|
+
// React.useEffect(() => {
|
|
92
|
+
|
|
93
|
+
// const isEqual = isObjEqual(convertToObjTrue(mergedSelectedKeys), rowSelection)
|
|
94
|
+
|
|
95
|
+
// if (!isEqual) {
|
|
96
|
+
|
|
97
|
+
// setRowSelection(convertToObjTrue(mergedSelectedKeys))
|
|
98
|
+
// }
|
|
99
|
+
|
|
100
|
+
// }, [mergedSelectedKeys])
|
|
101
|
+
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
if (isSelectionChange.isChange) {
|
|
104
|
+
const aa = table.getState().rowSelection;
|
|
105
|
+
const ids = Object.keys(aa);
|
|
106
|
+
const ssss = filterByIds(ids, isSelectionChange.rowsData ?? []); // lấy rowsData của trang hiện tại
|
|
107
|
+
|
|
108
|
+
const rs = ssss.map(it => it.original);
|
|
109
|
+
rowSelected?.({
|
|
110
|
+
type: isSelectionChange.type,
|
|
111
|
+
rowData: isSelectionChange.rowData,
|
|
112
|
+
selected: rs
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, [isSelectionChange, rowSelection, table.getState().rowSelection]);
|
|
116
|
+
React.useEffect(() => {
|
|
117
|
+
if (sorterChange) {
|
|
118
|
+
console.log('12312312313123');
|
|
119
|
+
const aa = table.getState().sorting;
|
|
120
|
+
const rs = aa.map(it => {
|
|
121
|
+
return {
|
|
122
|
+
columnKey: it.id,
|
|
123
|
+
field: it.id,
|
|
124
|
+
order: it.desc ? 'descend' : 'ascend'
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
if (onSorter) {
|
|
128
|
+
onSorter?.(rs);
|
|
129
|
+
} else {
|
|
130
|
+
triggerSorter(rs);
|
|
131
|
+
}
|
|
132
|
+
setSorterChange(false);
|
|
133
|
+
}
|
|
134
|
+
}, [onSorter, sorterChange, table, triggerSorter]);
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
if (filterChange) {
|
|
137
|
+
const operatorState = table.getState().operator;
|
|
138
|
+
console.log('operatorState', operatorState);
|
|
139
|
+
const merged = columnFilters.map(filter => {
|
|
140
|
+
const match = operatorState.find(op => op.id === filter.id);
|
|
141
|
+
const col = table.getVisibleFlatColumns().find(it => it.id === filter.id)?.columnDef.meta;
|
|
142
|
+
return {
|
|
143
|
+
field: filter.id,
|
|
144
|
+
key: filter.id,
|
|
145
|
+
column: col,
|
|
146
|
+
filteredKeys: filter.value,
|
|
147
|
+
operator: match ? match.operator : undefined
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
console.log('operatorState', operatorState);
|
|
151
|
+
console.log('merged', merged);
|
|
152
|
+
if (onFilter) {
|
|
153
|
+
onFilter?.(convertFilters(merged));
|
|
154
|
+
} else {
|
|
155
|
+
triggerFilter(convertFilters(merged));
|
|
156
|
+
const b = filterDataByColumns(originData, convertFilters(merged), [], []);
|
|
157
|
+
setMergedFilterKeys(getAllRowKey(b));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}, [filterChange, onFilter, originData, setMergedFilterKeys, table, triggerFilter, columnFilters]);
|
|
161
|
+
|
|
162
|
+
// reorder columns after drag & drop
|
|
163
|
+
function handleDragEnd(event) {
|
|
164
|
+
const {
|
|
165
|
+
active,
|
|
166
|
+
over
|
|
167
|
+
} = event;
|
|
168
|
+
if (active && over && active.id !== over.id) {
|
|
169
|
+
setColumnOrder?.(cols => {
|
|
170
|
+
const oldIndex = cols.indexOf(active.id);
|
|
171
|
+
const newIndex = cols.indexOf(over.id);
|
|
172
|
+
return arrayMove(cols, oldIndex, newIndex); //this is just a splice util
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}));
|
|
177
|
+
const ContainerComponent = TableContainer;
|
|
178
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
|
|
179
|
+
$prefix: prefix,
|
|
180
|
+
$theme: {
|
|
181
|
+
theme: theme?.theme,
|
|
182
|
+
...theme
|
|
183
|
+
},
|
|
184
|
+
className: classNames(`${prefix}-grid`, {
|
|
185
|
+
[`${prefix}-grid-light`]: !theme || theme.theme === 'light',
|
|
186
|
+
[`${prefix}-grid-dark`]: theme?.theme === 'dark'
|
|
187
|
+
}),
|
|
188
|
+
style: {
|
|
189
|
+
minHeight: minHeight ?? undefined,
|
|
190
|
+
maxHeight: height ?? undefined,
|
|
191
|
+
backgroundColor: theme?.backgroundColor ?? undefined
|
|
192
|
+
}
|
|
193
|
+
}, /*#__PURE__*/React.createElement(DndContext, {
|
|
194
|
+
collisionDetection: closestCenter,
|
|
195
|
+
modifiers: [restrictToHorizontalAxis],
|
|
196
|
+
onDragEnd: handleDragEnd,
|
|
197
|
+
sensors: sensors
|
|
198
|
+
}, /*#__PURE__*/React.createElement(ContainerComponent, _extends({}, rest, {
|
|
199
|
+
id: id,
|
|
200
|
+
t: t,
|
|
201
|
+
windowSize: windowSize,
|
|
202
|
+
table: table,
|
|
203
|
+
editAble: editAble,
|
|
204
|
+
dataSource: dataSource,
|
|
205
|
+
originData: originData,
|
|
206
|
+
prefix: prefix,
|
|
207
|
+
selectionSettings: selectionSettings,
|
|
208
|
+
isSelectionChange: isSelectionChange,
|
|
209
|
+
setIsSelectionChange: setIsSelectionChange,
|
|
210
|
+
setSorterChange: setSorterChange,
|
|
211
|
+
setFilterChange: setFilterChange,
|
|
212
|
+
height: height ?? minHeight ?? 700,
|
|
213
|
+
minHeight: minHeight,
|
|
214
|
+
pagination: pagination,
|
|
215
|
+
columns: columns,
|
|
216
|
+
propsColumns: propsColumns,
|
|
217
|
+
triggerChangeColumns: triggerChangeColumns,
|
|
218
|
+
columnHidden: columnHidden,
|
|
219
|
+
setExpanded: setExpanded,
|
|
220
|
+
expanded: expanded,
|
|
221
|
+
infiniteScroll: infiniteScroll,
|
|
222
|
+
setMergedFilterKeys: setMergedFilterKeys,
|
|
223
|
+
setColumnSizing: setColumnSizing,
|
|
224
|
+
setColumns: setColumns,
|
|
225
|
+
columnSizing: columnSizing,
|
|
226
|
+
columnSizingInfo: columnSizingInfo,
|
|
227
|
+
isFullScreen: isFullScreen,
|
|
228
|
+
setIsFullScreen: setIsFullScreen
|
|
229
|
+
})))), /*#__PURE__*/React.createElement(Modal, {
|
|
230
|
+
open: isFullScreen,
|
|
231
|
+
footer: null,
|
|
232
|
+
centered: true,
|
|
233
|
+
closable: true,
|
|
234
|
+
width: '100%',
|
|
235
|
+
style: {
|
|
236
|
+
maxWidth: '100%',
|
|
237
|
+
height: '100%'
|
|
238
|
+
},
|
|
239
|
+
onCancel: () => setIsFullScreen(false),
|
|
240
|
+
styles: {
|
|
241
|
+
content: {
|
|
242
|
+
height: '100vh',
|
|
243
|
+
borderRadius: 0,
|
|
244
|
+
padding: '15px 10px'
|
|
245
|
+
},
|
|
246
|
+
wrapper: {
|
|
247
|
+
zIndex: 1050
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
destroyOnClose: true
|
|
251
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
252
|
+
style: {
|
|
253
|
+
paddingTop: 40
|
|
254
|
+
}
|
|
255
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
256
|
+
className: classNames(`${prefix}-grid`, {
|
|
257
|
+
[`${prefix}-grid-light`]: !theme || theme.theme === 'light',
|
|
258
|
+
[`${prefix}-grid-dark`]: theme?.theme === 'dark'
|
|
259
|
+
}),
|
|
260
|
+
style: {
|
|
261
|
+
// minHeight: minHeight ?? undefined,
|
|
262
|
+
maxHeight: windowSize.innerHeight - 70
|
|
263
|
+
}
|
|
264
|
+
}, /*#__PURE__*/React.createElement(DndContext, {
|
|
265
|
+
collisionDetection: closestCenter,
|
|
266
|
+
modifiers: [restrictToHorizontalAxis],
|
|
267
|
+
onDragEnd: handleDragEnd,
|
|
268
|
+
sensors: sensors
|
|
269
|
+
}, /*#__PURE__*/React.createElement(ContainerComponent, _extends({}, rest, {
|
|
270
|
+
id: faker.string.alpha(20),
|
|
271
|
+
t: t,
|
|
272
|
+
table: table,
|
|
273
|
+
editAble: editAble,
|
|
274
|
+
dataSource: dataSource,
|
|
275
|
+
originData: originData,
|
|
276
|
+
prefix: prefix,
|
|
277
|
+
selectionSettings: selectionSettings,
|
|
278
|
+
isSelectionChange: isSelectionChange,
|
|
279
|
+
setIsSelectionChange: setIsSelectionChange,
|
|
280
|
+
setSorterChange: setSorterChange,
|
|
281
|
+
setFilterChange: setFilterChange,
|
|
282
|
+
height: windowSize.innerHeight - 70,
|
|
283
|
+
minHeight: minHeight,
|
|
284
|
+
pagination: pagination,
|
|
285
|
+
columns: columns,
|
|
286
|
+
windowSize: windowSize,
|
|
287
|
+
propsColumns: propsColumns,
|
|
288
|
+
triggerChangeColumns: triggerChangeColumns,
|
|
289
|
+
columnHidden: columnHidden,
|
|
290
|
+
setExpanded: setExpanded,
|
|
291
|
+
expanded: expanded,
|
|
292
|
+
infiniteScroll: infiniteScroll,
|
|
293
|
+
setMergedFilterKeys: setMergedFilterKeys,
|
|
294
|
+
setColumns: setColumns,
|
|
295
|
+
isFullScreen: isFullScreen,
|
|
296
|
+
setIsFullScreen: setIsFullScreen,
|
|
297
|
+
setColumnSizing: setColumnSizing,
|
|
298
|
+
columnSizing: columnSizing,
|
|
299
|
+
columnSizingInfo: columnSizingInfo
|
|
300
|
+
})))))));
|
|
301
|
+
};
|
|
302
|
+
export default Grid;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { ColumnDef, ColumnSizingInfoState, ColumnSizingState, Table } from '@tanstack/react-table';
|
|
4
|
+
import type { ColumnsTable, TableProps } from '../../table-component/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
|
+
isSelectionChange?: {
|
|
12
|
+
isChange: boolean;
|
|
13
|
+
type: string;
|
|
14
|
+
rowData: T;
|
|
15
|
+
rowsData: T[];
|
|
16
|
+
};
|
|
17
|
+
setIsSelectionChange: Dispatch<SetStateAction<{
|
|
18
|
+
isChange: boolean;
|
|
19
|
+
type: string;
|
|
20
|
+
rowData: T;
|
|
21
|
+
rowsData: T[];
|
|
22
|
+
}>>;
|
|
23
|
+
setSorterChange: Dispatch<SetStateAction<boolean>>;
|
|
24
|
+
setFilterChange: Dispatch<SetStateAction<boolean>>;
|
|
25
|
+
onContextMenu?: (data: T) => (event: any) => void;
|
|
26
|
+
windowSize: {
|
|
27
|
+
innerHeight: number;
|
|
28
|
+
innerWidth: number;
|
|
29
|
+
};
|
|
30
|
+
triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
|
|
31
|
+
mergedFilterKeys?: any;
|
|
32
|
+
setMergedFilterKeys?: any;
|
|
33
|
+
setExpanded?: any;
|
|
34
|
+
expanded?: any;
|
|
35
|
+
columns: ColumnDef<T>[];
|
|
36
|
+
propsColumns: ColumnsTable;
|
|
37
|
+
triggerChangeColumns: any;
|
|
38
|
+
columnHidden: any;
|
|
39
|
+
isFullScreen: boolean;
|
|
40
|
+
setIsFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
41
|
+
isDataTree: boolean;
|
|
42
|
+
setColumnSizing: Dispatch<SetStateAction<any>>;
|
|
43
|
+
setColumns: Dispatch<SetStateAction<any>>;
|
|
44
|
+
columnSizingInfo: ColumnSizingInfoState;
|
|
45
|
+
columnSizing: ColumnSizingState;
|
|
46
|
+
triggerGroupColumns?: (groupedColumns: string[]) => void;
|
|
47
|
+
};
|
|
48
|
+
declare const TableContainer: <RecordType extends object>(props: TableContainerProps<RecordType>) => React.JSX.Element;
|
|
49
|
+
export default TableContainer;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
// import type { Dispatch, SetStateAction } from 'react'
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import classNames from 'classnames';
|
|
6
|
+
import Pagination from 'rc-master-ui/es/pagination';
|
|
7
|
+
import { Toolbar } from 'rc-master-ui';
|
|
8
|
+
import { Maximize, Minimize } from 'becoxy-icons';
|
|
9
|
+
import { numericFormatter } from 'react-numeric-component';
|
|
10
|
+
import TableWrapper from "./TableWrapper";
|
|
11
|
+
import { ColumnsChoose } from "../../table-component/ColumnsChoose";
|
|
12
|
+
import { getTableHeight } from "../hook/utils";
|
|
13
|
+
import { TableContext } from "../useContext";
|
|
14
|
+
// import { ColumnsGroup } from '../../grid-component/ColumnsGroup';
|
|
15
|
+
import { flatColumns2 } from "../../table-component/hook/utils";
|
|
16
|
+
import { ColumnsGroup } from "../ColumnsGroup";
|
|
17
|
+
const TableContainer = props => {
|
|
18
|
+
const {
|
|
19
|
+
t,
|
|
20
|
+
table,
|
|
21
|
+
id,
|
|
22
|
+
prefix,
|
|
23
|
+
// commandClick,
|
|
24
|
+
editAble,
|
|
25
|
+
rowKey,
|
|
26
|
+
format,
|
|
27
|
+
dataSource,
|
|
28
|
+
originData,
|
|
29
|
+
expandable,
|
|
30
|
+
wrapSettings,
|
|
31
|
+
recordDoubleClick,
|
|
32
|
+
// triggerFilter,
|
|
33
|
+
selectionSettings,
|
|
34
|
+
isSelectionChange,
|
|
35
|
+
setIsSelectionChange,
|
|
36
|
+
onContextMenu,
|
|
37
|
+
// contextMenuItems,
|
|
38
|
+
setSorterChange,
|
|
39
|
+
setFilterChange,
|
|
40
|
+
height,
|
|
41
|
+
minHeight,
|
|
42
|
+
showToolbar,
|
|
43
|
+
toolbarItems,
|
|
44
|
+
actionTemplate,
|
|
45
|
+
pagination,
|
|
46
|
+
fullScreen,
|
|
47
|
+
showColumnChoose,
|
|
48
|
+
// summary,
|
|
49
|
+
locale,
|
|
50
|
+
groupColumns,
|
|
51
|
+
columns,
|
|
52
|
+
propsColumns,
|
|
53
|
+
triggerChangeColumns,
|
|
54
|
+
triggerGroupColumns,
|
|
55
|
+
columnHidden,
|
|
56
|
+
expanded,
|
|
57
|
+
setExpanded,
|
|
58
|
+
// showEmptyText,
|
|
59
|
+
infiniteScroll,
|
|
60
|
+
// next,
|
|
61
|
+
// loading,
|
|
62
|
+
windowSize,
|
|
63
|
+
// contextMenuOpen,
|
|
64
|
+
// contextMenuClick,
|
|
65
|
+
// contextMenuHidden,
|
|
66
|
+
isFullScreen,
|
|
67
|
+
setIsFullScreen,
|
|
68
|
+
isDataTree,
|
|
69
|
+
// setColumns,
|
|
70
|
+
// columnSizing,
|
|
71
|
+
// columnSizingInfo,
|
|
72
|
+
rowClassName,
|
|
73
|
+
onRowStyles,
|
|
74
|
+
onRowFooterStyles,
|
|
75
|
+
onRowHeaderStyles,
|
|
76
|
+
title,
|
|
77
|
+
groupSetting
|
|
78
|
+
} = props;
|
|
79
|
+
const tableContainerRef = React.useRef(null);
|
|
80
|
+
const containerRef = React.useRef(null);
|
|
81
|
+
const bottomToolbarRef = React.useRef(null);
|
|
82
|
+
const topToolbarRef = React.useRef(null);
|
|
83
|
+
const [tableHeight, settableHeight] = React.useState(0);
|
|
84
|
+
React.useEffect(() => {
|
|
85
|
+
// const totalHeight = minHeight ?? height
|
|
86
|
+
const totalHeight = getTableHeight(height, minHeight);
|
|
87
|
+
if (totalHeight) {
|
|
88
|
+
const topHeight = topToolbarRef.current ? topToolbarRef.current.offsetHeight : 0;
|
|
89
|
+
const bottomHeight = bottomToolbarRef.current ? bottomToolbarRef.current.offsetHeight : 0;
|
|
90
|
+
settableHeight(totalHeight - topHeight - bottomHeight);
|
|
91
|
+
}
|
|
92
|
+
}, [id, height, editAble, minHeight]);
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
const handleClickOutside = () => {
|
|
95
|
+
|
|
96
|
+
// setFocusedCell(undefined)
|
|
97
|
+
// setIsSelectionChange((prev) => (
|
|
98
|
+
// {
|
|
99
|
+
// ...prev,
|
|
100
|
+
// isChange: false
|
|
101
|
+
// }
|
|
102
|
+
// ))
|
|
103
|
+
};
|
|
104
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
105
|
+
return () => {
|
|
106
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
107
|
+
};
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
// React.useEffect(() => {
|
|
111
|
+
|
|
112
|
+
// if (!tableContainerRef.current) {
|
|
113
|
+
// return
|
|
114
|
+
// }
|
|
115
|
+
|
|
116
|
+
// if (columnSizingInfo.isResizingColumn === false) {
|
|
117
|
+
|
|
118
|
+
// const aa = updateColumnWidthsRecursive(propsColumns, columnSizing)
|
|
119
|
+
|
|
120
|
+
// setColumns(aa)
|
|
121
|
+
|
|
122
|
+
// }
|
|
123
|
+
|
|
124
|
+
// }, [columnSizingInfo])
|
|
125
|
+
|
|
126
|
+
// const triggerCommandClick = (args: Omit<CommandClick<RecordType>, 'rows'>) => {
|
|
127
|
+
|
|
128
|
+
// // const { id: idCommand, rowId, rowData, index } = args
|
|
129
|
+
|
|
130
|
+
// // const tmpData = [...dataSource]
|
|
131
|
+
|
|
132
|
+
// if (commandClick) {
|
|
133
|
+
// commandClick({
|
|
134
|
+
// ...args,
|
|
135
|
+
// rows: originData
|
|
136
|
+
// })
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
// }
|
|
140
|
+
|
|
141
|
+
const handleOnGroup = value => {
|
|
142
|
+
triggerGroupColumns?.(value);
|
|
143
|
+
};
|
|
144
|
+
const groupToolbar = () => {
|
|
145
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
146
|
+
style: {
|
|
147
|
+
display: 'flex',
|
|
148
|
+
gap: '10px',
|
|
149
|
+
marginRight: 10
|
|
150
|
+
}
|
|
151
|
+
}, groupSetting?.showGroupIcon !== false && /*#__PURE__*/React.createElement(ColumnsGroup, {
|
|
152
|
+
t: t
|
|
153
|
+
// defaultGroupColumns={['name']}
|
|
154
|
+
,
|
|
155
|
+
unClearableLevel: groupSetting?.unClearableLevel
|
|
156
|
+
// unClearableLevel={2}
|
|
157
|
+
,
|
|
158
|
+
columns: propsColumns ? flatColumns2(propsColumns) : [],
|
|
159
|
+
columnsGrouped: groupColumns,
|
|
160
|
+
onSubmit: handleOnGroup
|
|
161
|
+
}), /*#__PURE__*/React.createElement(React.Fragment, null));
|
|
162
|
+
};
|
|
163
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
164
|
+
ref: containerRef,
|
|
165
|
+
id: id
|
|
166
|
+
}, (showToolbar !== false || fullScreen !== false || title) && /*#__PURE__*/React.createElement("div", {
|
|
167
|
+
ref: topToolbarRef,
|
|
168
|
+
className: classNames(`${prefix}-grid-top-toolbar`, {})
|
|
169
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
170
|
+
style: {
|
|
171
|
+
textAlign: 'center'
|
|
172
|
+
}
|
|
173
|
+
}, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/React.createElement("div", {
|
|
174
|
+
style: {
|
|
175
|
+
display: 'flex',
|
|
176
|
+
justifyContent: 'space-between',
|
|
177
|
+
alignItems: 'center',
|
|
178
|
+
gap: '.75rem'
|
|
179
|
+
}
|
|
180
|
+
}, groupToolbar(), /*#__PURE__*/React.createElement("div", {
|
|
181
|
+
style: {
|
|
182
|
+
flex: 1,
|
|
183
|
+
overflow: 'hidden'
|
|
184
|
+
}
|
|
185
|
+
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
186
|
+
items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
|
|
187
|
+
mode: 'scroll'
|
|
188
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
189
|
+
style: {
|
|
190
|
+
display: 'flex',
|
|
191
|
+
justifyContent: 'space-between',
|
|
192
|
+
alignItems: 'center',
|
|
193
|
+
gap: '.75rem'
|
|
194
|
+
}
|
|
195
|
+
}, pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' && /*#__PURE__*/React.createElement(Pagination, _extends({
|
|
196
|
+
showSizeChanger: true,
|
|
197
|
+
responsive: true,
|
|
198
|
+
size: 'small',
|
|
199
|
+
rootClassName: 'top-pagination',
|
|
200
|
+
showTotal: (totalItems, range) =>
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
`${range[0]}-${range[1]} / ${totalItems} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
|
|
203
|
+
}, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, fullScreen !== false && (isFullScreen ? /*#__PURE__*/React.createElement(Minimize, {
|
|
204
|
+
fontSize: 16,
|
|
205
|
+
onClick: () => {
|
|
206
|
+
setIsFullScreen(!isFullScreen);
|
|
207
|
+
},
|
|
208
|
+
"data-tooltip-id": `${id}-tooltip-content`,
|
|
209
|
+
"data-tooltip-content": t ? t('Minimized') : 'Minimized'
|
|
210
|
+
}) : /*#__PURE__*/React.createElement(Maximize, {
|
|
211
|
+
fontSize: 16,
|
|
212
|
+
onClick: () => {
|
|
213
|
+
setIsFullScreen(!isFullScreen);
|
|
214
|
+
},
|
|
215
|
+
"data-tooltip-id": `${id}-tooltip-content`,
|
|
216
|
+
"data-tooltip-content": t ? t('Full screen') : 'Full screen'
|
|
217
|
+
})), showColumnChoose && /*#__PURE__*/React.createElement(ColumnsChoose, {
|
|
218
|
+
columnHidden: columnHidden,
|
|
219
|
+
columns: columns,
|
|
220
|
+
originColumns: propsColumns,
|
|
221
|
+
t: t,
|
|
222
|
+
columnsGroup: groupColumns,
|
|
223
|
+
triggerChangeColumns: triggerChangeColumns
|
|
224
|
+
})))), /*#__PURE__*/React.createElement(TableContext.Provider, {
|
|
225
|
+
value: {
|
|
226
|
+
t,
|
|
227
|
+
locale,
|
|
228
|
+
prefix,
|
|
229
|
+
id,
|
|
230
|
+
rowKey,
|
|
231
|
+
format,
|
|
232
|
+
expandable,
|
|
233
|
+
expanded,
|
|
234
|
+
setExpanded,
|
|
235
|
+
dataSource,
|
|
236
|
+
originData,
|
|
237
|
+
// triggerFilter,
|
|
238
|
+
wrapSettings,
|
|
239
|
+
recordDoubleClick,
|
|
240
|
+
selectionSettings,
|
|
241
|
+
isSelectionChange,
|
|
242
|
+
setIsSelectionChange,
|
|
243
|
+
onContextMenu,
|
|
244
|
+
setSorterChange,
|
|
245
|
+
setFilterChange,
|
|
246
|
+
windowSize,
|
|
247
|
+
isDataTree,
|
|
248
|
+
// focusedCell,
|
|
249
|
+
// setFocusedCell,
|
|
250
|
+
rowClassName,
|
|
251
|
+
onRowStyles,
|
|
252
|
+
onRowFooterStyles,
|
|
253
|
+
onRowHeaderStyles,
|
|
254
|
+
table,
|
|
255
|
+
pagination,
|
|
256
|
+
groupSetting
|
|
257
|
+
// visible,
|
|
258
|
+
// setVisible,
|
|
259
|
+
// selectedKeys,
|
|
260
|
+
// setSelectedKeys,
|
|
261
|
+
// currentFilter,
|
|
262
|
+
// setCurrentFilter
|
|
263
|
+
}
|
|
264
|
+
}, /*#__PURE__*/React.createElement(TableWrapper, {
|
|
265
|
+
tableContainerRef: tableContainerRef,
|
|
266
|
+
prefix: prefix,
|
|
267
|
+
id: id,
|
|
268
|
+
height: tableHeight,
|
|
269
|
+
minHeight: minHeight,
|
|
270
|
+
dataSource: dataSource,
|
|
271
|
+
table: table,
|
|
272
|
+
columns: columns
|
|
273
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
274
|
+
ref: bottomToolbarRef
|
|
275
|
+
}, pagination && !infiniteScroll && /*#__PURE__*/React.createElement(Pagination
|
|
276
|
+
// style={{padding: '0.75rem 1rem'}}
|
|
277
|
+
, _extends({
|
|
278
|
+
pageSizeOptions: [20, 50, 100, 1000, 10000]
|
|
279
|
+
}, pagination, {
|
|
280
|
+
rootClassName: 'pagination-template',
|
|
281
|
+
showSizeChanger: true,
|
|
282
|
+
responsive: true,
|
|
283
|
+
size: 'small',
|
|
284
|
+
total: pagination.total,
|
|
285
|
+
pageSize: pagination.onChange ? pagination.pageSize : table.getState().pagination.pageSize,
|
|
286
|
+
showTotal: (totalItems, range) => `${numericFormatter((range[0] ?? 0).toString(), {
|
|
287
|
+
thousandSeparator: '.'
|
|
288
|
+
})}-${numericFormatter((range[1] ?? 0).toString(), {
|
|
289
|
+
thousandSeparator: '.'
|
|
290
|
+
})} / ${numericFormatter((totalItems ?? 0).toString(), {
|
|
291
|
+
thousandSeparator: '.'
|
|
292
|
+
})} items`,
|
|
293
|
+
onChange: (page, pageSize1) => {
|
|
294
|
+
if (pagination.onChange) {
|
|
295
|
+
pagination.onChange(page, pageSize1);
|
|
296
|
+
table.setPageIndex(page - 1);
|
|
297
|
+
table.setPageSize(pageSize1);
|
|
298
|
+
} else {
|
|
299
|
+
table.setPageIndex(page - 1);
|
|
300
|
+
table.setPageSize(pageSize1);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}))));
|
|
304
|
+
};
|
|
305
|
+
export default TableContainer;
|