es-grid-template 1.7.27 → 1.7.28
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/InternalTable.js +31 -36
- package/es/grid-component/TempTable.d.ts +4 -0
- package/es/grid-component/TempTable.js +21 -0
- package/es/grid-component/hooks/columns/index.js +3 -1
- package/es/grid-component/index.d.ts +2 -2
- package/es/grid-component/index.js +6 -4
- package/es/grid-component/styles.scss +0 -1
- package/es/grid-component/table/GridEdit.js +112 -96
- package/es/grid-component/type.d.ts +7 -1
- package/es/table-component/InternalTable.js +100 -127
- package/es/table-component/TableContainer.d.ts +6 -0
- package/es/table-component/TableContainer.js +74 -70
- package/es/table-component/TableContainerEdit.d.ts +4 -0
- package/es/table-component/TableContainerEdit.js +353 -81
- package/es/table-component/body/TableBody.d.ts +2 -8
- package/es/table-component/body/TableBody.js +1 -0
- package/es/table-component/body/TableBodyCell.d.ts +1 -1
- package/es/table-component/body/TableBodyCell.js +25 -13
- package/es/table-component/body/TableBodyCellEdit.d.ts +1 -1
- package/es/table-component/body/TableBodyCellEdit.js +24 -10
- package/es/table-component/body/TableBodyRow.d.ts +3 -3
- package/es/table-component/body/TableBodyRow.js +4 -6
- package/es/table-component/footer/TableFooter.d.ts +2 -8
- package/es/table-component/footer/TableFooter.js +14 -13
- package/es/table-component/footer/TableFooterCell.d.ts +3 -6
- package/es/table-component/footer/TableFooterCell.js +12 -10
- package/es/table-component/footer/TableFooterRow.d.ts +2 -8
- package/es/table-component/footer/TableFooterRow.js +23 -48
- package/es/table-component/header/TableHead.d.ts +4 -3
- package/es/table-component/header/TableHead.js +3 -61
- package/es/table-component/header/TableHeadCell.d.ts +0 -3
- package/es/table-component/header/TableHeadCell.js +10 -9
- package/es/table-component/header/TableHeadRow.d.ts +6 -6
- package/es/table-component/header/TableHeadRow.js +10 -32
- package/es/table-component/style.scss +24 -2
- package/es/table-component/table/Grid.d.ts +1 -0
- package/es/table-component/table/Grid.js +6 -3
- package/es/table-component/table/TableWrapper.d.ts +32 -0
- package/es/table-component/table/TableWrapper.js +242 -0
- package/es/table-component/type.d.ts +4 -4
- package/es/table-component/useContext.d.ts +4 -0
- package/es/table-component/useContext.js +4 -0
- package/lib/grid-component/InternalTable.js +30 -35
- package/lib/grid-component/TempTable.d.ts +4 -0
- package/lib/grid-component/TempTable.js +30 -0
- package/lib/grid-component/hooks/columns/index.js +3 -1
- package/lib/grid-component/index.d.ts +2 -2
- package/lib/grid-component/index.js +5 -3
- package/lib/grid-component/styles.scss +0 -1
- package/lib/grid-component/table/GridEdit.js +112 -96
- package/lib/grid-component/type.d.ts +7 -1
- package/lib/table-component/InternalTable.js +101 -127
- package/lib/table-component/TableContainer.d.ts +6 -0
- package/lib/table-component/TableContainer.js +76 -70
- package/lib/table-component/TableContainerEdit.d.ts +4 -0
- package/lib/table-component/TableContainerEdit.js +349 -79
- package/lib/table-component/body/TableBody.d.ts +2 -8
- package/lib/table-component/body/TableBody.js +2 -0
- package/lib/table-component/body/TableBodyCell.d.ts +1 -1
- package/lib/table-component/body/TableBodyCell.js +25 -13
- package/lib/table-component/body/TableBodyCellEdit.d.ts +1 -1
- package/lib/table-component/body/TableBodyCellEdit.js +24 -10
- package/lib/table-component/body/TableBodyRow.d.ts +3 -3
- package/lib/table-component/body/TableBodyRow.js +4 -6
- package/lib/table-component/footer/TableFooter.d.ts +2 -8
- package/lib/table-component/footer/TableFooter.js +15 -13
- package/lib/table-component/footer/TableFooterCell.d.ts +3 -6
- package/lib/table-component/footer/TableFooterCell.js +13 -10
- package/lib/table-component/footer/TableFooterRow.d.ts +2 -8
- package/lib/table-component/footer/TableFooterRow.js +23 -48
- package/lib/table-component/header/TableHead.d.ts +4 -3
- package/lib/table-component/header/TableHead.js +3 -61
- package/lib/table-component/header/TableHeadCell.d.ts +0 -3
- package/lib/table-component/header/TableHeadCell.js +10 -8
- package/lib/table-component/header/TableHeadRow.d.ts +6 -6
- package/lib/table-component/header/TableHeadRow.js +10 -32
- package/lib/table-component/style.scss +24 -2
- package/lib/table-component/table/Grid.d.ts +1 -0
- package/lib/table-component/table/Grid.js +6 -3
- package/lib/table-component/table/TableWrapper.d.ts +32 -0
- package/lib/table-component/table/TableWrapper.js +251 -0
- package/lib/table-component/type.d.ts +4 -4
- package/lib/table-component/useContext.d.ts +4 -0
- package/lib/table-component/useContext.js +4 -0
- package/package.json +1 -1
|
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _TableBody = _interopRequireDefault(require("./body/TableBody"));
|
|
11
|
-
var _TableHead = _interopRequireDefault(require("./header/TableHead"));
|
|
12
10
|
var _utils = require("./hook/utils");
|
|
13
11
|
var _reactVirtual = require("@tanstack/react-virtual");
|
|
14
12
|
var _reactHookForm = require("react-hook-form");
|
|
@@ -21,9 +19,12 @@ var _rcMasterUi = require("rc-master-ui");
|
|
|
21
19
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
22
20
|
var _becoxyIcons = require("becoxy-icons");
|
|
23
21
|
var _ColumnsChoose = require("./ColumnsChoose");
|
|
24
|
-
var
|
|
22
|
+
var _TableWrapper = _interopRequireDefault(require("./table/TableWrapper"));
|
|
23
|
+
var _sweetalert2ReactContent = _interopRequireDefault(require("sweetalert2-react-content"));
|
|
24
|
+
var _sweetalert = _interopRequireDefault(require("sweetalert2"));
|
|
25
25
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
26
26
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
27
|
+
const MySwal = (0, _sweetalert2ReactContent.default)(_sweetalert.default);
|
|
27
28
|
const {
|
|
28
29
|
Paragraph,
|
|
29
30
|
Title
|
|
@@ -78,8 +79,8 @@ const TableContainerEdit = props => {
|
|
|
78
79
|
// triggerFilter,
|
|
79
80
|
selectionSettings,
|
|
80
81
|
setIsSelectionChange,
|
|
81
|
-
onContextMenu,
|
|
82
|
-
contextMenuItems,
|
|
82
|
+
// onContextMenu,
|
|
83
|
+
contextMenuItems: propsContext,
|
|
83
84
|
setSorterChange,
|
|
84
85
|
setFilterChange,
|
|
85
86
|
// tableHeight,
|
|
@@ -111,11 +112,17 @@ const TableContainerEdit = props => {
|
|
|
111
112
|
columnHidden,
|
|
112
113
|
showEmptyText,
|
|
113
114
|
isFullScreen,
|
|
114
|
-
setIsFullScreen
|
|
115
|
+
setIsFullScreen,
|
|
116
|
+
infiniteScroll,
|
|
117
|
+
windowSize,
|
|
118
|
+
next,
|
|
119
|
+
loading,
|
|
120
|
+
contextMenuOpen,
|
|
121
|
+
contextMenuClick,
|
|
122
|
+
contextMenuHidden,
|
|
123
|
+
showDefaultContext,
|
|
124
|
+
commandSettings
|
|
115
125
|
} = props;
|
|
116
|
-
|
|
117
|
-
// console.log('setIsFullScreen', setIsFullScreen)
|
|
118
|
-
|
|
119
126
|
const containerRef = _react.default.useRef(null);
|
|
120
127
|
const bottomToolbarRef = _react.default.useRef(null);
|
|
121
128
|
const topToolbarRef = _react.default.useRef(null);
|
|
@@ -125,26 +132,126 @@ const TableContainerEdit = props => {
|
|
|
125
132
|
|
|
126
133
|
// //The virtualizers need to know the scrollable container element
|
|
127
134
|
const tableContainerRef = _react.default.useRef(null);
|
|
128
|
-
const visibleColumns = table.getVisibleLeafColumns();
|
|
129
|
-
const fixedLeftColumns = table.getState().columnPinning.left ? visibleColumns.filter(vc => table.getState().columnPinning.left?.includes(vc.id)) : [];
|
|
130
|
-
const fixedRightColumns = table.getState().columnPinning.right ? visibleColumns.filter(vc => table.getState().columnPinning.right?.includes(vc.id)) : [];
|
|
131
135
|
|
|
132
|
-
//
|
|
133
|
-
const columnVirtualizer = (0, _reactVirtual.useVirtualizer)({
|
|
134
|
-
count: visibleColumns.length,
|
|
135
|
-
estimateSize: index => visibleColumns[index].getSize(),
|
|
136
|
-
//estimate width of each column for accurate scrollbar dragging
|
|
137
|
-
getScrollElement: () => tableContainerRef.current,
|
|
138
|
-
horizontal: true,
|
|
139
|
-
// measureElement(element) {
|
|
136
|
+
// const columnSizingState = table.getState().columnSizing;
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
const defaultContext = _react.default.useMemo(() => {
|
|
139
|
+
return [{
|
|
140
|
+
key: 'INSERT_BEFORE',
|
|
141
|
+
// label: 'Thêm dòng bên trên',
|
|
142
|
+
// label: `${t ? t(locale?.add_rows_before ?? 'Add rows before') : 'Add rows before'}`,
|
|
143
|
+
label: locale?.add_rows_before ?? 'Add rows before',
|
|
144
|
+
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Plus, {
|
|
145
|
+
fontSize: 14
|
|
146
|
+
}),
|
|
147
|
+
children: [{
|
|
148
|
+
parentKey: 'INSERT_BEFORE',
|
|
149
|
+
key: 'INSERT_BEFORE_1',
|
|
150
|
+
label: locale?.add_1 ?? 'Add 1 rows',
|
|
151
|
+
row: 1
|
|
152
|
+
}, {
|
|
153
|
+
parentKey: 'INSERT_BEFORE',
|
|
154
|
+
key: 'INSERT_BEFORE_10',
|
|
155
|
+
label: locale?.add_10 ?? 'Add 10 rows',
|
|
156
|
+
row: 10
|
|
157
|
+
}, {
|
|
158
|
+
parentKey: 'INSERT_BEFORE',
|
|
159
|
+
key: 'INSERT_BEFORE_50',
|
|
160
|
+
label: locale?.add_50 ?? 'Add 50 rows',
|
|
161
|
+
row: 50
|
|
162
|
+
}, {
|
|
163
|
+
parentKey: 'INSERT_BEFORE',
|
|
164
|
+
key: 'INSERT_BEFORE_100',
|
|
165
|
+
label: locale?.add_100 ?? 'Add 100 rows',
|
|
166
|
+
row: 100
|
|
167
|
+
}, {
|
|
168
|
+
parentKey: 'INSERT_BEFORE',
|
|
169
|
+
key: 'INSERT_BEFORE_ADV',
|
|
170
|
+
label: locale?.custom ?? 'Custom'
|
|
171
|
+
}]
|
|
172
|
+
}, {
|
|
173
|
+
key: 'INSERT_AFTER',
|
|
174
|
+
label: locale?.add_rows_after ?? 'Add rows after',
|
|
175
|
+
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Plus, {
|
|
176
|
+
fontSize: 14
|
|
177
|
+
}),
|
|
178
|
+
children: [{
|
|
179
|
+
parentKey: 'INSERT_AFTER',
|
|
180
|
+
key: 'INSERT_AFTER_1',
|
|
181
|
+
label: locale?.add_1 ?? 'Add 1 rows',
|
|
182
|
+
row: 1
|
|
183
|
+
}, {
|
|
184
|
+
parentKey: 'INSERT_AFTER',
|
|
185
|
+
key: 'INSERT_AFTER_10',
|
|
186
|
+
label: locale?.add_10 ?? 'Add 10 rows',
|
|
187
|
+
row: 10
|
|
188
|
+
}, {
|
|
189
|
+
parentKey: 'INSERT_AFTER',
|
|
190
|
+
key: 'INSERT_AFTER_50',
|
|
191
|
+
label: locale?.add_50 ?? 'Add 50 rows',
|
|
192
|
+
row: 50
|
|
193
|
+
}, {
|
|
194
|
+
parentKey: 'INSERT_AFTER',
|
|
195
|
+
key: 'INSERT_AFTER_100',
|
|
196
|
+
label: locale?.add_100 ?? 'Add 100 rows',
|
|
197
|
+
row: 100
|
|
198
|
+
}, {
|
|
199
|
+
parentKey: 'INSERT_AFTER',
|
|
200
|
+
key: 'INSERT_AFTER_ADV',
|
|
201
|
+
label: locale?.custom ?? 'Custom'
|
|
202
|
+
}]
|
|
203
|
+
}, {
|
|
204
|
+
key: 'INSERT_CHILDREN',
|
|
205
|
+
// label: 'Insert item children',
|
|
206
|
+
label: locale?.add_children ?? 'Add children',
|
|
207
|
+
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Plus, {
|
|
208
|
+
fontSize: 14
|
|
209
|
+
})
|
|
210
|
+
// children: [
|
|
211
|
+
// {
|
|
212
|
+
// parentKey: 'INSERT_AFTER',
|
|
213
|
+
// key: 'INSERT_AFTER_1',
|
|
214
|
+
// label: 'Thêm 1 dòng',
|
|
215
|
+
// row: 1
|
|
216
|
+
// },
|
|
217
|
+
// {
|
|
218
|
+
// parentKey: 'INSERT_AFTER',
|
|
219
|
+
// key: 'INSERT_AFTER_10',
|
|
220
|
+
// label: 'Thêm 10 dòng',
|
|
221
|
+
// row: 10
|
|
222
|
+
// },
|
|
223
|
+
// {
|
|
224
|
+
// parentKey: 'INSERT_AFTER',
|
|
225
|
+
// key: 'INSERT_AFTER_50',
|
|
226
|
+
// label: 'Thêm 50 dòng',
|
|
227
|
+
// row: 50
|
|
228
|
+
// },
|
|
229
|
+
// {
|
|
230
|
+
// parentKey: 'INSERT_AFTER',
|
|
231
|
+
// key: 'INSERT_AFTER_100',
|
|
232
|
+
// label: 'Thêm 100 dòng',
|
|
233
|
+
// row: 100
|
|
234
|
+
// },
|
|
235
|
+
// {
|
|
236
|
+
// parentKey: 'INSERT_AFTER',
|
|
237
|
+
// key: 'INSERT_AFTER_ADV',
|
|
238
|
+
// label: 'Tùy chỉnh'
|
|
239
|
+
// }
|
|
240
|
+
// ]
|
|
241
|
+
}, {
|
|
242
|
+
key: 'DELETE_CONTENT',
|
|
243
|
+
label: locale?.delete_content ?? 'Delete content',
|
|
244
|
+
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Trash2, {
|
|
245
|
+
fontSize: 14
|
|
246
|
+
})
|
|
247
|
+
}, {
|
|
248
|
+
key: 'DELETE_ROWS',
|
|
249
|
+
label: locale?.delete_rows ?? 'Delete rows',
|
|
250
|
+
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Trash2, {
|
|
251
|
+
fontSize: 14
|
|
252
|
+
})
|
|
253
|
+
}];
|
|
254
|
+
}, [locale]);
|
|
148
255
|
const itemsAdd = _react.default.useMemo(() => {
|
|
149
256
|
return [{
|
|
150
257
|
key: '10',
|
|
@@ -157,12 +264,14 @@ const TableContainerEdit = props => {
|
|
|
157
264
|
label: `100 ${t ? t('rows') : 'rows'}`
|
|
158
265
|
}];
|
|
159
266
|
}, [t]);
|
|
267
|
+
const contextMenuItems = _react.default.useMemo(() => {
|
|
268
|
+
const a = showDefaultContext !== false ? [...defaultContext] : [];
|
|
269
|
+
const b = propsContext && propsContext.length > 0 ? [...propsContext, {
|
|
270
|
+
type: 'divider'
|
|
271
|
+
}] : [];
|
|
272
|
+
return [...b, ...a];
|
|
273
|
+
}, [defaultContext, propsContext, showDefaultContext]);
|
|
160
274
|
const [dataErrors, setDataErrors] = _react.default.useState([]);
|
|
161
|
-
_react.default.useEffect(() => {
|
|
162
|
-
requestAnimationFrame(() => {
|
|
163
|
-
columnVirtualizer.measure();
|
|
164
|
-
});
|
|
165
|
-
}, [columnSizingState, columnVirtualizer]);
|
|
166
275
|
_react.default.useEffect(() => {
|
|
167
276
|
if (validate && dataSource && dataSource.length) {
|
|
168
277
|
validateData(dataSource, validate).then(error => {
|
|
@@ -173,6 +282,25 @@ const TableContainerEdit = props => {
|
|
|
173
282
|
});
|
|
174
283
|
}
|
|
175
284
|
}, [validate, dataSource]);
|
|
285
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
286
|
+
const fixedLeftColumns = table.getState().columnPinning.left ? visibleColumns.filter(vc => table.getState().columnPinning.left?.includes(vc.id)) : [];
|
|
287
|
+
const fixedRightColumns = table.getState().columnPinning.right ? visibleColumns.filter(vc => table.getState().columnPinning.right?.includes(vc.id)) : [];
|
|
288
|
+
|
|
289
|
+
//we are using a slightly different virtualization strategy for columns (compared to virtual rows) in order to support dynamic row heights
|
|
290
|
+
const columnVirtualizer = (0, _reactVirtual.useVirtualizer)({
|
|
291
|
+
count: visibleColumns.length,
|
|
292
|
+
estimateSize: index => visibleColumns[index].getSize(),
|
|
293
|
+
//estimate width of each column for accurate scrollbar dragging
|
|
294
|
+
getScrollElement: () => tableContainerRef.current,
|
|
295
|
+
horizontal: true,
|
|
296
|
+
// measureElement(element) {
|
|
297
|
+
|
|
298
|
+
// return element?.getBoundingClientRect().width;
|
|
299
|
+
// },
|
|
300
|
+
|
|
301
|
+
measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element?.getBoundingClientRect().height : undefined,
|
|
302
|
+
overscan: 1 //how many columns to render on each side off screen each way (adjust this for performance)
|
|
303
|
+
});
|
|
176
304
|
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
177
305
|
const cacheColumns = columnVirtualizer.measurementsCache;
|
|
178
306
|
const rightCols = table.getState().columnPinning.right?.length ? [...cacheColumns].slice(-(table.getState().columnPinning.right?.length ?? 0)) : [];
|
|
@@ -1110,6 +1238,174 @@ const TableContainerEdit = props => {
|
|
|
1110
1238
|
};
|
|
1111
1239
|
});
|
|
1112
1240
|
}, [handleAddMulti, handleDeleteAll, handleDeleteRows, handleDuplicate, handleInsertAfter, handleInsertBefore, handleInsertChild, itemsAdd, rowsFocus, t, toolbarItems]);
|
|
1241
|
+
const triggerCommandClick = args => {
|
|
1242
|
+
const {
|
|
1243
|
+
id: idCommand,
|
|
1244
|
+
rowId,
|
|
1245
|
+
rowData,
|
|
1246
|
+
index
|
|
1247
|
+
} = args;
|
|
1248
|
+
const tmpData = [...dataSource];
|
|
1249
|
+
if (idCommand === 'DELETE') {
|
|
1250
|
+
// bật modal confirm
|
|
1251
|
+
if (commandSettings && commandSettings.confirmDialog) {
|
|
1252
|
+
MySwal.fire({
|
|
1253
|
+
title: t ? t('Confirm') : 'Confirm',
|
|
1254
|
+
text: t ? t('Do you want to delete item?') : 'Do you want to delete item?',
|
|
1255
|
+
// icon: 'warning',
|
|
1256
|
+
allowOutsideClick: false,
|
|
1257
|
+
showCancelButton: true,
|
|
1258
|
+
confirmButtonText: t ? t('Delete') : 'Delete',
|
|
1259
|
+
cancelButtonText: t ? t('Cancel') : 'Cancel',
|
|
1260
|
+
customClass: {
|
|
1261
|
+
confirmButton: 'be-button btn-primary',
|
|
1262
|
+
cancelButton: 'be-button btn-danger ms-1'
|
|
1263
|
+
},
|
|
1264
|
+
buttonsStyling: false
|
|
1265
|
+
}).then(async result => {
|
|
1266
|
+
if (result.value) {
|
|
1267
|
+
if (!commandSettings || commandSettings && commandSettings.client !== false) {
|
|
1268
|
+
// client
|
|
1269
|
+
|
|
1270
|
+
// kiểm tra dòng hiện tại có parent
|
|
1271
|
+
|
|
1272
|
+
let newData = [];
|
|
1273
|
+
if (rowData?.parentId) {
|
|
1274
|
+
const parent = (0, _utils.findItemByKey)(tmpData, rowKey, rowData.parentId);
|
|
1275
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
1276
|
+
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
1277
|
+
childData.splice(Number(findIndex), 1);
|
|
1278
|
+
const newRowData = {
|
|
1279
|
+
...parent,
|
|
1280
|
+
children: childData
|
|
1281
|
+
};
|
|
1282
|
+
// const newDataSource = updateArrayByKey(tmpData, newRowData, rowKey as string)
|
|
1283
|
+
newData = (0, _utils.updateArrayByKey)(tmpData, newRowData, rowKey);
|
|
1284
|
+
} else {
|
|
1285
|
+
tmpData.splice(Number(index), 1);
|
|
1286
|
+
newData = [...tmpData];
|
|
1287
|
+
}
|
|
1288
|
+
if (commandClick) {
|
|
1289
|
+
commandClick({
|
|
1290
|
+
id: idCommand,
|
|
1291
|
+
rowId: rowData.rowId,
|
|
1292
|
+
rowData,
|
|
1293
|
+
index,
|
|
1294
|
+
rows: [...newData]
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
} else {
|
|
1298
|
+
// server ~~ không làm gì
|
|
1299
|
+
if (commandClick) {
|
|
1300
|
+
commandClick({
|
|
1301
|
+
id: idCommand,
|
|
1302
|
+
rowId: rowData.rowId,
|
|
1303
|
+
rowData,
|
|
1304
|
+
index,
|
|
1305
|
+
rows: [...originData]
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
} else if (result.dismiss === MySwal.DismissReason.cancel) {}
|
|
1310
|
+
});
|
|
1311
|
+
} else {
|
|
1312
|
+
// -------------------
|
|
1313
|
+
|
|
1314
|
+
if (!commandSettings || commandSettings && commandSettings.client !== false) {
|
|
1315
|
+
// client
|
|
1316
|
+
|
|
1317
|
+
let newData2 = [];
|
|
1318
|
+
if (rowData?.parentId) {
|
|
1319
|
+
const parent = (0, _utils.findItemByKey)(originData, rowKey, rowData.parentId);
|
|
1320
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
1321
|
+
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
1322
|
+
childData.splice(Number(findIndex), 1);
|
|
1323
|
+
const newRowData = {
|
|
1324
|
+
...parent,
|
|
1325
|
+
children: childData
|
|
1326
|
+
};
|
|
1327
|
+
newData2 = (0, _utils.updateArrayByKey)(tmpData, newRowData, rowKey);
|
|
1328
|
+
} else {
|
|
1329
|
+
tmpData.splice(Number(index), 1);
|
|
1330
|
+
newData2 = [...tmpData];
|
|
1331
|
+
}
|
|
1332
|
+
if (commandClick) {
|
|
1333
|
+
commandClick({
|
|
1334
|
+
id: idCommand,
|
|
1335
|
+
rowId,
|
|
1336
|
+
rowData,
|
|
1337
|
+
index,
|
|
1338
|
+
rows: [...newData2]
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
} else {
|
|
1342
|
+
// server
|
|
1343
|
+
if (commandClick) {
|
|
1344
|
+
commandClick({
|
|
1345
|
+
id: idCommand,
|
|
1346
|
+
rowId,
|
|
1347
|
+
rowData,
|
|
1348
|
+
index,
|
|
1349
|
+
rows: [...originData]
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
} else {
|
|
1355
|
+
if (commandClick) {
|
|
1356
|
+
commandClick({
|
|
1357
|
+
...args,
|
|
1358
|
+
rows: originData
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
const triggerContextMenuClick = args => {
|
|
1364
|
+
if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
|
|
1365
|
+
if (args.item.key === 'INSERT_BEFORE_ADV') {
|
|
1366
|
+
// mở Modal
|
|
1367
|
+
|
|
1368
|
+
// setOpenModalAddRow((prev) => (
|
|
1369
|
+
// {
|
|
1370
|
+
// ...prev,
|
|
1371
|
+
// open: true,
|
|
1372
|
+
// type: 'INSERT_BEFORE'
|
|
1373
|
+
// }
|
|
1374
|
+
// ))
|
|
1375
|
+
} else {
|
|
1376
|
+
handleInsertBefore(args.item, args.item.row);
|
|
1377
|
+
}
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
if (args.item?.parentKey && args.item.parentKey === 'INSERT_AFTER') {
|
|
1381
|
+
if (args.item.key === 'INSERT_AFTER_ADV') {
|
|
1382
|
+
|
|
1383
|
+
// setOpenModalAddRow((prev) => (
|
|
1384
|
+
// {
|
|
1385
|
+
// ...prev,
|
|
1386
|
+
// open: true,
|
|
1387
|
+
// type: 'INSERT_AFTER'
|
|
1388
|
+
// }
|
|
1389
|
+
// ))
|
|
1390
|
+
} else {
|
|
1391
|
+
handleInsertAfter(args.item, args.item.row);
|
|
1392
|
+
}
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
if (args.item.key === 'INSERT_CHILDREN') {
|
|
1396
|
+
handleInsertChild(args.item);
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
if (args.item.key === 'DELETE_ROWS') {
|
|
1400
|
+
handleDeleteRows(args.item);
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
if (args.item.key === 'DELETE_CONTENT') {
|
|
1404
|
+
handleDeleteContent();
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
contextMenuClick?.(args);
|
|
1408
|
+
};
|
|
1113
1409
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
1114
1410
|
ref: containerRef,
|
|
1115
1411
|
id: id
|
|
@@ -1169,21 +1465,6 @@ const TableContainerEdit = props => {
|
|
|
1169
1465
|
columnHidden: columnHidden
|
|
1170
1466
|
})))), /*#__PURE__*/_react.default.createElement("form", {
|
|
1171
1467
|
onSubmit: handleSubmit(onSubmit)
|
|
1172
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
1173
|
-
// className="container"
|
|
1174
|
-
className: (0, _classnames.default)(`${prefix}-grid-container`, {
|
|
1175
|
-
'ui-rc-table-ping-right': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) >= 0 && (tableContainerRef.current?.scrollLeft ?? 0) + (tableContainerRef.current?.clientWidth ?? 0) < (tableContainerRef.current?.scrollWidth ?? 0),
|
|
1176
|
-
'ui-rc-table-ping-left': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) > 0
|
|
1177
|
-
}),
|
|
1178
|
-
ref: tableContainerRef,
|
|
1179
|
-
style: {
|
|
1180
|
-
overflow: 'auto',
|
|
1181
|
-
//our scrollable table container
|
|
1182
|
-
position: 'relative',
|
|
1183
|
-
//needed for sticky header
|
|
1184
|
-
// height: tableHeight, //should be a fixed height
|
|
1185
|
-
maxHeight: tableHeight //should be a fixed height
|
|
1186
|
-
}
|
|
1187
1468
|
}, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
|
|
1188
1469
|
value: {
|
|
1189
1470
|
locale,
|
|
@@ -1200,7 +1481,7 @@ const TableContainerEdit = props => {
|
|
|
1200
1481
|
recordDoubleClick,
|
|
1201
1482
|
selectionSettings,
|
|
1202
1483
|
setIsSelectionChange,
|
|
1203
|
-
onContextMenu,
|
|
1484
|
+
// onContextMenu,
|
|
1204
1485
|
setSorterChange,
|
|
1205
1486
|
setFilterChange,
|
|
1206
1487
|
rangeState,
|
|
@@ -1234,44 +1515,33 @@ const TableContainerEdit = props => {
|
|
|
1234
1515
|
triggerPaste,
|
|
1235
1516
|
handleDeleteContent,
|
|
1236
1517
|
handleAddMulti,
|
|
1237
|
-
dataErrors
|
|
1518
|
+
dataErrors,
|
|
1519
|
+
windowSize
|
|
1238
1520
|
}
|
|
1239
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
width: table.getTotalSize()
|
|
1245
|
-
}
|
|
1246
|
-
}, /*#__PURE__*/_react.default.createElement(_TableHead.default, {
|
|
1247
|
-
tableContainerRef: tableContainerRef,
|
|
1248
|
-
columnVirtualizer: columnVirtualizer,
|
|
1249
|
-
table: table,
|
|
1250
|
-
virtualPaddingLeft: virtualPaddingLeft,
|
|
1251
|
-
virtualPaddingRight: virtualPaddingRight,
|
|
1252
|
-
fixedLeftColumns: fixedLeftColumns,
|
|
1253
|
-
fixedRightColumns: fixedRightColumns
|
|
1254
|
-
}), /*#__PURE__*/_react.default.createElement(_TableBody.default, {
|
|
1255
|
-
tableId: id,
|
|
1256
|
-
columnVirtualizer: columnVirtualizer,
|
|
1521
|
+
}, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, {
|
|
1522
|
+
contextMenuItems: contextMenuItems,
|
|
1523
|
+
height: tableHeight,
|
|
1524
|
+
id: id,
|
|
1525
|
+
prefix: prefix,
|
|
1257
1526
|
table: table,
|
|
1258
1527
|
tableContainerRef: tableContainerRef,
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
commandClick: commandClick,
|
|
1528
|
+
commandClick: triggerCommandClick,
|
|
1529
|
+
contextMenuClick: triggerContextMenuClick,
|
|
1530
|
+
contextMenuHidden: contextMenuHidden,
|
|
1531
|
+
contextMenuOpen: contextMenuOpen,
|
|
1264
1532
|
editAble: editAble,
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1533
|
+
showEmptyText: showEmptyText,
|
|
1534
|
+
summary: summary,
|
|
1535
|
+
dataSource: dataSource,
|
|
1536
|
+
infiniteScroll: infiniteScroll,
|
|
1537
|
+
next: next,
|
|
1538
|
+
loading: loading,
|
|
1268
1539
|
columnVirtualizer: columnVirtualizer,
|
|
1269
|
-
table: table,
|
|
1270
1540
|
virtualPaddingLeft: virtualPaddingLeft,
|
|
1271
1541
|
virtualPaddingRight: virtualPaddingRight,
|
|
1272
1542
|
fixedLeftColumns: fixedLeftColumns,
|
|
1273
1543
|
fixedRightColumns: fixedRightColumns
|
|
1274
|
-
})))
|
|
1544
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
1275
1545
|
ref: bottomToolbarRef
|
|
1276
1546
|
}, toolbarItemsBottom && toolbarItemsBottom.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
1277
1547
|
className: 'ui-rc-toolbar-bottom'
|
|
@@ -1291,7 +1561,7 @@ const TableContainerEdit = props => {
|
|
|
1291
1561
|
onClick: ({}) => {
|
|
1292
1562
|
setEditingKey('');
|
|
1293
1563
|
}
|
|
1294
|
-
})), pagination && /*#__PURE__*/_react.default.createElement(_pagination.default
|
|
1564
|
+
})), pagination && !infiniteScroll && /*#__PURE__*/_react.default.createElement(_pagination.default
|
|
1295
1565
|
// style={{padding: '0.75rem 1rem'}}
|
|
1296
1566
|
, (0, _extends2.default)({}, pagination, {
|
|
1297
1567
|
rootClassName: 'pagination-template',
|
|
@@ -1299,7 +1569,7 @@ const TableContainerEdit = props => {
|
|
|
1299
1569
|
responsive: true,
|
|
1300
1570
|
size: 'small',
|
|
1301
1571
|
total: pagination.total,
|
|
1302
|
-
pageSize: pagination.onChange ? pagination
|
|
1572
|
+
pageSize: pagination.onChange ? pagination?.pageSize : table.getState().pagination.pageSize,
|
|
1303
1573
|
pageSizeOptions: [20, 50, 100, 1000, 10000],
|
|
1304
1574
|
onChange: (page, pageSize) => {
|
|
1305
1575
|
if (pagination.onChange) {
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type { Virtualizer } from "@tanstack/react-virtual";
|
|
1
|
+
import { type Table } from "@tanstack/react-table";
|
|
3
2
|
import type { CommandClick } from "../type";
|
|
4
3
|
import React from "react";
|
|
5
4
|
interface TableBodyProps<T> {
|
|
6
|
-
columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
|
7
5
|
table: Table<T>;
|
|
8
6
|
tableContainerRef: React.RefObject<HTMLDivElement>;
|
|
9
|
-
|
|
10
|
-
virtualPaddingRight: number | undefined;
|
|
11
|
-
fixedLeftColumns: Column<T, unknown>[];
|
|
12
|
-
fixedRightColumns: Column<T, unknown>[];
|
|
13
|
-
commandClick?: (args: CommandClick) => void;
|
|
7
|
+
commandClick?: (args: CommandClick<T>) => void;
|
|
14
8
|
editAble?: boolean;
|
|
15
9
|
tableId: string;
|
|
16
10
|
showEmptyText?: boolean;
|
|
@@ -13,6 +13,8 @@ var _useContext = require("../useContext");
|
|
|
13
13
|
var _rcMasterUi = require("rc-master-ui");
|
|
14
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
// import type { Virtualizer } from "@tanstack/react-virtual";
|
|
17
|
+
|
|
16
18
|
// import type { Dispatch, SetStateAction } from "react";
|
|
17
19
|
|
|
18
20
|
const TableBody = ({
|
|
@@ -4,7 +4,7 @@ import React from "react";
|
|
|
4
4
|
import type { VirtualItem } from "@tanstack/react-virtual";
|
|
5
5
|
interface TableBodyCellProps<T> {
|
|
6
6
|
cell: Cell<T, unknown>;
|
|
7
|
-
commandClick?: (args: CommandClick) => void;
|
|
7
|
+
commandClick?: (args: CommandClick<T>) => void;
|
|
8
8
|
table: Table<T>;
|
|
9
9
|
virtualRow?: VirtualItem;
|
|
10
10
|
}
|
|
@@ -22,7 +22,9 @@ const renderCellIndex = props => {
|
|
|
22
22
|
parrents,
|
|
23
23
|
cell
|
|
24
24
|
} = props;
|
|
25
|
-
return /*#__PURE__*/_react.default.createElement("span",
|
|
25
|
+
return /*#__PURE__*/_react.default.createElement("span", {
|
|
26
|
+
className: "ui-rc_cell-content"
|
|
27
|
+
}, parrents.map(pr => {
|
|
26
28
|
return `${pr.index + 1}.`;
|
|
27
29
|
}), cell.row.index + 1);
|
|
28
30
|
};
|
|
@@ -30,7 +32,8 @@ const renderCommand = args => {
|
|
|
30
32
|
const {
|
|
31
33
|
cell,
|
|
32
34
|
commandClick,
|
|
33
|
-
id
|
|
35
|
+
id,
|
|
36
|
+
data
|
|
34
37
|
} = args;
|
|
35
38
|
const col = cell.column.columnDef.meta ?? {};
|
|
36
39
|
const record = cell.row.original;
|
|
@@ -43,7 +46,9 @@ const renderCommand = args => {
|
|
|
43
46
|
visible: typeof it.visible === 'function' ? it.visible?.(record) : it.visible
|
|
44
47
|
};
|
|
45
48
|
}) : [];
|
|
46
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
49
|
+
return /*#__PURE__*/_react.default.createElement("span", {
|
|
50
|
+
className: "ui-rc_cell-content"
|
|
51
|
+
}, /*#__PURE__*/_react.default.createElement(_space.default, null, commands.filter(it => it.visible !== false).map(item => {
|
|
47
52
|
return /*#__PURE__*/_react.default.createElement(_Command.default, {
|
|
48
53
|
id: id,
|
|
49
54
|
key: item.id,
|
|
@@ -52,15 +57,14 @@ const renderCommand = args => {
|
|
|
52
57
|
onClick: () => {
|
|
53
58
|
commandClick?.({
|
|
54
59
|
id: item.id,
|
|
55
|
-
// rowId: getRowKey(record, index) as any,
|
|
56
60
|
rowId: record.rowId,
|
|
57
61
|
rowData: record,
|
|
58
|
-
index: cell.row.index
|
|
59
|
-
|
|
62
|
+
index: cell.row.index,
|
|
63
|
+
rows: [...data]
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
66
|
});
|
|
63
|
-
}));
|
|
67
|
+
})));
|
|
64
68
|
};
|
|
65
69
|
const renderSelection = args => {
|
|
66
70
|
const {
|
|
@@ -105,7 +109,9 @@ const TableBodyCell = props => {
|
|
|
105
109
|
prefix,
|
|
106
110
|
setIsSelectionChange,
|
|
107
111
|
selectionSettings,
|
|
108
|
-
id
|
|
112
|
+
id,
|
|
113
|
+
originData,
|
|
114
|
+
wrapSettings
|
|
109
115
|
} = (0, _react.useContext)(_useContext.TableContext);
|
|
110
116
|
const columnMeta = cell.column.columnDef.meta ?? {};
|
|
111
117
|
const parrents = cell.row.getParentRows();
|
|
@@ -118,12 +124,15 @@ const TableBodyCell = props => {
|
|
|
118
124
|
return /*#__PURE__*/_react.default.createElement("td", {
|
|
119
125
|
key: cell.id,
|
|
120
126
|
className: (0, _classnames.default)(`${prefix}-grid-cell`, {
|
|
121
|
-
[`${prefix}-grid-cell-ellipsis`]:
|
|
127
|
+
[`${prefix}-grid-cell-ellipsis`]: !wrapSettings || !(wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Content')),
|
|
128
|
+
[`${prefix}-grid-cell-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Content'),
|
|
122
129
|
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
123
|
-
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn
|
|
130
|
+
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
131
|
+
[`${prefix}-grid-cell-text-center`]: columnMeta?.headerTextAlign === 'center',
|
|
132
|
+
[`${prefix}-grid-cell-text-right`]: columnMeta?.headerTextAlign === 'right' || columnMeta.type === 'number'
|
|
124
133
|
}),
|
|
125
134
|
style: {
|
|
126
|
-
display: 'flex',
|
|
135
|
+
// display: 'flex',
|
|
127
136
|
width: cell.column.getSize(),
|
|
128
137
|
// border: '1px solid #e5e7eb',
|
|
129
138
|
...(0, _utils.getCommonPinningStyles)(cell.column)
|
|
@@ -149,12 +158,15 @@ const TableBodyCell = props => {
|
|
|
149
158
|
}), cell.column.id === "command" && renderCommand({
|
|
150
159
|
cell,
|
|
151
160
|
commandClick,
|
|
152
|
-
id
|
|
161
|
+
id,
|
|
162
|
+
data: originData
|
|
153
163
|
}), cell.column.id === "selection_column" && renderSelection({
|
|
154
164
|
cell,
|
|
155
165
|
table,
|
|
156
166
|
selectionSettings,
|
|
157
167
|
setIsSelectionChange
|
|
158
|
-
}), !_constant.nonActionColumn.includes(cell.column.id) && (
|
|
168
|
+
}), !_constant.nonActionColumn.includes(cell.column.id) && (isFirstRightPinnedColumn ? /*#__PURE__*/_react.default.createElement("span", {
|
|
169
|
+
className: "ui-rc_cell-content"
|
|
170
|
+
}, (0, _reactTable.flexRender)(cell.column.columnDef.cell, cell.getContext())) : (0, _reactTable.flexRender)(cell.column.columnDef.cell, cell.getContext())));
|
|
159
171
|
};
|
|
160
172
|
var _default = exports.default = TableBodyCell;
|
|
@@ -8,7 +8,7 @@ interface TableBodyCellProps<T> {
|
|
|
8
8
|
columnVirtualizer: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
|
9
9
|
tableId: string;
|
|
10
10
|
cell: Cell<T, unknown>;
|
|
11
|
-
commandClick?: (args: CommandClick) => void;
|
|
11
|
+
commandClick?: (args: CommandClick<T>) => void;
|
|
12
12
|
virtualRow: VirtualItem;
|
|
13
13
|
[key: string]: any;
|
|
14
14
|
}
|