es-grid-template 1.7.47 → 1.8.0
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/TempTable.js +1 -3
- package/es/table-component/ColumnsChoose.js +9 -2
- package/es/table-component/InternalTable.js +1 -0
- package/es/table-component/TableContainer.d.ts +5 -1
- package/es/table-component/TableContainer.js +33 -3
- package/es/table-component/TableContainerEdit.js +87 -62
- package/es/table-component/body/EditableCell.js +34 -2
- package/es/table-component/body/TableBody.js +1 -1
- package/es/table-component/body/TableBodyCell.d.ts +7 -3
- package/es/table-component/body/TableBodyCell.js +268 -135
- package/es/table-component/body/TableBodyCellEdit.d.ts +2 -2
- package/es/table-component/body/TableBodyCellEdit.js +18 -13
- package/es/table-component/body/TableBodyRow.d.ts +2 -2
- package/es/table-component/body/TableBodyRow.js +45 -16
- package/es/table-component/components/command/Command.js +2 -0
- package/es/table-component/footer/TableFooter.js +1 -1
- package/es/table-component/footer/TableFooterCell.js +3 -2
- package/es/table-component/footer/TableFooterRow.js +4 -3
- package/es/table-component/header/TableHead.d.ts +1 -1
- package/es/table-component/header/TableHead.js +83 -20
- package/es/table-component/header/TableHeadCell.js +13 -8
- package/es/table-component/header/TableHeadCell2.d.ts +17 -0
- package/es/table-component/header/TableHeadCell2.js +331 -0
- package/es/table-component/header/TableHeadGroupCell.d.ts +17 -0
- package/es/table-component/header/TableHeadGroupCell.js +327 -0
- package/es/table-component/header/TableHeadRow.js +1 -1
- package/es/table-component/hook/utils.js +5 -2
- package/es/table-component/style.scss +26 -4
- package/es/table-component/table/Grid.js +19 -19
- package/es/table-component/table/TableWrapper.js +1 -1
- package/lib/grid-component/TempTable.js +1 -3
- package/lib/table-component/ColumnsChoose.js +9 -2
- package/lib/table-component/InternalTable.js +1 -0
- package/lib/table-component/TableContainer.d.ts +5 -1
- package/lib/table-component/TableContainer.js +32 -2
- package/lib/table-component/TableContainerEdit.js +87 -62
- package/lib/table-component/body/EditableCell.js +34 -2
- package/lib/table-component/body/TableBody.js +1 -1
- package/lib/table-component/body/TableBodyCell.d.ts +7 -3
- package/lib/table-component/body/TableBodyCell.js +267 -136
- package/lib/table-component/body/TableBodyCellEdit.d.ts +2 -2
- package/lib/table-component/body/TableBodyCellEdit.js +18 -13
- package/lib/table-component/body/TableBodyRow.d.ts +2 -2
- package/lib/table-component/body/TableBodyRow.js +45 -16
- package/lib/table-component/components/command/Command.js +2 -0
- package/lib/table-component/footer/TableFooter.js +1 -1
- package/lib/table-component/footer/TableFooterCell.js +3 -2
- package/lib/table-component/footer/TableFooterRow.js +4 -3
- package/lib/table-component/header/TableHead.d.ts +1 -1
- package/lib/table-component/header/TableHead.js +84 -20
- package/lib/table-component/header/TableHeadCell.js +13 -8
- package/lib/table-component/header/TableHeadCell2.d.ts +17 -0
- package/lib/table-component/header/TableHeadCell2.js +340 -0
- package/lib/table-component/header/TableHeadGroupCell.d.ts +17 -0
- package/lib/table-component/header/TableHeadGroupCell.js +336 -0
- package/lib/table-component/header/TableHeadRow.js +1 -1
- package/lib/table-component/hook/utils.js +5 -2
- package/lib/table-component/style.scss +26 -4
- package/lib/table-component/table/Grid.js +19 -19
- package/lib/table-component/table/TableWrapper.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// import { useSortable } from "@dnd-kit/sortable"
|
|
2
|
+
|
|
3
|
+
import { flexRender } from '@tanstack/react-table';
|
|
4
|
+
import React, { useContext } from 'react';
|
|
5
|
+
// import { CSS } from '@dnd-kit/utilities'
|
|
6
|
+
// import type { Virtualizer } from '@tanstack/react-virtual'
|
|
7
|
+
import { Button, Space } from 'antd';
|
|
8
|
+
import { ArrowDown, ArrowUp, FilterFill, SortCancel } from 'becoxy-icons';
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import { Checkbox, Dropdown, Select } from 'rc-master-ui';
|
|
11
|
+
import { booleanOperator, nonActionColumn, numberOperator, stringOperator, translateOption } from "../hook/constant";
|
|
12
|
+
import { extendsObject, getCommonPinningStyles, getDefaultOperator, getTypeFilter } from "../hook/utils";
|
|
13
|
+
import { TableContext } from "../useContext";
|
|
14
|
+
import { renderFilter } from "./renderFilter";
|
|
15
|
+
import ReactDOMServer from 'react-dom/server';
|
|
16
|
+
|
|
17
|
+
// import { ColumnTable } from "../type";
|
|
18
|
+
|
|
19
|
+
// import { Tooltip } from 'react-tooltip'
|
|
20
|
+
|
|
21
|
+
const TableHeadCell2 = props => {
|
|
22
|
+
const {
|
|
23
|
+
column,
|
|
24
|
+
header,
|
|
25
|
+
getPopupContainer,
|
|
26
|
+
table,
|
|
27
|
+
depth,
|
|
28
|
+
// t,
|
|
29
|
+
// columnVirtualizer,
|
|
30
|
+
// rowHeaderVirtualizer,
|
|
31
|
+
colSpan,
|
|
32
|
+
rowSpan
|
|
33
|
+
} = props;
|
|
34
|
+
const {
|
|
35
|
+
t,
|
|
36
|
+
prefix,
|
|
37
|
+
setSorterChange,
|
|
38
|
+
setFilterChange,
|
|
39
|
+
wrapSettings,
|
|
40
|
+
selectionSettings,
|
|
41
|
+
setIsSelectionChange,
|
|
42
|
+
id,
|
|
43
|
+
locale
|
|
44
|
+
} = useContext(TableContext);
|
|
45
|
+
const isPinned = column.getIsPinned();
|
|
46
|
+
const isLastLeftPinnedColumn = isPinned === 'left' && column.getIsLastColumn('left');
|
|
47
|
+
const isFirstRightPinnedColumn = isPinned === 'right' && column.getIsFirstColumn('right');
|
|
48
|
+
const [selectedKeys, setSelectedKeys] = React.useState([]);
|
|
49
|
+
const [visible, setVisible] = React.useState(false);
|
|
50
|
+
const {
|
|
51
|
+
filterIcon
|
|
52
|
+
} = column.columnDef.meta ?? {};
|
|
53
|
+
|
|
54
|
+
// const column = (column.columnDef ?? {}) as ColumnTable
|
|
55
|
+
// const column = column.columnDef
|
|
56
|
+
|
|
57
|
+
const originalColumn = column.columnDef.meta ?? {};
|
|
58
|
+
const filtered = (column.getFilterValue() ?? []).length > 0;
|
|
59
|
+
const cellContent = flexRender(column.columnDef.header, header.getContext());
|
|
60
|
+
// const cellContent = 'aaaa'
|
|
61
|
+
|
|
62
|
+
const html = ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement(React.Fragment, null, cellContent));
|
|
63
|
+
const hasValue = html.trim().length > 0;
|
|
64
|
+
|
|
65
|
+
// const filtered = column.getIsFiltered()
|
|
66
|
+
|
|
67
|
+
// const { attributes, isDragging, listeners, setNodeRef, transform } =
|
|
68
|
+
// useSortable({
|
|
69
|
+
// id: column.id,
|
|
70
|
+
// })
|
|
71
|
+
|
|
72
|
+
const style = {
|
|
73
|
+
// opacity: isDragging ? 0.8 : 1,
|
|
74
|
+
// position: 'relative',
|
|
75
|
+
// transform: CSS.Translate.toString(transform), // translate instead of transform to avoid squishing
|
|
76
|
+
transition: 'width transform 0.2s ease-in-out',
|
|
77
|
+
whiteSpace: 'nowrap'
|
|
78
|
+
// width: column.getSize(),
|
|
79
|
+
// zIndex: isDragging ? 1 : 0,
|
|
80
|
+
};
|
|
81
|
+
const getDropdownTrigger = () => {
|
|
82
|
+
let iconFilter;
|
|
83
|
+
if (typeof filterIcon === 'function') {
|
|
84
|
+
iconFilter = filterIcon(filtered);
|
|
85
|
+
} else if (filterIcon) {
|
|
86
|
+
iconFilter = filterIcon;
|
|
87
|
+
} else {
|
|
88
|
+
iconFilter = /*#__PURE__*/React.createElement(FilterFill, {
|
|
89
|
+
style: {
|
|
90
|
+
color: filtered ? '#E3165B' : '#283046'
|
|
91
|
+
},
|
|
92
|
+
fontSize: 12
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
96
|
+
role: "button",
|
|
97
|
+
tabIndex: -1,
|
|
98
|
+
className: classNames(`${prefix}-trigger`, {
|
|
99
|
+
active: filtered
|
|
100
|
+
}),
|
|
101
|
+
onClick: e => {
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
}
|
|
104
|
+
}, iconFilter);
|
|
105
|
+
};
|
|
106
|
+
const triggerVisible = newVisible => {
|
|
107
|
+
setVisible(newVisible);
|
|
108
|
+
};
|
|
109
|
+
const onVisibleChange = (newVisible, info) => {
|
|
110
|
+
if (info.source === 'trigger') {
|
|
111
|
+
if (newVisible) {
|
|
112
|
+
const filterValue = column.getFilterValue() ?? [];
|
|
113
|
+
const operatorValue = column.getFilterOperator() ?? getDefaultOperator(column?.meta ?? {});
|
|
114
|
+
setSelectedKeys(filterValue);
|
|
115
|
+
column.setFilterOperator?.(operatorValue);
|
|
116
|
+
} else {}
|
|
117
|
+
triggerVisible(newVisible);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const doFilter = type => {
|
|
121
|
+
if (type) {
|
|
122
|
+
column.setFilterValue(!originalColumn.typeFilter || originalColumn.typeFilter === 'Text' ? selectedKeys.length === 0 ? [''] : selectedKeys : selectedKeys);
|
|
123
|
+
} else {
|
|
124
|
+
column.setFilterValue(undefined);
|
|
125
|
+
setSelectedKeys([]);
|
|
126
|
+
}
|
|
127
|
+
setFilterChange(true);
|
|
128
|
+
triggerVisible(false);
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
setFilterChange(false);
|
|
131
|
+
}, 10);
|
|
132
|
+
};
|
|
133
|
+
const mergedDropdownProps = extendsObject({
|
|
134
|
+
trigger: ['click'],
|
|
135
|
+
placement: 'bottomRight',
|
|
136
|
+
// placement: direction === 'rtl' ? 'bottomLeft' : 'bottomRight',
|
|
137
|
+
children: getDropdownTrigger(),
|
|
138
|
+
getPopupContainer
|
|
139
|
+
}, {
|
|
140
|
+
// ...filterDropdownProps,
|
|
141
|
+
// rootClassName: classNames(rootClassName, filterDropdownProps.rootClassName),
|
|
142
|
+
open: visible,
|
|
143
|
+
onOpenChange: onVisibleChange,
|
|
144
|
+
destroyPopupOnHide: true,
|
|
145
|
+
dropdownRender: () => {
|
|
146
|
+
const type = getTypeFilter(originalColumn);
|
|
147
|
+
const operatorValue = column.getFilterOperator() ?? getDefaultOperator(originalColumn);
|
|
148
|
+
const operatorOptions = ['Checkbox', 'Dropdown', 'DropTree', 'CheckboxDropdown'].includes(type) ? booleanOperator : !type || type === 'Text' ? stringOperator : numberOperator;
|
|
149
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
150
|
+
// className='ui-rc-table-filter-dropdown'
|
|
151
|
+
|
|
152
|
+
className: classNames(`${prefix}-grid-filter-dropdown`, {}),
|
|
153
|
+
style: {}
|
|
154
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
155
|
+
style: {
|
|
156
|
+
minWidth: 275,
|
|
157
|
+
padding: '8px'
|
|
158
|
+
}
|
|
159
|
+
}, /*#__PURE__*/React.createElement("div", null), column.meta?.showOperator !== false && column.meta?.typeFilter !== 'DateRange' && column.meta?.typeFilter !== 'NumberRange' && /*#__PURE__*/React.createElement("div", {
|
|
160
|
+
className: 'mb-1'
|
|
161
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
162
|
+
options: translateOption(operatorOptions, t),
|
|
163
|
+
style: {
|
|
164
|
+
width: '100%',
|
|
165
|
+
marginBottom: 8
|
|
166
|
+
},
|
|
167
|
+
value: operatorValue,
|
|
168
|
+
onChange: val => {
|
|
169
|
+
column.setFilterOperator(val);
|
|
170
|
+
}
|
|
171
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
172
|
+
style: {
|
|
173
|
+
marginBottom: 8
|
|
174
|
+
}
|
|
175
|
+
}, renderFilter({
|
|
176
|
+
column: column,
|
|
177
|
+
selectedKeys,
|
|
178
|
+
setSelectedKeys
|
|
179
|
+
// selectedKeys: (column.getFilterValue() ?? []) as string[],
|
|
180
|
+
// setSelectedKeys: column.setFilterValue,
|
|
181
|
+
})), /*#__PURE__*/React.createElement(Space, {
|
|
182
|
+
style: {
|
|
183
|
+
justifyContent: 'end',
|
|
184
|
+
width: '100%'
|
|
185
|
+
}
|
|
186
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
187
|
+
type: "primary",
|
|
188
|
+
onClick: () => {
|
|
189
|
+
// column.setFilterValue(selectedKeys)
|
|
190
|
+
|
|
191
|
+
doFilter(true);
|
|
192
|
+
},
|
|
193
|
+
size: "small",
|
|
194
|
+
style: {
|
|
195
|
+
width: 90
|
|
196
|
+
}
|
|
197
|
+
}, t ? t('Filter') : 'Filter'), /*#__PURE__*/React.createElement(Button, {
|
|
198
|
+
type: "link",
|
|
199
|
+
size: "small",
|
|
200
|
+
onClick: () => {
|
|
201
|
+
// column.setFilterValue([])
|
|
202
|
+
// column.setFilterOperator('')
|
|
203
|
+
|
|
204
|
+
setSelectedKeys([]);
|
|
205
|
+
doFilter(false);
|
|
206
|
+
}
|
|
207
|
+
}, t ? t('Clear') : 'Clear'))));
|
|
208
|
+
|
|
209
|
+
// if (typeof filterDropdownProps?.dropdownRender === 'function') {
|
|
210
|
+
// return filterDropdownProps.dropdownRender(dropdownContent);
|
|
211
|
+
// }
|
|
212
|
+
// return dropdownContent;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
216
|
+
// ref={setNodeRef}
|
|
217
|
+
className: classNames(`${prefix}-grid-cell`, {
|
|
218
|
+
[`${prefix}-grid-cell-ellipsis`]: !wrapSettings || !(wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')),
|
|
219
|
+
[`${prefix}-grid-cell-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header'),
|
|
220
|
+
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
221
|
+
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
222
|
+
[`${prefix}-grid-cell-text-center`]: (originalColumn?.headerTextAlign ?? originalColumn?.textAlign) === 'center',
|
|
223
|
+
[`${prefix}-grid-cell-text-right`]: (originalColumn?.headerTextAlign ?? originalColumn.textAlign) === 'right'
|
|
224
|
+
})
|
|
225
|
+
// colSpan={colSpan}
|
|
226
|
+
// rowSpan={rowSpan}
|
|
227
|
+
,
|
|
228
|
+
|
|
229
|
+
key: column.id,
|
|
230
|
+
style: {
|
|
231
|
+
// display: 'flex',
|
|
232
|
+
// width: column.getSize(),
|
|
233
|
+
minWidth: column.getSize(),
|
|
234
|
+
// flex: 1,
|
|
235
|
+
flexGrow: column.getSize(),
|
|
236
|
+
gridRow: `${depth + 1} / span ${rowSpan}`,
|
|
237
|
+
gridColumn: `span ${colSpan}`,
|
|
238
|
+
// maxWidth: header.getSize(),
|
|
239
|
+
...getCommonPinningStyles(column),
|
|
240
|
+
width: 'auto',
|
|
241
|
+
...style
|
|
242
|
+
},
|
|
243
|
+
"data-tooltip-id": `${id}-tooltip-content`,
|
|
244
|
+
"data-tooltip-delay-show": 500,
|
|
245
|
+
"data-tooltip-html": !hasValue ? '' : ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement("div", null, cellContent))
|
|
246
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
247
|
+
className: classNames('', {
|
|
248
|
+
[`${prefix}-grid-filter-column`]: column.id !== 'selection_column',
|
|
249
|
+
[`${prefix}-grid-selection-column`]: column.id === 'selection_column'
|
|
250
|
+
})
|
|
251
|
+
}, column.id === 'selection_column' && selectionSettings && selectionSettings.hideSelectAll !== false && selectionSettings.type !== 'single' && selectionSettings.mode !== 'radio' && /*#__PURE__*/React.createElement(Checkbox, {
|
|
252
|
+
checked: table.getIsAllRowsSelected(),
|
|
253
|
+
indeterminate: table.getIsSomeRowsSelected(),
|
|
254
|
+
onChange: e => {
|
|
255
|
+
setIsSelectionChange({
|
|
256
|
+
isChange: true,
|
|
257
|
+
type: 'all',
|
|
258
|
+
rowData: {}
|
|
259
|
+
});
|
|
260
|
+
table.getToggleAllRowsSelectedHandler()(e);
|
|
261
|
+
}
|
|
262
|
+
}), column.id !== 'selection_column' && /*#__PURE__*/React.createElement("span", {
|
|
263
|
+
className: "ui-rc-table-column-title",
|
|
264
|
+
style: {
|
|
265
|
+
flex: 1
|
|
266
|
+
}
|
|
267
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
268
|
+
className: classNames('', {
|
|
269
|
+
[`${prefix}-grid-cell-ellipsis`]: !wrapSettings || !(wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')),
|
|
270
|
+
[`${prefix}-grid-cell-text-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')
|
|
271
|
+
})
|
|
272
|
+
}, cellContent)), !nonActionColumn.includes(column.id) && column.columns.length < 1 && /*#__PURE__*/React.createElement("span", {
|
|
273
|
+
className: "ui-rc-header-trigger"
|
|
274
|
+
}, column.getCanSort() && /*#__PURE__*/React.createElement("div", {
|
|
275
|
+
style: {
|
|
276
|
+
marginInlineEnd: 6,
|
|
277
|
+
cursor: 'pointer'
|
|
278
|
+
},
|
|
279
|
+
onClick: e => {
|
|
280
|
+
setSorterChange(true);
|
|
281
|
+
const toggleSortingHandler = column.getToggleSortingHandler();
|
|
282
|
+
if (typeof toggleSortingHandler === 'function') {
|
|
283
|
+
toggleSortingHandler(e);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}, column.getIsSorted() ? column.getIsSorted() === 'asc' ? /*#__PURE__*/React.createElement(ArrowUp, {
|
|
287
|
+
fontSize: 15,
|
|
288
|
+
color: '#000'
|
|
289
|
+
// data-tooltip-id={`${id}-tooltip-header-trigger`}
|
|
290
|
+
,
|
|
291
|
+
"data-tooltip-id": `${id}-tooltip-content`
|
|
292
|
+
// data-tooltip-content='Nhấp để sắp xếp giảm dần'
|
|
293
|
+
,
|
|
294
|
+
"data-tooltip-content": locale?.triggerDesc ?? 'Click to sort descending'
|
|
295
|
+
}) : /*#__PURE__*/React.createElement(ArrowDown, {
|
|
296
|
+
fontSize: 15,
|
|
297
|
+
color: '#000',
|
|
298
|
+
"data-tooltip-id": `${id}-tooltip-content`
|
|
299
|
+
// data-tooltip-id={`${id}-tooltip-header-trigger`}
|
|
300
|
+
// data-tooltip-content='Nhấp để hủy sắp xếp'
|
|
301
|
+
,
|
|
302
|
+
"data-tooltip-content": locale?.cancelSort ?? 'Click to cancel sorting'
|
|
303
|
+
}) : /*#__PURE__*/React.createElement(SortCancel
|
|
304
|
+
// data-tooltip-id={`${id}-tooltip-header-trigger`}
|
|
305
|
+
, {
|
|
306
|
+
"data-tooltip-id": `${id}-tooltip-content`
|
|
307
|
+
// data-tooltip-content='Nhấp để sắp xếp tăng dần'
|
|
308
|
+
,
|
|
309
|
+
"data-tooltip-content": locale?.triggerAsc ?? 'Click to sort ascending',
|
|
310
|
+
fontSize: 15,
|
|
311
|
+
style: {
|
|
312
|
+
display: 'flex'
|
|
313
|
+
},
|
|
314
|
+
className: classNames(`ui-rc-table-column-sorter-cancel`, {
|
|
315
|
+
active: true
|
|
316
|
+
})
|
|
317
|
+
})), column.getCanFilter() && /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Dropdown, mergedDropdownProps)))), column.getCanResize() && /*#__PURE__*/React.createElement("div", {
|
|
318
|
+
onDoubleClick: () => column.resetSize(),
|
|
319
|
+
onMouseDown: header.getResizeHandler(),
|
|
320
|
+
onTouchStart: header.getResizeHandler(),
|
|
321
|
+
// onMouseUp: () => {
|
|
322
|
+
// requestAnimationFrame(() => {
|
|
323
|
+
// columnVirtualizer.measure()
|
|
324
|
+
// // rowHeaderVirtualizer.measure()
|
|
325
|
+
// })
|
|
326
|
+
// },
|
|
327
|
+
|
|
328
|
+
className: `resizer ${column.getIsResizing() ? 'isResizing' : ''}`
|
|
329
|
+
}));
|
|
330
|
+
};
|
|
331
|
+
export default TableHeadCell2;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Table } from '@tanstack/react-table';
|
|
2
|
+
import { type Header } from '@tanstack/react-table';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import type { Virtualizer } from '@tanstack/react-virtual';
|
|
5
|
+
interface TableHeadCellProps<T> {
|
|
6
|
+
t?: any;
|
|
7
|
+
table: Table<T>;
|
|
8
|
+
column: any;
|
|
9
|
+
header: Header<T, unknown>;
|
|
10
|
+
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
|
|
11
|
+
columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
|
12
|
+
colSpan: number;
|
|
13
|
+
rowSpan: number;
|
|
14
|
+
depth: number;
|
|
15
|
+
}
|
|
16
|
+
declare const TableHeadGroupCell: <RecordType extends object>(props: TableHeadCellProps<RecordType>) => React.JSX.Element;
|
|
17
|
+
export default TableHeadGroupCell;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// import { useSortable } from "@dnd-kit/sortable"
|
|
2
|
+
|
|
3
|
+
import { flexRender } from '@tanstack/react-table';
|
|
4
|
+
import React, { useContext } from 'react';
|
|
5
|
+
// import { CSS } from '@dnd-kit/utilities'
|
|
6
|
+
// import type { Virtualizer } from '@tanstack/react-virtual'
|
|
7
|
+
import { Button, Space } from 'antd';
|
|
8
|
+
import { ArrowDown, ArrowUp, FilterFill, SortCancel } from 'becoxy-icons';
|
|
9
|
+
import classNames from 'classnames';
|
|
10
|
+
import { Checkbox, Dropdown, Select } from 'rc-master-ui';
|
|
11
|
+
import { booleanOperator, nonActionColumn, numberOperator, stringOperator, translateOption } from "../hook/constant";
|
|
12
|
+
import { extendsObject, getCommonPinningStyles, getDefaultOperator, getTypeFilter } from "../hook/utils";
|
|
13
|
+
import { TableContext } from "../useContext";
|
|
14
|
+
import { renderFilter } from "./renderFilter";
|
|
15
|
+
import ReactDOMServer from 'react-dom/server';
|
|
16
|
+
|
|
17
|
+
// import { ColumnTable } from "../type";
|
|
18
|
+
|
|
19
|
+
// import { Tooltip } from 'react-tooltip'
|
|
20
|
+
|
|
21
|
+
const TableHeadGroupCell = props => {
|
|
22
|
+
const {
|
|
23
|
+
column,
|
|
24
|
+
header,
|
|
25
|
+
getPopupContainer,
|
|
26
|
+
table,
|
|
27
|
+
depth,
|
|
28
|
+
// t,
|
|
29
|
+
// columnVirtualizer,
|
|
30
|
+
// rowHeaderVirtualizer,
|
|
31
|
+
colSpan,
|
|
32
|
+
rowSpan
|
|
33
|
+
} = props;
|
|
34
|
+
const {
|
|
35
|
+
t,
|
|
36
|
+
prefix,
|
|
37
|
+
setSorterChange,
|
|
38
|
+
setFilterChange,
|
|
39
|
+
wrapSettings,
|
|
40
|
+
selectionSettings,
|
|
41
|
+
setIsSelectionChange,
|
|
42
|
+
id,
|
|
43
|
+
locale
|
|
44
|
+
} = useContext(TableContext);
|
|
45
|
+
const isPinned = column.getIsPinned();
|
|
46
|
+
const isLastLeftPinnedColumn = isPinned === 'left' && column.getIsLastColumn('left');
|
|
47
|
+
const isFirstRightPinnedColumn = isPinned === 'right' && column.getIsFirstColumn('right');
|
|
48
|
+
const [selectedKeys, setSelectedKeys] = React.useState([]);
|
|
49
|
+
const [visible, setVisible] = React.useState(false);
|
|
50
|
+
const {
|
|
51
|
+
filterIcon
|
|
52
|
+
} = column.columnDef.meta ?? {};
|
|
53
|
+
|
|
54
|
+
// const column = (column.columnDef ?? {}) as ColumnTable
|
|
55
|
+
// const column = column.columnDef
|
|
56
|
+
|
|
57
|
+
const originalColumn = column.columnDef.meta ?? {};
|
|
58
|
+
const filtered = (column.getFilterValue() ?? []).length > 0;
|
|
59
|
+
const cellContent = flexRender(column.columnDef.header, header.getContext());
|
|
60
|
+
const html = ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement(React.Fragment, null, cellContent));
|
|
61
|
+
const hasValue = html.trim().length > 0;
|
|
62
|
+
|
|
63
|
+
// const filtered = column.getIsFiltered()
|
|
64
|
+
|
|
65
|
+
// const { attributes, isDragging, listeners, setNodeRef, transform } =
|
|
66
|
+
// useSortable({
|
|
67
|
+
// id: column.id,
|
|
68
|
+
// })
|
|
69
|
+
|
|
70
|
+
const style = {
|
|
71
|
+
// opacity: isDragging ? 0.8 : 1,
|
|
72
|
+
// position: 'relative',
|
|
73
|
+
// transform: CSS.Translate.toString(transform), // translate instead of transform to avoid squishing
|
|
74
|
+
transition: 'width transform 0.2s ease-in-out',
|
|
75
|
+
whiteSpace: 'nowrap'
|
|
76
|
+
// width: column.getSize(),
|
|
77
|
+
// zIndex: isDragging ? 1 : 0,
|
|
78
|
+
};
|
|
79
|
+
const getDropdownTrigger = () => {
|
|
80
|
+
let iconFilter;
|
|
81
|
+
if (typeof filterIcon === 'function') {
|
|
82
|
+
iconFilter = filterIcon(filtered);
|
|
83
|
+
} else if (filterIcon) {
|
|
84
|
+
iconFilter = filterIcon;
|
|
85
|
+
} else {
|
|
86
|
+
iconFilter = /*#__PURE__*/React.createElement(FilterFill, {
|
|
87
|
+
style: {
|
|
88
|
+
color: filtered ? '#E3165B' : '#283046'
|
|
89
|
+
},
|
|
90
|
+
fontSize: 12
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
94
|
+
role: "button",
|
|
95
|
+
tabIndex: -1,
|
|
96
|
+
className: classNames(`${prefix}-trigger`, {
|
|
97
|
+
active: filtered
|
|
98
|
+
}),
|
|
99
|
+
onClick: e => {
|
|
100
|
+
e.stopPropagation();
|
|
101
|
+
}
|
|
102
|
+
}, iconFilter);
|
|
103
|
+
};
|
|
104
|
+
const triggerVisible = newVisible => {
|
|
105
|
+
setVisible(newVisible);
|
|
106
|
+
};
|
|
107
|
+
const onVisibleChange = (newVisible, info) => {
|
|
108
|
+
if (info.source === 'trigger') {
|
|
109
|
+
if (newVisible) {
|
|
110
|
+
const filterValue = column.getFilterValue() ?? [];
|
|
111
|
+
const operatorValue = column.getFilterOperator() ?? getDefaultOperator(column?.meta ?? {});
|
|
112
|
+
setSelectedKeys(filterValue);
|
|
113
|
+
column.setFilterOperator?.(operatorValue);
|
|
114
|
+
} else {}
|
|
115
|
+
triggerVisible(newVisible);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const doFilter = type => {
|
|
119
|
+
if (type) {
|
|
120
|
+
column.setFilterValue(!originalColumn.typeFilter || originalColumn.typeFilter === 'Text' ? selectedKeys.length === 0 ? [''] : selectedKeys : selectedKeys);
|
|
121
|
+
} else {
|
|
122
|
+
column.setFilterValue(undefined);
|
|
123
|
+
setSelectedKeys([]);
|
|
124
|
+
}
|
|
125
|
+
setFilterChange(true);
|
|
126
|
+
triggerVisible(false);
|
|
127
|
+
setTimeout(() => {
|
|
128
|
+
setFilterChange(false);
|
|
129
|
+
}, 10);
|
|
130
|
+
};
|
|
131
|
+
const mergedDropdownProps = extendsObject({
|
|
132
|
+
trigger: ['click'],
|
|
133
|
+
placement: 'bottomRight',
|
|
134
|
+
// placement: direction === 'rtl' ? 'bottomLeft' : 'bottomRight',
|
|
135
|
+
children: getDropdownTrigger(),
|
|
136
|
+
getPopupContainer
|
|
137
|
+
}, {
|
|
138
|
+
// ...filterDropdownProps,
|
|
139
|
+
// rootClassName: classNames(rootClassName, filterDropdownProps.rootClassName),
|
|
140
|
+
open: visible,
|
|
141
|
+
onOpenChange: onVisibleChange,
|
|
142
|
+
destroyPopupOnHide: true,
|
|
143
|
+
dropdownRender: () => {
|
|
144
|
+
const type = getTypeFilter(originalColumn);
|
|
145
|
+
const operatorValue = column.getFilterOperator() ?? getDefaultOperator(originalColumn);
|
|
146
|
+
const operatorOptions = ['Checkbox', 'Dropdown', 'DropTree', 'CheckboxDropdown'].includes(type) ? booleanOperator : !type || type === 'Text' ? stringOperator : numberOperator;
|
|
147
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
148
|
+
// className='ui-rc-table-filter-dropdown'
|
|
149
|
+
|
|
150
|
+
className: classNames(`${prefix}-grid-filter-dropdown`, {}),
|
|
151
|
+
style: {}
|
|
152
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
153
|
+
style: {
|
|
154
|
+
minWidth: 275,
|
|
155
|
+
padding: '8px'
|
|
156
|
+
}
|
|
157
|
+
}, /*#__PURE__*/React.createElement("div", null), column.meta?.showOperator !== false && column.meta?.typeFilter !== 'DateRange' && column.meta?.typeFilter !== 'NumberRange' && /*#__PURE__*/React.createElement("div", {
|
|
158
|
+
className: 'mb-1'
|
|
159
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
160
|
+
options: translateOption(operatorOptions, t),
|
|
161
|
+
style: {
|
|
162
|
+
width: '100%',
|
|
163
|
+
marginBottom: 8
|
|
164
|
+
},
|
|
165
|
+
value: operatorValue,
|
|
166
|
+
onChange: val => {
|
|
167
|
+
column.setFilterOperator(val);
|
|
168
|
+
}
|
|
169
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
170
|
+
style: {
|
|
171
|
+
marginBottom: 8
|
|
172
|
+
}
|
|
173
|
+
}, renderFilter({
|
|
174
|
+
column: column,
|
|
175
|
+
selectedKeys,
|
|
176
|
+
setSelectedKeys
|
|
177
|
+
// selectedKeys: (column.getFilterValue() ?? []) as string[],
|
|
178
|
+
// setSelectedKeys: column.setFilterValue,
|
|
179
|
+
})), /*#__PURE__*/React.createElement(Space, {
|
|
180
|
+
style: {
|
|
181
|
+
justifyContent: 'end',
|
|
182
|
+
width: '100%'
|
|
183
|
+
}
|
|
184
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
185
|
+
type: "primary",
|
|
186
|
+
onClick: () => {
|
|
187
|
+
// column.setFilterValue(selectedKeys)
|
|
188
|
+
|
|
189
|
+
doFilter(true);
|
|
190
|
+
},
|
|
191
|
+
size: "small",
|
|
192
|
+
style: {
|
|
193
|
+
width: 90
|
|
194
|
+
}
|
|
195
|
+
}, t ? t('Filter') : 'Filter'), /*#__PURE__*/React.createElement(Button, {
|
|
196
|
+
type: "link",
|
|
197
|
+
size: "small",
|
|
198
|
+
onClick: () => {
|
|
199
|
+
// column.setFilterValue([])
|
|
200
|
+
// column.setFilterOperator('')
|
|
201
|
+
|
|
202
|
+
setSelectedKeys([]);
|
|
203
|
+
doFilter(false);
|
|
204
|
+
}
|
|
205
|
+
}, t ? t('Clear') : 'Clear'))));
|
|
206
|
+
|
|
207
|
+
// if (typeof filterDropdownProps?.dropdownRender === 'function') {
|
|
208
|
+
// return filterDropdownProps.dropdownRender(dropdownContent);
|
|
209
|
+
// }
|
|
210
|
+
// return dropdownContent;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
214
|
+
// ref={setNodeRef}
|
|
215
|
+
className: classNames(`${prefix}-grid-cell`, {
|
|
216
|
+
[`${prefix}-grid-cell-ellipsis`]: !wrapSettings || !(wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')),
|
|
217
|
+
[`${prefix}-grid-cell-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header'),
|
|
218
|
+
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
219
|
+
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
220
|
+
[`${prefix}-grid-cell-text-center`]: (originalColumn?.headerTextAlign ?? originalColumn?.textAlign) === 'center',
|
|
221
|
+
[`${prefix}-grid-cell-text-right`]: (originalColumn?.headerTextAlign ?? originalColumn.textAlign) === 'right'
|
|
222
|
+
})
|
|
223
|
+
// colSpan={colSpan}
|
|
224
|
+
// rowSpan={rowSpan}
|
|
225
|
+
,
|
|
226
|
+
|
|
227
|
+
key: column.id,
|
|
228
|
+
style: {
|
|
229
|
+
// display: 'flex',
|
|
230
|
+
// width: column.getSize(),
|
|
231
|
+
minWidth: column.getSize(),
|
|
232
|
+
flex: 1,
|
|
233
|
+
gridRow: `${depth + 1} / span ${rowSpan}`,
|
|
234
|
+
gridColumn: `span ${colSpan}`,
|
|
235
|
+
// maxWidth: header.getSize(),
|
|
236
|
+
...getCommonPinningStyles(column),
|
|
237
|
+
width: 'auto',
|
|
238
|
+
...style
|
|
239
|
+
},
|
|
240
|
+
"data-tooltip-id": `${id}-tooltip-content`,
|
|
241
|
+
"data-tooltip-html": !hasValue ? '' : ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement("div", null, cellContent))
|
|
242
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
243
|
+
className: classNames('', {
|
|
244
|
+
[`${prefix}-grid-filter-column`]: column.id !== 'selection_column',
|
|
245
|
+
[`${prefix}-grid-selection-column`]: column.id === 'selection_column'
|
|
246
|
+
})
|
|
247
|
+
}, column.id === 'selection_column' && selectionSettings && selectionSettings.hideSelectAll !== false && selectionSettings.type !== 'single' && selectionSettings.mode !== 'radio' && /*#__PURE__*/React.createElement(Checkbox, {
|
|
248
|
+
checked: table.getIsAllRowsSelected(),
|
|
249
|
+
indeterminate: table.getIsSomeRowsSelected(),
|
|
250
|
+
onChange: e => {
|
|
251
|
+
setIsSelectionChange({
|
|
252
|
+
isChange: true,
|
|
253
|
+
type: 'all',
|
|
254
|
+
rowData: {}
|
|
255
|
+
});
|
|
256
|
+
table.getToggleAllRowsSelectedHandler()(e);
|
|
257
|
+
}
|
|
258
|
+
}), column.id !== 'selection_column' && /*#__PURE__*/React.createElement("span", {
|
|
259
|
+
className: "ui-rc-table-column-title",
|
|
260
|
+
style: {
|
|
261
|
+
flex: 1
|
|
262
|
+
}
|
|
263
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
264
|
+
className: classNames('', {
|
|
265
|
+
[`${prefix}-grid-cell-ellipsis`]: !wrapSettings || !(wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')),
|
|
266
|
+
[`${prefix}-grid-cell-text-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Header')
|
|
267
|
+
})
|
|
268
|
+
}, cellContent)), !nonActionColumn.includes(column.id) && column.columns.length < 1 && /*#__PURE__*/React.createElement("span", {
|
|
269
|
+
className: "ui-rc-header-trigger"
|
|
270
|
+
}, column.getCanSort() && /*#__PURE__*/React.createElement("div", {
|
|
271
|
+
style: {
|
|
272
|
+
marginInlineEnd: 6,
|
|
273
|
+
cursor: 'pointer'
|
|
274
|
+
},
|
|
275
|
+
onClick: e => {
|
|
276
|
+
setSorterChange(true);
|
|
277
|
+
const toggleSortingHandler = column.getToggleSortingHandler();
|
|
278
|
+
if (typeof toggleSortingHandler === 'function') {
|
|
279
|
+
toggleSortingHandler(e);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}, column.getIsSorted() ? column.getIsSorted() === 'asc' ? /*#__PURE__*/React.createElement(ArrowUp, {
|
|
283
|
+
fontSize: 15,
|
|
284
|
+
color: '#000'
|
|
285
|
+
// data-tooltip-id={`${id}-tooltip-header-trigger`}
|
|
286
|
+
,
|
|
287
|
+
"data-tooltip-id": `${id}-tooltip-content`
|
|
288
|
+
// data-tooltip-content='Nhấp để sắp xếp giảm dần'
|
|
289
|
+
,
|
|
290
|
+
"data-tooltip-content": locale?.triggerDesc ?? 'Click to sort descending'
|
|
291
|
+
}) : /*#__PURE__*/React.createElement(ArrowDown, {
|
|
292
|
+
fontSize: 15,
|
|
293
|
+
color: '#000',
|
|
294
|
+
"data-tooltip-id": `${id}-tooltip-content`
|
|
295
|
+
// data-tooltip-id={`${id}-tooltip-header-trigger`}
|
|
296
|
+
// data-tooltip-content='Nhấp để hủy sắp xếp'
|
|
297
|
+
,
|
|
298
|
+
"data-tooltip-content": locale?.cancelSort ?? 'Click to cancel sorting'
|
|
299
|
+
}) : /*#__PURE__*/React.createElement(SortCancel
|
|
300
|
+
// data-tooltip-id={`${id}-tooltip-header-trigger`}
|
|
301
|
+
, {
|
|
302
|
+
"data-tooltip-id": `${id}-tooltip-content`
|
|
303
|
+
// data-tooltip-content='Nhấp để sắp xếp tăng dần'
|
|
304
|
+
,
|
|
305
|
+
"data-tooltip-content": locale?.triggerAsc ?? 'Click to sort ascending',
|
|
306
|
+
fontSize: 15,
|
|
307
|
+
style: {
|
|
308
|
+
display: 'flex'
|
|
309
|
+
},
|
|
310
|
+
className: classNames(`ui-rc-table-column-sorter-cancel`, {
|
|
311
|
+
active: true
|
|
312
|
+
})
|
|
313
|
+
})), column.getCanFilter() && /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Dropdown, mergedDropdownProps)))), column.getCanResize() && /*#__PURE__*/React.createElement("div", {
|
|
314
|
+
onDoubleClick: () => column.resetSize(),
|
|
315
|
+
onMouseDown: header.getResizeHandler(),
|
|
316
|
+
onTouchStart: header.getResizeHandler(),
|
|
317
|
+
// onMouseUp: () => {
|
|
318
|
+
// requestAnimationFrame(() => {
|
|
319
|
+
// columnVirtualizer.measure()
|
|
320
|
+
// // rowHeaderVirtualizer.measure()
|
|
321
|
+
// })
|
|
322
|
+
// },
|
|
323
|
+
|
|
324
|
+
className: `resizer ${column.getIsResizing() ? 'isResizing' : ''}`
|
|
325
|
+
}));
|
|
326
|
+
};
|
|
327
|
+
export default TableHeadGroupCell;
|
|
@@ -22,7 +22,7 @@ const TableHeadRow = ({
|
|
|
22
22
|
// const virtualColumns = columnVirtualizer.getVirtualItems()
|
|
23
23
|
|
|
24
24
|
const columnOrder = table.getState().columnOrder;
|
|
25
|
-
return /*#__PURE__*/React.createElement("
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
26
|
key: headerGroup.id
|
|
27
27
|
// ref={el => {
|
|
28
28
|
// if (el) rowHeaderVirtualizer.measureElement(el)
|