es-grid-template 1.2.9 → 1.3.1
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/assets/index.css +16 -0
- package/assets/index.scss +37 -3
- package/es/grid-component/ColumnsGroup/ColumnsGroup.js +4 -4
- package/es/grid-component/ConvertColumnTable.js +1 -0
- package/es/grid-component/EditableCell.js +11 -8
- package/es/grid-component/InternalTable.js +19 -11
- package/es/grid-component/TableGrid.js +2 -0
- package/es/grid-component/hooks/useColumns.d.ts +4 -2
- package/es/grid-component/hooks/useColumns.js +10 -5
- package/es/grid-component/hooks/utils.d.ts +1 -0
- package/es/grid-component/hooks/utils.js +21 -0
- package/es/grid-component/styles.scss +24 -0
- package/es/grid-component/table/GridEdit.js +82 -47
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +4 -4
- package/lib/grid-component/ConvertColumnTable.js +1 -0
- package/lib/grid-component/EditableCell.js +11 -8
- package/lib/grid-component/InternalTable.js +19 -11
- package/lib/grid-component/TableGrid.js +1 -0
- package/lib/grid-component/hooks/useColumns.d.ts +4 -2
- package/lib/grid-component/hooks/useColumns.js +9 -4
- package/lib/grid-component/hooks/utils.d.ts +1 -0
- package/lib/grid-component/hooks/utils.js +24 -2
- package/lib/grid-component/styles.scss +24 -0
- package/lib/grid-component/table/GridEdit.js +80 -45
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import React, { Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
4
|
import classNames from "classnames";
|
|
5
5
|
import { Button, Dropdown, Form } from "antd";
|
|
@@ -13,7 +13,7 @@ import dayjs from "dayjs";
|
|
|
13
13
|
import 'dayjs/locale/es';
|
|
14
14
|
import 'dayjs/locale/vi';
|
|
15
15
|
import TableGrid from "../TableGrid";
|
|
16
|
-
import { addRows8, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isEditable, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
16
|
+
import { addRows8, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isEditable, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
17
17
|
import Message from "../../Message/Message";
|
|
18
18
|
// import Command from "../Command";
|
|
19
19
|
|
|
@@ -26,6 +26,7 @@ dayjs.extend(customParseFormat);
|
|
|
26
26
|
const toast = 'top-right';
|
|
27
27
|
const GridEdit = props => {
|
|
28
28
|
const {
|
|
29
|
+
id,
|
|
29
30
|
tableRef,
|
|
30
31
|
t,
|
|
31
32
|
columns,
|
|
@@ -60,6 +61,7 @@ const GridEdit = props => {
|
|
|
60
61
|
// selectedRowKeys,
|
|
61
62
|
// defaultSelectedRowKeys
|
|
62
63
|
} = selectionSettings || {};
|
|
64
|
+
const ref = useRef(null);
|
|
63
65
|
const isSelecting = useRef(false);
|
|
64
66
|
const startCell = useRef(null);
|
|
65
67
|
const childrenColumnName = 'children';
|
|
@@ -494,35 +496,53 @@ const GridEdit = props => {
|
|
|
494
496
|
useEffect(() => {
|
|
495
497
|
const handleClickOutside = event => {
|
|
496
498
|
const element = event.target;
|
|
497
|
-
|
|
499
|
+
|
|
500
|
+
// const tableId = id ? document.getElementById(id) : undefined
|
|
501
|
+
// const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
|
|
498
502
|
const container = document.querySelector(".be-popup-container");
|
|
503
|
+
const tableBody = document.querySelector(`#${id} .ui-rc-table-tbody`);
|
|
499
504
|
// const containerHidden = document.querySelector(".be-popup-container.ant-picker-dropdown-hidden")
|
|
500
505
|
|
|
501
506
|
// const toolbarContainer = document.getElementsByClassName("ui-rc-toolbar");
|
|
502
|
-
const itemContainer = document.querySelector(
|
|
507
|
+
const itemContainer = document.querySelector(`#${id} .ui-rc-toolbar-selection-overflow-item`);
|
|
503
508
|
const isInsideContainer = element.closest(".be-popup-container") && container;
|
|
504
|
-
const isInsideToolbar = element.closest(
|
|
509
|
+
const isInsideToolbar = element.closest(`#${id} .ui-rc-toolbar-selection-overflow-item`) && itemContainer;
|
|
505
510
|
if (isInsideContainer || isInsideToolbar) {
|
|
511
|
+
// console.log('ooooooooooooo')
|
|
506
512
|
return;
|
|
507
513
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
} else {}
|
|
514
|
+
|
|
515
|
+
// if (ref.current && !ref.current.contains(event.target)) {
|
|
516
|
+
// if (ref.current && tableId && !tableId.contains(event.target as Node)) {
|
|
517
|
+
if (ref.current && tableBody && !tableBody.contains(event.target)) {
|
|
518
|
+
setEditingKey('');
|
|
519
|
+
isSelecting.current = false;
|
|
520
|
+
startCell.current = null;
|
|
521
|
+
setSelectedCells(new Set());
|
|
522
|
+
setRowsSelected(new Set());
|
|
518
523
|
}
|
|
524
|
+
|
|
525
|
+
// if (tableBodies.length > 0) {
|
|
526
|
+
// const tableBody = tableBodies[0]; // Chọn tbody đầu tiên (nếu có nhiều)
|
|
527
|
+
//
|
|
528
|
+
// if (!tableBody.contains(event.target as Node)) {
|
|
529
|
+
// setEditingKey('')
|
|
530
|
+
// isSelecting.current = false;
|
|
531
|
+
// startCell.current = null;
|
|
532
|
+
// setSelectedCells(new Set())
|
|
533
|
+
// setRowsSelected(new Set())
|
|
534
|
+
// } else {
|
|
535
|
+
//
|
|
536
|
+
// }
|
|
537
|
+
// }
|
|
519
538
|
};
|
|
520
539
|
document.addEventListener("click", handleClickOutside);
|
|
521
540
|
return () => {
|
|
522
541
|
document.removeEventListener("click", handleClickOutside);
|
|
523
542
|
};
|
|
524
543
|
}, []);
|
|
525
|
-
const handleMouseDown = (record, row, col, e) => {
|
|
544
|
+
const handleMouseDown = useCallback((record, row, col, e) => {
|
|
545
|
+
setEditingKey('');
|
|
526
546
|
if (e.button === 2) {
|
|
527
547
|
e.stopPropagation();
|
|
528
548
|
return;
|
|
@@ -559,7 +579,7 @@ const GridEdit = props => {
|
|
|
559
579
|
// setSelectedCells(new Set([`${row}-${col}`]));
|
|
560
580
|
// setRowsSelected(new Set())
|
|
561
581
|
// }
|
|
562
|
-
};
|
|
582
|
+
}, []);
|
|
563
583
|
|
|
564
584
|
// const handlePointEnter = (e: any) => {
|
|
565
585
|
//
|
|
@@ -853,7 +873,7 @@ const GridEdit = props => {
|
|
|
853
873
|
const selectedArray = Array.from(selectedCells).map(key => {
|
|
854
874
|
const [row, col] = key.split("-").map(Number);
|
|
855
875
|
// @ts-ignore
|
|
856
|
-
const columnKey = columns[col].field;
|
|
876
|
+
const columnKey = editAbleColumns(columns)[col - 1].field;
|
|
857
877
|
|
|
858
878
|
// @ts-ignore
|
|
859
879
|
return {
|
|
@@ -932,16 +952,17 @@ const GridEdit = props => {
|
|
|
932
952
|
// Không vượt quá số cột
|
|
933
953
|
return;
|
|
934
954
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
955
|
+
if (columns[targetCol].editEnable) {
|
|
956
|
+
// @ts-ignore
|
|
957
|
+
const columnKey = columns[targetCol].field;
|
|
958
|
+
|
|
959
|
+
// @ts-ignore
|
|
960
|
+
newData[targetRow] = {
|
|
961
|
+
...newData[targetRow],
|
|
962
|
+
[columnKey]: cellValue.trim()
|
|
963
|
+
};
|
|
964
|
+
pastedColumns.add(columnKey);
|
|
965
|
+
}
|
|
945
966
|
});
|
|
946
967
|
|
|
947
968
|
// Lưu dòng được paste
|
|
@@ -980,16 +1001,17 @@ const GridEdit = props => {
|
|
|
980
1001
|
// Không vượt quá số cột
|
|
981
1002
|
return;
|
|
982
1003
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1004
|
+
if (columns[targetCol].editEnable) {
|
|
1005
|
+
// @ts-ignore
|
|
1006
|
+
const columnKey = columns[targetCol].field;
|
|
1007
|
+
|
|
1008
|
+
// @ts-ignore
|
|
1009
|
+
childData[targetRow] = {
|
|
1010
|
+
...childData[targetRow],
|
|
1011
|
+
[columnKey]: cellValue.trim()
|
|
1012
|
+
};
|
|
1013
|
+
pastedColumns.add(columnKey);
|
|
1014
|
+
}
|
|
993
1015
|
});
|
|
994
1016
|
|
|
995
1017
|
// Lưu dòng được paste
|
|
@@ -1288,7 +1310,7 @@ const GridEdit = props => {
|
|
|
1288
1310
|
tabIndex: (rowIndex ?? 0) * columns.length + colIndex
|
|
1289
1311
|
};
|
|
1290
1312
|
},
|
|
1291
|
-
render: (value, record
|
|
1313
|
+
render: (value, record) => {
|
|
1292
1314
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1293
1315
|
return /*#__PURE__*/React.createElement("div", {
|
|
1294
1316
|
className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {
|
|
@@ -1297,10 +1319,11 @@ const GridEdit = props => {
|
|
|
1297
1319
|
}),
|
|
1298
1320
|
onMouseDown: event => handleMouseDownColIndex(rowNumber, colIndex, event),
|
|
1299
1321
|
onMouseEnter: event => handleMouseEnterColIndex(rowNumber, colIndex, event),
|
|
1300
|
-
onClick: () => handleClickRowHeader(rowNumber, colIndex)
|
|
1322
|
+
onClick: () => handleClickRowHeader(rowNumber, colIndex),
|
|
1323
|
+
onMouseUp: handleMouseUp
|
|
1301
1324
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1302
1325
|
className: 'ui-rc_content'
|
|
1303
|
-
},
|
|
1326
|
+
}, findItemPath(dataSource, record, rowKey)));
|
|
1304
1327
|
}
|
|
1305
1328
|
};
|
|
1306
1329
|
}
|
|
@@ -1314,6 +1337,10 @@ const GridEdit = props => {
|
|
|
1314
1337
|
onCell: (record, rowIndex) => {
|
|
1315
1338
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1316
1339
|
return {
|
|
1340
|
+
// onKeyPress: () => {
|
|
1341
|
+
//
|
|
1342
|
+
// },
|
|
1343
|
+
|
|
1317
1344
|
onKeyDown: event => {
|
|
1318
1345
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
1319
1346
|
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
|
|
@@ -1427,14 +1454,15 @@ const GridEdit = props => {
|
|
|
1427
1454
|
return /*#__PURE__*/React.createElement("div", {
|
|
1428
1455
|
className: classNames('ui-rc_cell-content', {
|
|
1429
1456
|
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
1430
|
-
selected: selectedCells.has(`${rowNumber}-${colIndex}`)
|
|
1457
|
+
selected: selectedCells.has(`${rowNumber}-${colIndex}`),
|
|
1458
|
+
disable: !isEditable(column, record)
|
|
1431
1459
|
}),
|
|
1432
1460
|
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
1433
1461
|
onMouseEnter: () => handleMouseEnter(rowNumber, colIndex),
|
|
1434
1462
|
onMouseUp: handleMouseUp
|
|
1435
1463
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1436
1464
|
className: 'ui-rc_content'
|
|
1437
|
-
}, renderContent(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && isEditable(column, record)
|
|
1465
|
+
}, renderContent(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && isEditable(column, record) && !isSelectDragging &&
|
|
1438
1466
|
/*#__PURE__*/
|
|
1439
1467
|
// showDraggingPoint &&
|
|
1440
1468
|
React.createElement("div", {
|
|
@@ -1500,7 +1528,8 @@ const GridEdit = props => {
|
|
|
1500
1528
|
style: {
|
|
1501
1529
|
position: 'relative'
|
|
1502
1530
|
},
|
|
1503
|
-
|
|
1531
|
+
ref: ref
|
|
1532
|
+
// onMouseUp={handleMouseUp}
|
|
1504
1533
|
}, /*#__PURE__*/React.createElement(TableContext.Provider, {
|
|
1505
1534
|
value: {
|
|
1506
1535
|
rowKey,
|
|
@@ -1521,7 +1550,7 @@ const GridEdit = props => {
|
|
|
1521
1550
|
rowHoverBg: '#eb461912',
|
|
1522
1551
|
rowSelectedBg: '#eb4619',
|
|
1523
1552
|
rowSelectedHoverBg: '#eb4619',
|
|
1524
|
-
cellFontSize: 12,
|
|
1553
|
+
// cellFontSize: 12,
|
|
1525
1554
|
cellFontSizeSM: 13,
|
|
1526
1555
|
headerBg: '#ffffff',
|
|
1527
1556
|
cellPaddingBlockSM: 7
|
|
@@ -1534,11 +1563,13 @@ const GridEdit = props => {
|
|
|
1534
1563
|
}
|
|
1535
1564
|
}, /*#__PURE__*/React.createElement(TableGrid, _extends({}, rest, {
|
|
1536
1565
|
t: t,
|
|
1566
|
+
id: id,
|
|
1537
1567
|
tableRef: tableRef,
|
|
1538
1568
|
dataSource: dataSource,
|
|
1539
1569
|
components: {
|
|
1540
1570
|
...components,
|
|
1541
1571
|
body: {
|
|
1572
|
+
// wrapper: () => <div></div>,
|
|
1542
1573
|
cell: EditableCell
|
|
1543
1574
|
// cell: () => <EditableCell />,
|
|
1544
1575
|
}
|
|
@@ -1551,11 +1582,15 @@ const GridEdit = props => {
|
|
|
1551
1582
|
target: 'sorter-icon'
|
|
1552
1583
|
},
|
|
1553
1584
|
format: format,
|
|
1554
|
-
toolbarItems: toolbarItems
|
|
1585
|
+
toolbarItems: toolbarItems
|
|
1586
|
+
// selectionSettings={selectionSettings ? {...selectionSettings, checkboxOnly: true} : undefined}
|
|
1587
|
+
,
|
|
1555
1588
|
selectionSettings: selectionSettings ? {
|
|
1556
1589
|
...selectionSettings,
|
|
1557
1590
|
checkboxOnly: true
|
|
1558
|
-
} :
|
|
1591
|
+
} : {
|
|
1592
|
+
checkboxOnly: true
|
|
1593
|
+
},
|
|
1559
1594
|
rowHoverable: false,
|
|
1560
1595
|
bottomToolbar: bottomToolbar,
|
|
1561
1596
|
expandable: {
|
|
@@ -43,7 +43,7 @@ const ColumnsGroup = props => {
|
|
|
43
43
|
return rsCol.map(it => ({
|
|
44
44
|
...it,
|
|
45
45
|
value: it.field,
|
|
46
|
-
label: t ? t(it
|
|
46
|
+
label: t ? t(it?.columnGroupText ?? it?.headerText) : it?.columnGroupText ?? it?.headerText
|
|
47
47
|
}));
|
|
48
48
|
}, [rsCol, t]);
|
|
49
49
|
|
|
@@ -146,7 +146,7 @@ const ColumnsGroup = props => {
|
|
|
146
146
|
,
|
|
147
147
|
labelRender: labelProps => {
|
|
148
148
|
const it = columns.find(col => col.field === labelProps.value);
|
|
149
|
-
return t ? t(it
|
|
149
|
+
return t ? t(it?.columnGroupText ?? it?.headerText) : it?.columnGroupText ?? it?.headerText;
|
|
150
150
|
}
|
|
151
151
|
// hideSelectedOptions
|
|
152
152
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -175,7 +175,7 @@ const ColumnsGroup = props => {
|
|
|
175
175
|
,
|
|
176
176
|
labelRender: labelProps => {
|
|
177
177
|
const it = columns.find(col => col.field === labelProps.value);
|
|
178
|
-
return t ? t(it
|
|
178
|
+
return t ? t(it?.columnGroupText ?? it?.headerText) : it?.columnGroupText ?? it?.headerText;
|
|
179
179
|
}
|
|
180
180
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
181
181
|
className: 'mb-1',
|
|
@@ -202,7 +202,7 @@ const ColumnsGroup = props => {
|
|
|
202
202
|
,
|
|
203
203
|
labelRender: labelProps => {
|
|
204
204
|
const it = columns.find(col => col.field === labelProps.value);
|
|
205
|
-
return t ? t(it
|
|
205
|
+
return t ? t(it?.columnGroupText ?? it?.headerText) : it?.columnGroupText ?? it?.headerText;
|
|
206
206
|
}
|
|
207
207
|
}))), /*#__PURE__*/_react.default.createElement(BoxAction, {
|
|
208
208
|
className: 'px-1'
|
|
@@ -126,7 +126,7 @@ const EditableCell = props => {
|
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
},
|
|
129
|
-
placeholder: column.placeholder,
|
|
129
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
130
130
|
disabled: (0, _hooks.isDisable)(column, record) ?? false,
|
|
131
131
|
maxDate: maxDate,
|
|
132
132
|
minDate: minDate
|
|
@@ -166,7 +166,7 @@ const EditableCell = props => {
|
|
|
166
166
|
},
|
|
167
167
|
showTime: true,
|
|
168
168
|
value: date,
|
|
169
|
-
placeholder: column.placeholder,
|
|
169
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
170
170
|
disabled: (0, _hooks.isDisable)(column, record) ?? false,
|
|
171
171
|
maxDate: maxDate,
|
|
172
172
|
minDate: minDate,
|
|
@@ -217,7 +217,7 @@ const EditableCell = props => {
|
|
|
217
217
|
height: '100%'
|
|
218
218
|
},
|
|
219
219
|
picker: editType,
|
|
220
|
-
placeholder: column.placeholder,
|
|
220
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
221
221
|
disabled: (0, _hooks.isDisable)(column, record) ?? false,
|
|
222
222
|
maxDate: maxDateValue1,
|
|
223
223
|
minDate: minDateValue1,
|
|
@@ -234,7 +234,7 @@ const EditableCell = props => {
|
|
|
234
234
|
height: '100%'
|
|
235
235
|
},
|
|
236
236
|
picker: editType,
|
|
237
|
-
placeholder: column.placeholder,
|
|
237
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
238
238
|
disabled: (0, _hooks.isDisable)(column, record) ?? false,
|
|
239
239
|
maxDate: maxWeekValue,
|
|
240
240
|
minDate: minWeekValue,
|
|
@@ -254,6 +254,7 @@ const EditableCell = props => {
|
|
|
254
254
|
format: timeFormat,
|
|
255
255
|
type: 'mask'
|
|
256
256
|
},
|
|
257
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
257
258
|
maxDate: maxTime,
|
|
258
259
|
minDate: minTime,
|
|
259
260
|
disabled: (0, _hooks.isDisable)(column, record) ?? false,
|
|
@@ -327,7 +328,7 @@ const EditableCell = props => {
|
|
|
327
328
|
defaultOpen: column.field === cellEditing?.column.field
|
|
328
329
|
// autoFocus={true}
|
|
329
330
|
,
|
|
330
|
-
placeholder: t ? t('Select') : 'Select',
|
|
331
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
331
332
|
allowClear: column.isClearable ?? false,
|
|
332
333
|
maxTagCount: 'responsive',
|
|
333
334
|
rowKey: keySelect,
|
|
@@ -407,7 +408,7 @@ const EditableCell = props => {
|
|
|
407
408
|
width: '100%',
|
|
408
409
|
height: '100%'
|
|
409
410
|
},
|
|
410
|
-
placeholder: t ? t('Select') : 'Select',
|
|
411
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
411
412
|
allowClear: column.isClearable ?? false,
|
|
412
413
|
maxTagCount: 'responsive',
|
|
413
414
|
popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
|
|
@@ -461,7 +462,7 @@ const EditableCell = props => {
|
|
|
461
462
|
width: '100%',
|
|
462
463
|
height: '100%'
|
|
463
464
|
},
|
|
464
|
-
placeholder: t ? t('Select') : 'Select',
|
|
465
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
465
466
|
allowClear: column.isClearable ?? false,
|
|
466
467
|
maxTagCount: 'responsive',
|
|
467
468
|
popupMatchSelectWidth: menuWidth ? menuWidth + 10 : undefined,
|
|
@@ -531,7 +532,7 @@ const EditableCell = props => {
|
|
|
531
532
|
overflow: 'auto'
|
|
532
533
|
},
|
|
533
534
|
treeData: newTreeData,
|
|
534
|
-
placeholder: t ? t('Select') : 'Select',
|
|
535
|
+
placeholder: t ? t(column.placeholder ?? 'Select') : column.placeholder ?? 'Select',
|
|
535
536
|
treeDefaultExpandAll: true,
|
|
536
537
|
defaultOpen: column.field === cellEditing?.column.field
|
|
537
538
|
// autoFocus={true}
|
|
@@ -745,6 +746,7 @@ const EditableCell = props => {
|
|
|
745
746
|
customInput: _antd.Input
|
|
746
747
|
// valueIsNumericString={true}
|
|
747
748
|
,
|
|
749
|
+
placeholder: t ? t(column.placeholder ?? 'Enter') : column.placeholder ?? 'Enter',
|
|
748
750
|
autoComplete: 'off',
|
|
749
751
|
className: (0, _classnames.default)('be-cell-editing rounded-0 input-element', {
|
|
750
752
|
'is-invalid': isInvalid,
|
|
@@ -788,6 +790,7 @@ const EditableCell = props => {
|
|
|
788
790
|
,
|
|
789
791
|
disabled: (0, _hooks.isDisable)(column, record) ?? false,
|
|
790
792
|
className: (0, _classnames.default)('be-cell-editing rounded-0 input-element'),
|
|
793
|
+
placeholder: t ? t(column.placeholder ?? 'Enter') : column.placeholder ?? 'Enter',
|
|
791
794
|
value: !(0, _hooks.isNullOrUndefined)(value) ? value : '',
|
|
792
795
|
onBlur: () => {
|
|
793
796
|
const formState = getValues();
|
|
@@ -130,9 +130,20 @@ const InternalTable = props => {
|
|
|
130
130
|
const newColumns = (0, _hooks.updateArrayByKey)(columns, newColumn, 'field');
|
|
131
131
|
setColumns(newColumns);
|
|
132
132
|
};
|
|
133
|
+
|
|
134
|
+
// ============================ RowKey ============================
|
|
135
|
+
const getRowKey = _react.default.useMemo(() => {
|
|
136
|
+
if (typeof rowKey === 'function') {
|
|
137
|
+
return rowKey;
|
|
138
|
+
}
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
return record => record?.[rowKey];
|
|
141
|
+
}, [rowKey]);
|
|
133
142
|
const [transformSelectionColumns] = (0, _useColumns.default)({
|
|
134
143
|
locale,
|
|
135
144
|
t,
|
|
145
|
+
rowKey,
|
|
146
|
+
dataSource: mergerdData,
|
|
136
147
|
buddhistLocale,
|
|
137
148
|
dataSourceFilter: propDataSourceFilter,
|
|
138
149
|
format,
|
|
@@ -146,15 +157,6 @@ const InternalTable = props => {
|
|
|
146
157
|
return transformSelectionColumns(columns);
|
|
147
158
|
}, [columns, transformSelectionColumns]);
|
|
148
159
|
|
|
149
|
-
// ============================ RowKey ============================
|
|
150
|
-
const getRowKey = _react.default.useMemo(() => {
|
|
151
|
-
if (typeof rowKey === 'function') {
|
|
152
|
-
return rowKey;
|
|
153
|
-
}
|
|
154
|
-
// @ts-ignore
|
|
155
|
-
return record => record?.[rowKey];
|
|
156
|
-
}, [rowKey]);
|
|
157
|
-
|
|
158
160
|
// const triggerChangeColumns = (newColumns: ColumnsTable<RecordType>) => {
|
|
159
161
|
const triggerChangeColumns = (newColumns, type) => {
|
|
160
162
|
setColumns(newColumns);
|
|
@@ -334,10 +336,12 @@ const InternalTable = props => {
|
|
|
334
336
|
const handlePasteCallback = callbackData => {
|
|
335
337
|
const newDataUpdate = (0, _hooks.updateData)(dataSource, callbackData, rowKey);
|
|
336
338
|
triggerChangeData(newDataUpdate);
|
|
337
|
-
|
|
339
|
+
|
|
340
|
+
// onCellPaste?.dataChange?.(newDataUpdate)
|
|
338
341
|
};
|
|
339
342
|
if (onCellPaste && onCellPaste.onPasted) {
|
|
340
343
|
if (onCellPaste.onPasted.length > 1) {
|
|
344
|
+
// có callback
|
|
341
345
|
onCellPaste.onPasted({
|
|
342
346
|
pasteData: pastedRows,
|
|
343
347
|
type: 'onPaste',
|
|
@@ -345,6 +349,7 @@ const InternalTable = props => {
|
|
|
345
349
|
pastedColumns: pastedColumnsArray
|
|
346
350
|
}, handlePasteCallback);
|
|
347
351
|
} else {
|
|
352
|
+
// không có callback
|
|
348
353
|
onCellPaste.onPasted({
|
|
349
354
|
pasteData: pastedRows,
|
|
350
355
|
type: 'onPaste',
|
|
@@ -352,8 +357,11 @@ const InternalTable = props => {
|
|
|
352
357
|
pastedColumns: pastedColumnsArray
|
|
353
358
|
}, handlePasteCallback);
|
|
354
359
|
triggerChangeData(newData);
|
|
355
|
-
|
|
360
|
+
|
|
361
|
+
// onCellPaste.dataChange?.(newData)
|
|
356
362
|
}
|
|
363
|
+
} else {
|
|
364
|
+
triggerChangeData(newData);
|
|
357
365
|
}
|
|
358
366
|
};
|
|
359
367
|
const TableComponent = groupAble ? _Group.default : editAble ? _GridEdit.default : _Grid.default;
|
|
@@ -309,6 +309,7 @@ const TableGrid = props => {
|
|
|
309
309
|
}), /*#__PURE__*/_react.default.createElement(_rcMasterUi.Table, (0, _extends2.default)({
|
|
310
310
|
ref: tableRef
|
|
311
311
|
}, rest, {
|
|
312
|
+
// id={newGuid()}
|
|
312
313
|
locale: {
|
|
313
314
|
...locale,
|
|
314
315
|
emptyText: showEmptyText !== false ? /*#__PURE__*/_react.default.createElement(_rcMasterUi.Empty, {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AnyObject, IGroupSetting } from "../type";
|
|
2
2
|
export declare const SELECTION_COLUMN: {};
|
|
3
|
-
interface UseColumnsConfig {
|
|
3
|
+
interface UseColumnsConfig<RecordType> {
|
|
4
4
|
t?: any;
|
|
5
|
+
dataSource: RecordType[];
|
|
5
6
|
buddhistLocale?: any;
|
|
6
7
|
dataSourceFilter?: any;
|
|
7
8
|
locale?: any;
|
|
@@ -11,6 +12,7 @@ interface UseColumnsConfig {
|
|
|
11
12
|
groupAble?: boolean;
|
|
12
13
|
groupSetting?: IGroupSetting;
|
|
13
14
|
groupColumns?: string[];
|
|
15
|
+
rowKey?: any;
|
|
14
16
|
}
|
|
15
|
-
declare const useColumns: <RecordType extends AnyObject = AnyObject>(config: UseColumnsConfig) => readonly [any];
|
|
17
|
+
declare const useColumns: <RecordType extends AnyObject = AnyObject>(config: UseColumnsConfig<RecordType>) => readonly [any];
|
|
16
18
|
export default useColumns;
|
|
@@ -50,7 +50,9 @@ const useColumns = config => {
|
|
|
50
50
|
handleResize,
|
|
51
51
|
groupAble,
|
|
52
52
|
groupColumns,
|
|
53
|
-
groupSetting
|
|
53
|
+
groupSetting,
|
|
54
|
+
dataSource,
|
|
55
|
+
rowKey
|
|
54
56
|
} = config;
|
|
55
57
|
|
|
56
58
|
// ====================== Selections ======================
|
|
@@ -149,8 +151,8 @@ const useColumns = config => {
|
|
|
149
151
|
const transformColumns = (0, _react.useCallback)(columns => {
|
|
150
152
|
// >>>>>>>>>>> Support selection
|
|
151
153
|
const cloneColumns = [...columns];
|
|
152
|
-
const firstNonGroupColumn = (0, _columns.flatColumns2)(cloneColumns).find(col => col.field && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
153
|
-
const nonGroupColumns = (0, _columns.flatColumns2)(cloneColumns).filter(col => col.field && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
154
|
+
const firstNonGroupColumn = (0, _columns.flatColumns2)(cloneColumns).find(col => col.field && col.field !== '#' && col.field !== 'index' && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
155
|
+
const nonGroupColumns = (0, _columns.flatColumns2)(cloneColumns).filter(col => col.field && col.field !== '#' && col.field !== 'index' && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
154
156
|
|
|
155
157
|
// ===================== Render =====================
|
|
156
158
|
|
|
@@ -192,7 +194,10 @@ const useColumns = config => {
|
|
|
192
194
|
onCell: () => ({
|
|
193
195
|
className: 'cell-number'
|
|
194
196
|
}),
|
|
195
|
-
render: (
|
|
197
|
+
render: (val, record) => {
|
|
198
|
+
// return rowIndex + 1
|
|
199
|
+
return (0, _utils.findItemPath)(dataSource, record, rowKey);
|
|
200
|
+
}
|
|
196
201
|
};
|
|
197
202
|
}
|
|
198
203
|
if (col.key === 'command') {
|
|
@@ -71,3 +71,4 @@ export declare const checkChild: (inputArray: any[]) => boolean;
|
|
|
71
71
|
export declare const isEditable: <RecordType>(column: ColumnTable, rowData: RecordType) => boolean | ((rowData: any) => boolean);
|
|
72
72
|
export declare const isArraysEqual: (arr1: any[], arr2: any[]) => boolean;
|
|
73
73
|
export declare const editAbleColumns: <T>(columns: ColumnsTable<T>) => ColumnTable<T>[];
|
|
74
|
+
export declare const findItemPath: (tree: any[], targetItem: any, rowKey: any) => any;
|
|
@@ -8,7 +8,7 @@ exports.addRowIdArray = void 0;
|
|
|
8
8
|
exports.addRows8 = addRows8;
|
|
9
9
|
exports.editAbleColumns = exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertFlatColumn = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertColumns = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = exports.checkChild = void 0;
|
|
10
10
|
exports.findAllChildrenKeys = findAllChildrenKeys;
|
|
11
|
-
exports.getFirstSelectCell = exports.getEditType = exports.getDefaultValue = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = exports.findItemByKey = void 0;
|
|
11
|
+
exports.getFirstSelectCell = exports.getEditType = exports.getDefaultValue = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = exports.findItemPath = exports.findItemByKey = void 0;
|
|
12
12
|
exports.getHiddenParentKeys = getHiddenParentKeys;
|
|
13
13
|
exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.removeColumns = exports.parseBooleanToValue = exports.newGuid = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isEditable = exports.isDisable = exports.isColor = exports.isArraysEqual = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = exports.getRowsPasteIndex = exports.getRowNumber = exports.getLastSelectCell = void 0;
|
|
14
14
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
@@ -850,4 +850,26 @@ exports.isArraysEqual = isArraysEqual;
|
|
|
850
850
|
const editAbleColumns = columns => {
|
|
851
851
|
return columns.filter(col => col.field !== '#' && col.field !== 'index' && col.field !== 'command' && col.visible !== false);
|
|
852
852
|
};
|
|
853
|
-
exports.editAbleColumns = editAbleColumns;
|
|
853
|
+
exports.editAbleColumns = editAbleColumns;
|
|
854
|
+
const findItemPath = (tree, targetItem, rowKey) => {
|
|
855
|
+
let result = null;
|
|
856
|
+
function dfs(nodes, path = []) {
|
|
857
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
858
|
+
const currentPath = [...path, i + 1];
|
|
859
|
+
const node = nodes[i];
|
|
860
|
+
if (node?.[rowKey] === targetItem?.[rowKey]) {
|
|
861
|
+
result = currentPath.join('.');
|
|
862
|
+
return true;
|
|
863
|
+
}
|
|
864
|
+
if (node?.children) {
|
|
865
|
+
if (dfs(node.children, currentPath)) {
|
|
866
|
+
return true;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
dfs(tree);
|
|
873
|
+
return result;
|
|
874
|
+
};
|
|
875
|
+
exports.findItemPath = findItemPath;
|
|
@@ -133,6 +133,21 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
133
133
|
|
|
134
134
|
.#{$prefix}-table-tbody {
|
|
135
135
|
|
|
136
|
+
|
|
137
|
+
.#{$prefix}-table-cell {
|
|
138
|
+
line-height: 22px;
|
|
139
|
+
|
|
140
|
+
.ui-rc-table-cell-content {
|
|
141
|
+
line-height: 22px;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
&.#{$prefix}-table-cell-fix-left-last {
|
|
145
|
+
.#{$prefix}-table-cell-content {
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
136
151
|
.#{$prefix}-table-row {
|
|
137
152
|
|
|
138
153
|
&.#{$prefix}-table-row-selected {
|
|
@@ -212,6 +227,10 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
212
227
|
|
|
213
228
|
.#{$prefix}-table-cell {
|
|
214
229
|
|
|
230
|
+
.ui-rc-table-cell-content {
|
|
231
|
+
line-height: 22px;
|
|
232
|
+
}
|
|
233
|
+
|
|
215
234
|
&.#{$prefix}-table-cell-fix-left-last {
|
|
216
235
|
.#{$prefix}-table-cell-content {
|
|
217
236
|
//overflow: visible;
|
|
@@ -604,6 +623,10 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
604
623
|
background-color: $cell-selected-bg;
|
|
605
624
|
}
|
|
606
625
|
|
|
626
|
+
.ui-rc_cell-content.disable {
|
|
627
|
+
background-color: #f0f0f0;
|
|
628
|
+
}
|
|
629
|
+
|
|
607
630
|
.ui-rc_cell-content--index {
|
|
608
631
|
&.focus {
|
|
609
632
|
background-color: $cell-index-focus-bg;
|
|
@@ -688,6 +711,7 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
|
|
|
688
711
|
transition: 0.3s;
|
|
689
712
|
white-space: nowrap;
|
|
690
713
|
overflow: hidden;
|
|
714
|
+
line-height: 22px;
|
|
691
715
|
}
|
|
692
716
|
}
|
|
693
717
|
}
|