es-grid-template 1.4.1 → 1.4.2
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/EditableCell.js +46 -15
- package/es/grid-component/InternalTable.d.ts +1 -0
- package/es/grid-component/InternalTable.js +467 -111
- package/es/grid-component/TableGrid.js +2 -7
- package/es/grid-component/hooks/columns/index.d.ts +1 -1
- package/es/grid-component/hooks/columns/index.js +3 -13
- package/es/grid-component/hooks/useColumns.js +2 -0
- package/es/grid-component/hooks/utils.d.ts +1 -1
- package/es/grid-component/hooks/utils.js +3 -3
- package/es/grid-component/styles.scss +1186 -1170
- package/es/grid-component/table/Grid.d.ts +1 -0
- package/es/grid-component/table/GridEdit.d.ts +1 -0
- package/es/grid-component/table/GridEdit.js +156 -121
- package/es/grid-component/table/Group.d.ts +1 -0
- package/es/grid-component/type.d.ts +7 -2
- package/es/grid-component/useContext.d.ts +1 -0
- package/lib/grid-component/EditableCell.js +46 -15
- package/lib/grid-component/InternalTable.d.ts +1 -0
- package/lib/grid-component/InternalTable.js +467 -100
- package/lib/grid-component/TableGrid.js +2 -7
- package/lib/grid-component/hooks/columns/index.d.ts +1 -1
- package/lib/grid-component/hooks/columns/index.js +5 -15
- package/lib/grid-component/hooks/useColumns.js +2 -0
- package/lib/grid-component/hooks/utils.d.ts +1 -1
- package/lib/grid-component/hooks/utils.js +3 -3
- package/lib/grid-component/styles.scss +1186 -1170
- package/lib/grid-component/table/Grid.d.ts +1 -0
- package/lib/grid-component/table/GridEdit.d.ts +1 -0
- package/lib/grid-component/table/GridEdit.js +156 -121
- package/lib/grid-component/table/Group.d.ts +1 -0
- package/lib/grid-component/type.d.ts +7 -2
- package/lib/grid-component/useContext.d.ts +1 -0
- package/package.json +109 -109
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import React, { Fragment } from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import React, { createContext, Fragment, useCallback, useContext, useState } from 'react';
|
|
3
|
+
// import {Resizable} from "react-resizable";
|
|
4
4
|
import 'react-resizable/css/styles.css';
|
|
5
5
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
6
|
-
import { addRowIdArray,
|
|
7
|
-
// filterDataByColumns,
|
|
8
|
-
// filterDataByColumns2,
|
|
9
|
-
// filterDataByColumns3,
|
|
10
|
-
findItemByKey,
|
|
11
|
-
// convertFlatColumn,
|
|
12
|
-
removeColumns,
|
|
13
|
-
// removeFieldRecursive,
|
|
14
|
-
// addRowIdArray,
|
|
15
|
-
updateArrayByKey, updateColumnsByGroup, updateData } from "./hooks";
|
|
6
|
+
import { addRowIdArray, booleanOperator, findItemByKey, findItemPath, getFormat, getTypeFilter, numberOperator, removeColumns, stringOperator, translateOption, updateArrayByKey, updateColumnsByGroup, updateData } from "./hooks";
|
|
16
7
|
import dayjs from "dayjs";
|
|
17
8
|
import 'dayjs/locale/es';
|
|
18
9
|
import 'dayjs/locale/vi';
|
|
@@ -20,25 +11,74 @@ import GridEdit from "./table/GridEdit";
|
|
|
20
11
|
import Grid from "./table/Grid";
|
|
21
12
|
import en from "rc-master-ui/es/date-picker/locale/en_US";
|
|
22
13
|
import vi from "rc-master-ui/es/date-picker/locale/vi_VN";
|
|
23
|
-
import useColumns from "./hooks/useColumns";
|
|
14
|
+
// import useColumns from "./hooks/useColumns";
|
|
15
|
+
|
|
24
16
|
import "./styles.scss";
|
|
25
|
-
import { flatColumns2 } from "./hooks/columns";
|
|
17
|
+
import { flatColumns2, renderContent, renderFilter } from "./hooks/columns";
|
|
26
18
|
import Group from "./table/Group";
|
|
27
19
|
import Swal from "sweetalert2";
|
|
28
20
|
import withReactContent from "sweetalert2-react-content";
|
|
29
21
|
import { Tooltip } from "react-tooltip";
|
|
22
|
+
import classNames from "classnames";
|
|
23
|
+
import HeaderContent from "./hooks/content/HeaderContent";
|
|
24
|
+
import { ArrowDown, ArrowUp, FilterFill } from "becoxy-icons";
|
|
25
|
+
import { Select } from "rc-master-ui";
|
|
26
|
+
import { Button, Space } from "antd";
|
|
27
|
+
import { SearchOutlined } from "@ant-design/icons";
|
|
28
|
+
import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
|
|
29
|
+
import { closestCenter, DndContext, DragOverlay, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
|
|
30
|
+
import { arrayMove, horizontalListSortingStrategy, SortableContext, useSortable } from "@dnd-kit/sortable";
|
|
31
|
+
// import {CSS} from "@dnd-kit/utilities";
|
|
32
|
+
import { Resizable } from "react-resizable";
|
|
30
33
|
dayjs.extend(customParseFormat);
|
|
31
34
|
const MySwal = withReactContent(Swal);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
const ASCEND = 'ascend';
|
|
36
|
+
const DESCEND = 'descend';
|
|
37
|
+
export const SELECTION_COLUMN = {};
|
|
38
|
+
const dragActiveStyle = (dragState, id) => {
|
|
39
|
+
const {
|
|
40
|
+
active,
|
|
41
|
+
over,
|
|
42
|
+
direction
|
|
43
|
+
} = dragState;
|
|
44
|
+
// drag active style
|
|
45
|
+
let style = {};
|
|
46
|
+
if (active && active === id) {
|
|
47
|
+
style = {
|
|
48
|
+
backgroundColor: '#c0c0c0',
|
|
49
|
+
opacity: 0.3
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// dragover dashed style
|
|
53
|
+
else if (over && id === over && active !== over) {
|
|
54
|
+
style = direction === 'right' ? {
|
|
55
|
+
borderRight: '1px dashed gray'
|
|
56
|
+
} : {
|
|
57
|
+
borderLeft: '1px dashed gray'
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return style;
|
|
61
|
+
};
|
|
62
|
+
const DragIndexContext = /*#__PURE__*/createContext({
|
|
63
|
+
active: -1,
|
|
64
|
+
over: -1
|
|
65
|
+
});
|
|
36
66
|
const ResizableTitle = props => {
|
|
37
67
|
const {
|
|
38
68
|
onResize,
|
|
39
69
|
width,
|
|
40
70
|
...restProps
|
|
41
71
|
} = props;
|
|
72
|
+
const dragState = useContext(DragIndexContext);
|
|
73
|
+
|
|
74
|
+
// const { attributes, listeners, setNodeRef, isDragging } = useSortable({ id: props.id });
|
|
75
|
+
|
|
76
|
+
const style = {
|
|
77
|
+
...props.style,
|
|
78
|
+
// cursor: 'move',
|
|
79
|
+
// ...(isDragging ? { position: 'relative', zIndex: 9999, userSelect: 'none' } : {}),
|
|
80
|
+
...dragActiveStyle(dragState, props.id)
|
|
81
|
+
};
|
|
42
82
|
if (!width) {
|
|
43
83
|
return /*#__PURE__*/React.createElement("th", restProps);
|
|
44
84
|
}
|
|
@@ -58,9 +98,47 @@ const ResizableTitle = props => {
|
|
|
58
98
|
draggableOpts: {
|
|
59
99
|
enableUserSelectHack: false
|
|
60
100
|
}
|
|
61
|
-
}, /*#__PURE__*/React.createElement("th", restProps
|
|
101
|
+
}, /*#__PURE__*/React.createElement("th", _extends({}, restProps, {
|
|
102
|
+
style: style
|
|
103
|
+
})))
|
|
62
104
|
);
|
|
63
105
|
};
|
|
106
|
+
const TableBodyCell = props => {
|
|
107
|
+
const dragState = useContext(DragIndexContext);
|
|
108
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
109
|
+
style: {
|
|
110
|
+
...props.style,
|
|
111
|
+
...dragActiveStyle(dragState, props.id)
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
};
|
|
115
|
+
const SortableHeaderCell = ({
|
|
116
|
+
children,
|
|
117
|
+
columnKey
|
|
118
|
+
}) => {
|
|
119
|
+
const {
|
|
120
|
+
attributes,
|
|
121
|
+
listeners,
|
|
122
|
+
setNodeRef,
|
|
123
|
+
isDragging
|
|
124
|
+
} = useSortable({
|
|
125
|
+
id: columnKey
|
|
126
|
+
});
|
|
127
|
+
const style = {
|
|
128
|
+
// ...props.style,
|
|
129
|
+
cursor: 'move',
|
|
130
|
+
...(isDragging ? {
|
|
131
|
+
position: 'relative',
|
|
132
|
+
zIndex: 9999,
|
|
133
|
+
userSelect: 'none'
|
|
134
|
+
} : {})
|
|
135
|
+
// ...dragActiveStyle(dragState, props.id),
|
|
136
|
+
};
|
|
137
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
138
|
+
ref: setNodeRef,
|
|
139
|
+
style: style
|
|
140
|
+
}, attributes, listeners), children);
|
|
141
|
+
};
|
|
64
142
|
const InternalTable = props => {
|
|
65
143
|
const {
|
|
66
144
|
t,
|
|
@@ -89,6 +167,7 @@ const InternalTable = props => {
|
|
|
89
167
|
groupColumns,
|
|
90
168
|
commandClick,
|
|
91
169
|
commandSettings,
|
|
170
|
+
pagination,
|
|
92
171
|
...rest
|
|
93
172
|
} = props;
|
|
94
173
|
const rowKey = React.useMemo(() => {
|
|
@@ -106,32 +185,19 @@ const InternalTable = props => {
|
|
|
106
185
|
// const [isFilter, setIsFilter] = React.useState<boolean>(false);
|
|
107
186
|
// const [cellTooltip, seCellTooltip] = React.useState<any>(undefined);
|
|
108
187
|
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
188
|
+
const [dragIndex, setDragIndex] = useState({
|
|
189
|
+
active: -1,
|
|
190
|
+
over: -1
|
|
191
|
+
});
|
|
192
|
+
const [tooltipContent, setTooltipContent] = useState('');
|
|
193
|
+
const mergedData = React.useMemo(() => {
|
|
112
194
|
return addRowIdArray(dataSource);
|
|
113
|
-
// return dataSource
|
|
114
195
|
}, [dataSource]);
|
|
115
196
|
const [columns, setColumns] = React.useState([]);
|
|
116
197
|
const tableRef = React.useRef(null);
|
|
117
198
|
React.useEffect(() => {
|
|
118
199
|
setColumns(propsColumns);
|
|
119
200
|
}, [propsColumns]);
|
|
120
|
-
// }, [!!propsColumns.length && !!propsColumns])
|
|
121
|
-
|
|
122
|
-
// const [data, setData] = useState<RecordType[]>([]);
|
|
123
|
-
|
|
124
|
-
// const [isManualUpdate, setIsManualUpdate] = useState(false);
|
|
125
|
-
|
|
126
|
-
// useEffect(() => {
|
|
127
|
-
// if (!isManualUpdate) {
|
|
128
|
-
// const mergedData = addRowIdArray(dataSource)
|
|
129
|
-
//
|
|
130
|
-
// setData(mergedData || []);
|
|
131
|
-
// }
|
|
132
|
-
// setIsManualUpdate(false);
|
|
133
|
-
// }, [dataSource, isManualUpdate])
|
|
134
|
-
|
|
135
201
|
const handleResize = column => (e, {
|
|
136
202
|
size
|
|
137
203
|
}) => {
|
|
@@ -152,31 +218,287 @@ const InternalTable = props => {
|
|
|
152
218
|
return record => record?.[rowKey];
|
|
153
219
|
}, [rowKey]);
|
|
154
220
|
|
|
155
|
-
// const
|
|
156
|
-
//
|
|
157
|
-
//
|
|
221
|
+
// const [transformSelectionColumns] = useColumns<RecordType>(
|
|
222
|
+
// {
|
|
223
|
+
// locale,
|
|
224
|
+
// t,
|
|
225
|
+
// rowKey,
|
|
226
|
+
// // dataSource: mergerdData,
|
|
227
|
+
// dataSource,
|
|
228
|
+
// buddhistLocale,
|
|
229
|
+
// dataSourceFilter: propDataSourceFilter,
|
|
230
|
+
// format,
|
|
231
|
+
// sortMultiple,
|
|
232
|
+
// groupAble,
|
|
233
|
+
// groupSetting,
|
|
234
|
+
// groupColumns,
|
|
235
|
+
// handleResize,
|
|
236
|
+
// // onMouseHover
|
|
237
|
+
// },
|
|
238
|
+
// );
|
|
158
239
|
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
240
|
+
// const mergedColumns: any = React.useMemo(() => {
|
|
241
|
+
// return transformSelectionColumns(columns)
|
|
242
|
+
// }, [columns, transformSelectionColumns])
|
|
243
|
+
|
|
244
|
+
const firstNonGroupColumn = flatColumns2(columns).find(col => col.field && col.field !== '#' && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
245
|
+
const nonGroupColumns = flatColumns2(columns).filter(col => col.field && col.field !== '#' && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
246
|
+
const getColumnSearchProps = useCallback(column => ({
|
|
247
|
+
filterDropdown: ({
|
|
248
|
+
setSelectedKeys,
|
|
249
|
+
selectedKeys,
|
|
250
|
+
confirm,
|
|
251
|
+
setOperatorKey,
|
|
252
|
+
operatorKey,
|
|
253
|
+
visible,
|
|
254
|
+
searchValue,
|
|
255
|
+
setSearchValue
|
|
256
|
+
}) => {
|
|
257
|
+
const type = getTypeFilter(column);
|
|
258
|
+
const operatorOptions = type === ('Checkbox' || 'Dropdown' || 'DropTree' || 'CheckboxDropdown') ? booleanOperator : !type || type === 'Text' ? stringOperator : numberOperator;
|
|
259
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
260
|
+
style: {
|
|
261
|
+
padding: 8,
|
|
262
|
+
minWidth: 275
|
|
263
|
+
},
|
|
264
|
+
onKeyDown: e => e.stopPropagation()
|
|
265
|
+
}, column?.showOperator !== false && column?.typeFilter !== 'DateRange' && column?.typeFilter !== 'NumberRange' && /*#__PURE__*/React.createElement("div", {
|
|
266
|
+
className: 'mb-1'
|
|
267
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
268
|
+
options: translateOption(operatorOptions, t),
|
|
269
|
+
style: {
|
|
270
|
+
width: '100%',
|
|
271
|
+
marginBottom: 8
|
|
272
|
+
},
|
|
273
|
+
value: operatorKey,
|
|
274
|
+
onChange: val => {
|
|
275
|
+
setOperatorKey(val);
|
|
276
|
+
}
|
|
277
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
278
|
+
style: {
|
|
279
|
+
marginBottom: 8
|
|
280
|
+
}
|
|
281
|
+
}, renderFilter(column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, propDataSourceFilter ?? [], buddhistLocale, locale, t)), /*#__PURE__*/React.createElement(Space, {
|
|
282
|
+
style: {
|
|
283
|
+
justifyContent: 'end',
|
|
284
|
+
width: '100%'
|
|
285
|
+
}
|
|
286
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
287
|
+
type: "primary",
|
|
288
|
+
onClick: () => {
|
|
289
|
+
// confirm({closeDropdown: false})
|
|
290
|
+
confirm();
|
|
291
|
+
// handleSearch(selectedKeys as string[], confirm)
|
|
292
|
+
},
|
|
293
|
+
icon: /*#__PURE__*/React.createElement(SearchOutlined, null),
|
|
294
|
+
size: "small",
|
|
295
|
+
style: {
|
|
296
|
+
width: 90
|
|
297
|
+
}
|
|
298
|
+
}, t ? t('Filter') : 'Filter'), /*#__PURE__*/React.createElement(Button, {
|
|
299
|
+
type: "link",
|
|
300
|
+
size: "small",
|
|
301
|
+
onClick: () => {
|
|
302
|
+
// setSearchValue('')
|
|
303
|
+
setSelectedKeys([]);
|
|
304
|
+
confirm();
|
|
305
|
+
// handleSearch()
|
|
306
|
+
// close()
|
|
307
|
+
}
|
|
308
|
+
}, t ? t("Clear") : 'Clear')));
|
|
309
|
+
},
|
|
310
|
+
filterIcon: filtered => /*#__PURE__*/React.createElement(FilterFill, {
|
|
311
|
+
fontSize: 12
|
|
312
|
+
// onClick={() => {
|
|
313
|
+
// onFilterClick?.(column, onFilterCallback)
|
|
314
|
+
// }}
|
|
315
|
+
,
|
|
316
|
+
style: {
|
|
317
|
+
color: filtered ? '#E3165B' : '#283046'
|
|
318
|
+
}
|
|
319
|
+
}),
|
|
320
|
+
filterDropdownProps: {
|
|
321
|
+
onOpenChange(open) {
|
|
322
|
+
if (open) {
|
|
323
|
+
// setTimeout(() => searchInput.current?.select(), 100)
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}), [buddhistLocale, propDataSourceFilter, locale, t]);
|
|
328
|
+
const convertColumns = React.useMemo(() => {
|
|
329
|
+
return flatColumns2(columns).map((column, colIndex) => {
|
|
330
|
+
if (column === SELECTION_COLUMN) {
|
|
331
|
+
return SELECTION_COLUMN;
|
|
332
|
+
}
|
|
333
|
+
const transformedColumn = {
|
|
334
|
+
...column,
|
|
335
|
+
dataIndex: column.field ?? column.dataIndex,
|
|
336
|
+
// key: column.field ?? column.dataIndex ?? column.key,
|
|
337
|
+
// title: () => (<HeaderContent column={{...column} as any} t={t}/>),
|
|
338
|
+
title: /*#__PURE__*/React.createElement(SortableHeaderCell, {
|
|
339
|
+
columnKey: column.field
|
|
340
|
+
}, /*#__PURE__*/React.createElement(HeaderContent, {
|
|
341
|
+
column: {
|
|
342
|
+
...column
|
|
343
|
+
},
|
|
344
|
+
t: t
|
|
345
|
+
})),
|
|
346
|
+
ellipsis: column.ellipsis !== false,
|
|
347
|
+
align: column.textAlign ?? column.align,
|
|
348
|
+
fixed: column.fixedType ?? column.fixed,
|
|
349
|
+
isSummary: column.isSummary ?? column.haveSum,
|
|
350
|
+
hidden: column.hidden ?? column.visible === false
|
|
351
|
+
};
|
|
352
|
+
if (transformedColumn.field === '#') {
|
|
353
|
+
return {
|
|
354
|
+
...transformedColumn,
|
|
355
|
+
onCell: () => ({
|
|
356
|
+
className: 'cell-number'
|
|
357
|
+
}),
|
|
358
|
+
render: (val, record) => {
|
|
359
|
+
if (pagination && pagination.onChange && pagination.currentPage && pagination.pageSize) {
|
|
360
|
+
return findItemPath(mergedData, record, rowKey, pagination.currentPage, pagination.pageSize);
|
|
361
|
+
}
|
|
362
|
+
return findItemPath(mergedData, record, rowKey);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
if (transformedColumn.field === 'command') {
|
|
367
|
+
return {
|
|
368
|
+
...transformedColumn,
|
|
369
|
+
onCell: () => ({
|
|
370
|
+
className: 'cell-number',
|
|
371
|
+
style: {
|
|
372
|
+
padding: '2px 8px'
|
|
373
|
+
}
|
|
374
|
+
})
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
...transformedColumn,
|
|
379
|
+
...(transformedColumn.allowFiltering === false ? {} : {
|
|
380
|
+
...getColumnSearchProps(column)
|
|
381
|
+
}),
|
|
382
|
+
sorter: column.sorter === false ? undefined : {
|
|
383
|
+
compare: a => a,
|
|
384
|
+
multiple: sortMultiple ? colIndex : undefined
|
|
385
|
+
},
|
|
386
|
+
sortIcon: args => {
|
|
387
|
+
const {
|
|
388
|
+
sortOrder
|
|
389
|
+
} = args;
|
|
390
|
+
return /*#__PURE__*/React.createElement(Fragment, null, !sortOrder && /*#__PURE__*/React.createElement(ArrowUp, {
|
|
391
|
+
fontSize: 15,
|
|
392
|
+
style: {
|
|
393
|
+
display: 'flex',
|
|
394
|
+
opacity: 0,
|
|
395
|
+
marginLeft: 4
|
|
396
|
+
},
|
|
397
|
+
className: classNames(`ui-rc-table-column-sorter-up`, {
|
|
398
|
+
active: true
|
|
399
|
+
})
|
|
400
|
+
}), sortOrder === ASCEND && /*#__PURE__*/React.createElement("span", {
|
|
401
|
+
className: classNames(`ui-rc-table-column-sorter-up`, {
|
|
402
|
+
active: sortOrder === ASCEND
|
|
403
|
+
}),
|
|
404
|
+
style: {
|
|
405
|
+
display: 'flex',
|
|
406
|
+
marginLeft: 4
|
|
407
|
+
}
|
|
408
|
+
}, /*#__PURE__*/React.createElement(ArrowUp, {
|
|
409
|
+
fontSize: 15,
|
|
410
|
+
color: '#000'
|
|
411
|
+
})), sortOrder === DESCEND && /*#__PURE__*/React.createElement("span", {
|
|
412
|
+
className: classNames(`ui-rc-table-column-sorter-up`, {
|
|
413
|
+
active: sortOrder === DESCEND
|
|
414
|
+
}),
|
|
415
|
+
style: {
|
|
416
|
+
display: 'flex',
|
|
417
|
+
marginLeft: 4
|
|
418
|
+
}
|
|
419
|
+
}, /*#__PURE__*/React.createElement(ArrowDown, {
|
|
420
|
+
fontSize: 15,
|
|
421
|
+
color: '#000'
|
|
422
|
+
})));
|
|
423
|
+
},
|
|
424
|
+
onHeaderCell: () => ({
|
|
425
|
+
id: `${column.field}`,
|
|
426
|
+
width: column.width,
|
|
427
|
+
onResize: handleResize?.(column),
|
|
428
|
+
className: column.headerTextAlign === 'center' ? 'head-align-center' : column.headerTextAlign === 'right' ? 'head-align-right' : ''
|
|
429
|
+
}),
|
|
430
|
+
onCell: (data, index) => {
|
|
431
|
+
return {
|
|
432
|
+
id: `${column.field}`,
|
|
433
|
+
colSpan: groupColumns && data.children && column.field === firstNonGroupColumn?.field ? 2 : groupColumns && data.children && nonGroupColumns[1].field === column.field ? 0 : 1,
|
|
434
|
+
// 'z-index': data?.children && column.field === firstNonGroupColumn?.field ? 11 : undefined,
|
|
435
|
+
...transformedColumn?.onCell?.(data, index),
|
|
436
|
+
className: classNames(transformedColumn?.onCell?.(data, index).className ?? '', {
|
|
437
|
+
'cell-group': groupColumns && data.children,
|
|
438
|
+
'cell-group-fixed': groupColumns && data.children && column.field === firstNonGroupColumn?.field
|
|
439
|
+
}),
|
|
440
|
+
'data-tooltip-id': "tooltip-cell-content"
|
|
441
|
+
};
|
|
442
|
+
},
|
|
443
|
+
render: (value, record, rowIndex) => {
|
|
444
|
+
const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
|
|
445
|
+
const cellFormat = getFormat(colFormat, format);
|
|
446
|
+
if (groupSetting && groupSetting.hiddenColumnGroup === false) {
|
|
447
|
+
if (record.children) {
|
|
448
|
+
return renderContent(column, value, record, rowIndex, cellFormat);
|
|
449
|
+
}
|
|
450
|
+
if (groupColumns?.includes(column.field)) {
|
|
451
|
+
return '';
|
|
452
|
+
}
|
|
453
|
+
return renderContent(column, value, record, rowIndex, cellFormat);
|
|
454
|
+
}
|
|
455
|
+
if (column.field === firstNonGroupColumn?.field && record.children) {
|
|
456
|
+
const currentGroupColumn = flatColumns2(columns).find(it => it.field === record.field);
|
|
457
|
+
if (currentGroupColumn?.template) {
|
|
458
|
+
return renderContent(currentGroupColumn, record[record.field], record, rowIndex, cellFormat);
|
|
459
|
+
}
|
|
460
|
+
return /*#__PURE__*/React.createElement("span", null, currentGroupColumn?.headerText, ": ", renderContent(currentGroupColumn, record[record.field], record, rowIndex, cellFormat));
|
|
461
|
+
}
|
|
462
|
+
return renderContent(column, value, record, rowIndex, cellFormat);
|
|
463
|
+
},
|
|
464
|
+
hidden: groupSetting && groupSetting.hiddenColumnGroup === false ? transformedColumn.hidden : groupAble && groupColumns && groupColumns.includes(column.field) ? true : transformedColumn.hidden
|
|
465
|
+
};
|
|
466
|
+
});
|
|
467
|
+
}, [columns, t, getColumnSearchProps, sortMultiple, groupSetting, groupAble, groupColumns, pagination, mergedData, rowKey, handleResize, firstNonGroupColumn?.field, nonGroupColumns, format]);
|
|
468
|
+
const transformColumns = React.useCallback(cols => {
|
|
469
|
+
return cols.map(column => {
|
|
470
|
+
const find = convertColumns.find(it => it.field === column.field);
|
|
471
|
+
if (column === SELECTION_COLUMN) {
|
|
472
|
+
return SELECTION_COLUMN;
|
|
473
|
+
}
|
|
474
|
+
if (find) {
|
|
475
|
+
return {
|
|
476
|
+
...find
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
if (!find) {
|
|
480
|
+
return {
|
|
481
|
+
...column
|
|
482
|
+
};
|
|
483
|
+
}
|
|
178
484
|
|
|
179
|
-
|
|
485
|
+
// Xử lý đệ quy cho children
|
|
486
|
+
if (column.children?.length) {
|
|
487
|
+
return {
|
|
488
|
+
...column,
|
|
489
|
+
children: transformColumns(column.children)
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}, [convertColumns]);
|
|
494
|
+
const mergedColumns = React.useMemo(() => {
|
|
495
|
+
return transformColumns(columns);
|
|
496
|
+
}, [columns, transformColumns]);
|
|
497
|
+
const sensors = useSensors(useSensor(PointerSensor, {
|
|
498
|
+
activationConstraint: {
|
|
499
|
+
distance: 1
|
|
500
|
+
}
|
|
501
|
+
}));
|
|
180
502
|
const triggerChangeColumns = (newColumns, type) => {
|
|
181
503
|
setColumns(newColumns);
|
|
182
504
|
if (tableRef.current && type === 'columnChoose') {
|
|
@@ -191,6 +513,34 @@ const InternalTable = props => {
|
|
|
191
513
|
flattenColumns: []
|
|
192
514
|
});
|
|
193
515
|
};
|
|
516
|
+
const onDragEnd = ({
|
|
517
|
+
active,
|
|
518
|
+
over
|
|
519
|
+
}) => {
|
|
520
|
+
if (active.id !== over?.id) {
|
|
521
|
+
const targetColumn = flatColumns2(columns).find(it => it.field === over?.id);
|
|
522
|
+
const activeIndex = flatColumns2(columns).findIndex(i => i.field === active?.id);
|
|
523
|
+
const overIndex = flatColumns2(columns).findIndex(i => i.field === over?.id);
|
|
524
|
+
const rs = arrayMove(columns, activeIndex, overIndex);
|
|
525
|
+
triggerChangeColumns(rs, targetColumn && targetColumn.fixed === 'left' ? 'columnChoose' : '');
|
|
526
|
+
}
|
|
527
|
+
setDragIndex({
|
|
528
|
+
active: -1,
|
|
529
|
+
over: -1
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
const onDragOver = ({
|
|
533
|
+
active,
|
|
534
|
+
over
|
|
535
|
+
}) => {
|
|
536
|
+
const activeIndex = columns.findIndex(i => i.field === active.id);
|
|
537
|
+
const overIndex = columns.findIndex(i => i.field === over?.id);
|
|
538
|
+
setDragIndex({
|
|
539
|
+
active: active.id,
|
|
540
|
+
over: over?.id,
|
|
541
|
+
direction: overIndex > activeIndex ? 'right' : 'left'
|
|
542
|
+
});
|
|
543
|
+
};
|
|
194
544
|
const triggerGroupColumns = groupedColumns => {
|
|
195
545
|
setColumns(updateColumnsByGroup(mergedColumns, groupedColumns));
|
|
196
546
|
if (groupSetting) {
|
|
@@ -232,20 +582,6 @@ const InternalTable = props => {
|
|
|
232
582
|
onDataChange?.(newData);
|
|
233
583
|
// onDataChange?.(removeFieldRecursive(newData, 'isFilterState'))
|
|
234
584
|
};
|
|
235
|
-
|
|
236
|
-
// const triggerFilter = (queries: any) => {
|
|
237
|
-
// console.log('queries', queries)
|
|
238
|
-
// // console.log('data', dataSource)
|
|
239
|
-
// setFilterState(queries)
|
|
240
|
-
//
|
|
241
|
-
// if (queries && queries.length > 0) {
|
|
242
|
-
// setIsFilter(true)
|
|
243
|
-
// } else {
|
|
244
|
-
// setIsFilter(false)
|
|
245
|
-
// }
|
|
246
|
-
//
|
|
247
|
-
// }
|
|
248
|
-
|
|
249
585
|
const triggerCommandClick = args => {
|
|
250
586
|
const {
|
|
251
587
|
id,
|
|
@@ -253,7 +589,7 @@ const InternalTable = props => {
|
|
|
253
589
|
rowData,
|
|
254
590
|
index
|
|
255
591
|
} = args;
|
|
256
|
-
const tmpData = [...
|
|
592
|
+
const tmpData = [...mergedData];
|
|
257
593
|
if (id === 'DELETE') {
|
|
258
594
|
// bật modal confirm
|
|
259
595
|
if (commandSettings && commandSettings.confirmDialog) {
|
|
@@ -279,7 +615,7 @@ const InternalTable = props => {
|
|
|
279
615
|
|
|
280
616
|
let newData = [];
|
|
281
617
|
if (rowData?.parentId) {
|
|
282
|
-
const parent = findItemByKey(
|
|
618
|
+
const parent = findItemByKey(mergedData, rowKey, rowData.parentId);
|
|
283
619
|
const childData = parent?.children ? [...parent.children] : [];
|
|
284
620
|
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
285
621
|
childData.splice(Number(findIndex), 1);
|
|
@@ -311,7 +647,7 @@ const InternalTable = props => {
|
|
|
311
647
|
rowId: rowData.rowId,
|
|
312
648
|
rowData,
|
|
313
649
|
index,
|
|
314
|
-
rows: [...
|
|
650
|
+
rows: [...mergedData]
|
|
315
651
|
});
|
|
316
652
|
}
|
|
317
653
|
}
|
|
@@ -325,7 +661,7 @@ const InternalTable = props => {
|
|
|
325
661
|
|
|
326
662
|
let newData2 = [];
|
|
327
663
|
if (rowData?.parentId) {
|
|
328
|
-
const parent = findItemByKey(
|
|
664
|
+
const parent = findItemByKey(mergedData, rowKey, rowData.parentId);
|
|
329
665
|
const childData = parent?.children ? [...parent.children] : [];
|
|
330
666
|
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
331
667
|
childData.splice(Number(findIndex), 1);
|
|
@@ -355,7 +691,7 @@ const InternalTable = props => {
|
|
|
355
691
|
rowId,
|
|
356
692
|
rowData,
|
|
357
693
|
index,
|
|
358
|
-
rows: [...
|
|
694
|
+
rows: [...mergedData]
|
|
359
695
|
});
|
|
360
696
|
}
|
|
361
697
|
}
|
|
@@ -368,7 +704,7 @@ const InternalTable = props => {
|
|
|
368
704
|
};
|
|
369
705
|
const triggerPaste = (pastedRows, pastedColumnsArray, newData) => {
|
|
370
706
|
const handlePasteCallback = callbackData => {
|
|
371
|
-
const newDataUpdate = updateData(
|
|
707
|
+
const newDataUpdate = updateData(mergedData, callbackData, rowKey);
|
|
372
708
|
triggerChangeData(newDataUpdate);
|
|
373
709
|
|
|
374
710
|
// onCellPaste?.dataChange?.(newDataUpdate)
|
|
@@ -379,7 +715,7 @@ const InternalTable = props => {
|
|
|
379
715
|
onCellPaste.onPasted({
|
|
380
716
|
pasteData: pastedRows,
|
|
381
717
|
type: 'onPaste',
|
|
382
|
-
data:
|
|
718
|
+
data: mergedData,
|
|
383
719
|
pastedColumns: pastedColumnsArray
|
|
384
720
|
}, handlePasteCallback);
|
|
385
721
|
} else {
|
|
@@ -387,7 +723,7 @@ const InternalTable = props => {
|
|
|
387
723
|
onCellPaste.onPasted({
|
|
388
724
|
pasteData: pastedRows,
|
|
389
725
|
type: 'onPaste',
|
|
390
|
-
data:
|
|
726
|
+
data: mergedData,
|
|
391
727
|
pastedColumns: pastedColumnsArray
|
|
392
728
|
}, handlePasteCallback);
|
|
393
729
|
triggerChangeData(newData);
|
|
@@ -399,22 +735,23 @@ const InternalTable = props => {
|
|
|
399
735
|
}
|
|
400
736
|
};
|
|
401
737
|
const TableComponent = groupAble ? Group : editAble ? GridEdit : Grid;
|
|
402
|
-
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(
|
|
738
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(DndContext, {
|
|
739
|
+
sensors: sensors,
|
|
740
|
+
modifiers: [restrictToHorizontalAxis],
|
|
741
|
+
onDragEnd: onDragEnd,
|
|
742
|
+
onDragOver: onDragOver,
|
|
743
|
+
collisionDetection: closestCenter
|
|
744
|
+
}, /*#__PURE__*/React.createElement(SortableContext, {
|
|
745
|
+
items: columns.map(i => i.field),
|
|
746
|
+
strategy: horizontalListSortingStrategy
|
|
747
|
+
}, /*#__PURE__*/React.createElement(DragIndexContext.Provider, {
|
|
748
|
+
value: dragIndex
|
|
749
|
+
}, /*#__PURE__*/React.createElement(TableComponent, _extends({}, rest, {
|
|
403
750
|
t: t,
|
|
404
751
|
locale: locale,
|
|
405
752
|
tableRef: tableRef,
|
|
406
|
-
dataSource:
|
|
407
|
-
|
|
408
|
-
// components={components}
|
|
409
|
-
,
|
|
410
|
-
components: {
|
|
411
|
-
header: {
|
|
412
|
-
cell: allowResizing ? ResizableTitle : undefined
|
|
413
|
-
}
|
|
414
|
-
},
|
|
415
|
-
format: format
|
|
416
|
-
// columns={columns}
|
|
417
|
-
,
|
|
753
|
+
dataSource: mergedData,
|
|
754
|
+
format: format,
|
|
418
755
|
columns: mergedColumns,
|
|
419
756
|
showSorterTooltip: {
|
|
420
757
|
target: 'sorter-icon'
|
|
@@ -429,25 +766,44 @@ const InternalTable = props => {
|
|
|
429
766
|
groupSetting: groupSetting,
|
|
430
767
|
groupAble: groupAble,
|
|
431
768
|
groupColumns: groupColumns,
|
|
432
|
-
commandClick: triggerCommandClick
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
769
|
+
commandClick: triggerCommandClick,
|
|
770
|
+
pagination: pagination,
|
|
771
|
+
components: {
|
|
772
|
+
header: {
|
|
773
|
+
cell: ResizableTitle
|
|
774
|
+
},
|
|
775
|
+
body: {
|
|
776
|
+
cell: TableBodyCell
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
setTooltipContent: setTooltipContent
|
|
780
|
+
})))), /*#__PURE__*/React.createElement(DragOverlay, {
|
|
781
|
+
style: {
|
|
782
|
+
width: 100
|
|
783
|
+
}
|
|
784
|
+
}, /*#__PURE__*/React.createElement("th", {
|
|
785
|
+
style: {
|
|
786
|
+
backgroundColor: '#c4c4c4',
|
|
787
|
+
padding: 6,
|
|
788
|
+
borderRadius: 6,
|
|
789
|
+
fontWeight: 500
|
|
790
|
+
}
|
|
791
|
+
}, columns[columns.findIndex(i => i.field === dragIndex.active)]?.headerText))), /*#__PURE__*/React.createElement(Tooltip, {
|
|
792
|
+
id: "tooltip-form-error",
|
|
793
|
+
style: {
|
|
794
|
+
zIndex: 1999
|
|
795
|
+
}
|
|
796
|
+
}), /*#__PURE__*/React.createElement(Tooltip, {
|
|
438
797
|
id: "tooltip-cell-content",
|
|
439
798
|
style: {
|
|
440
799
|
zIndex: 1999
|
|
800
|
+
},
|
|
801
|
+
render: () => {
|
|
802
|
+
if (tooltipContent) {
|
|
803
|
+
return /*#__PURE__*/React.createElement("span", null, typeof tooltipContent === 'function' ? tooltipContent() : tooltipContent);
|
|
804
|
+
}
|
|
805
|
+
return undefined;
|
|
441
806
|
}
|
|
442
|
-
// content={'sssss'}
|
|
443
|
-
// content={cellTooltip}
|
|
444
|
-
// render={() => {
|
|
445
|
-
// return (
|
|
446
|
-
// <span>
|
|
447
|
-
// aaaa
|
|
448
|
-
// </span>
|
|
449
|
-
// )
|
|
450
|
-
// }}
|
|
451
807
|
}));
|
|
452
808
|
};
|
|
453
809
|
export default InternalTable;
|