es-grid-template 1.8.63 → 1.8.64
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/type.d.ts +1 -0
- package/es/table-component/InternalTable.js +1 -4
- package/es/table-component/TableContainer.js +5 -5
- package/es/table-component/TableContainerEdit.js +158 -29
- package/es/table-component/body/TableBodyCellEdit.js +69 -31
- package/es/table-component/hook/utils.d.ts +2 -0
- package/es/table-component/hook/utils.js +39 -2
- package/es/table-component/table/Grid.js +10 -7
- package/es/table-component/table/TableWrapper.js +0 -2
- package/es/table-component/type.d.ts +1 -0
- package/es/table-component/useContext.d.ts +3 -1
- package/lib/grid-component/type.d.ts +1 -0
- package/lib/table-component/InternalTable.js +1 -4
- package/lib/table-component/TableContainer.js +5 -5
- package/lib/table-component/TableContainerEdit.js +158 -29
- package/lib/table-component/body/TableBodyCellEdit.js +69 -31
- package/lib/table-component/hook/utils.d.ts +2 -0
- package/lib/table-component/hook/utils.js +45 -4
- package/lib/table-component/table/Grid.js +10 -7
- package/lib/table-component/table/TableWrapper.js +0 -2
- package/lib/table-component/type.d.ts +1 -0
- package/lib/table-component/useContext.d.ts +3 -1
- package/package.json +1 -1
|
@@ -285,6 +285,7 @@ export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<Re
|
|
|
285
285
|
onRowStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | ((data: RecordType, row: Row<RecordType>) => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
|
|
286
286
|
onRowHeaderStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | (() => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
|
|
287
287
|
onRowFooterStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | (() => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
|
|
288
|
+
fullScreenTitle?: ReactNode | (() => ReactNode);
|
|
288
289
|
}
|
|
289
290
|
export type PaginationConfig = TablePaginationConfig & {
|
|
290
291
|
currentPage?: number;
|
|
@@ -200,10 +200,7 @@ const InternalTable = props => {
|
|
|
200
200
|
triggerSorter: setSorterStates,
|
|
201
201
|
setMergedFilterKeys: setMergedFilterKeys,
|
|
202
202
|
mergedFilterKeys: mergedFilterKeys,
|
|
203
|
-
expanded: expanded
|
|
204
|
-
// onContextMenu={onContextMenu}
|
|
205
|
-
// contextMenuItems={contextMenuItems}
|
|
206
|
-
,
|
|
203
|
+
expanded: expanded,
|
|
207
204
|
editAble: isFullScreen ? false : editAble,
|
|
208
205
|
triggerChangeColumns: triggerChangeColumns,
|
|
209
206
|
setExpanded: setExpanded,
|
|
@@ -185,10 +185,6 @@ const TableContainer = props => {
|
|
|
185
185
|
ref: topToolbarRef,
|
|
186
186
|
className: classNames(`${prefix}-grid-top-toolbar`, {})
|
|
187
187
|
}, /*#__PURE__*/React.createElement("div", {
|
|
188
|
-
style: {
|
|
189
|
-
textAlign: 'center'
|
|
190
|
-
}
|
|
191
|
-
}, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/React.createElement("div", {
|
|
192
188
|
style: {
|
|
193
189
|
display: 'flex',
|
|
194
190
|
justifyContent: 'space-between',
|
|
@@ -239,7 +235,11 @@ const TableContainer = props => {
|
|
|
239
235
|
t: t,
|
|
240
236
|
columnsGroup: groupColumns,
|
|
241
237
|
triggerChangeColumns: triggerChangeColumns
|
|
242
|
-
})))
|
|
238
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
239
|
+
style: {
|
|
240
|
+
textAlign: 'center'
|
|
241
|
+
}
|
|
242
|
+
}, typeof title === 'function' ? title?.(originData) : title)), /*#__PURE__*/React.createElement(TableContext.Provider, {
|
|
243
243
|
value: {
|
|
244
244
|
t,
|
|
245
245
|
locale,
|
|
@@ -358,6 +358,9 @@ const TableContainerEdit = props => {
|
|
|
358
358
|
const [isPasting, setIsPasting] = React.useState(false);
|
|
359
359
|
// const [isFullScreen] = React.useState(false);
|
|
360
360
|
const [tableHeight, settableHeight] = React.useState(0);
|
|
361
|
+
|
|
362
|
+
// const [isAddNewRow, setIsAddNewRow] = React.useState(false)
|
|
363
|
+
|
|
361
364
|
const rowsFocus = React.useMemo(() => {
|
|
362
365
|
return startCell && endCell ? getRowIdsBetween(table, startCell.rowId, endCell.rowId) : [];
|
|
363
366
|
}, [endCell, startCell, table]);
|
|
@@ -396,7 +399,7 @@ const TableContainerEdit = props => {
|
|
|
396
399
|
}, [startCell, endCell, table]);
|
|
397
400
|
const triggerChangeData = React.useCallback(newData => {
|
|
398
401
|
onDataChange?.(newData);
|
|
399
|
-
}, [onDataChange]);
|
|
402
|
+
}, [onDataChange, dataSource]);
|
|
400
403
|
const triggerPaste = React.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
|
|
401
404
|
const handlePasteCallback = callbackData => {
|
|
402
405
|
const rsFilterData = updateOrInsert(flattenArray([...originData]), callbackData);
|
|
@@ -955,6 +958,30 @@ const TableContainerEdit = props => {
|
|
|
955
958
|
mode: 'onChange',
|
|
956
959
|
resolver: validate ? yupResolver(validate) : undefined
|
|
957
960
|
});
|
|
961
|
+
const handleAddMulti = React.useCallback((item, n, newId) => {
|
|
962
|
+
if (item.onClick) {
|
|
963
|
+
item.onClick({
|
|
964
|
+
toolbar: item
|
|
965
|
+
});
|
|
966
|
+
} else {
|
|
967
|
+
const defaultRowValue = getDefaultValue(defaultValue);
|
|
968
|
+
const newRows = Array.from({
|
|
969
|
+
length: n
|
|
970
|
+
}).map(() => defaultRowValue ? {
|
|
971
|
+
...defaultRowValue,
|
|
972
|
+
id: undefined,
|
|
973
|
+
rowId: n === 1 && newId ? newId : newGuid()
|
|
974
|
+
} : {
|
|
975
|
+
id: undefined,
|
|
976
|
+
rowId: n === 1 && newId ? newId : newGuid()
|
|
977
|
+
});
|
|
978
|
+
const kkk = getAllRowKey(newRows) ?? [];
|
|
979
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
980
|
+
setMergedFilterKeys?.(rs);
|
|
981
|
+
const newData = dataSource.concat(newRows);
|
|
982
|
+
triggerChangeData?.(newData);
|
|
983
|
+
}
|
|
984
|
+
}, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
|
|
958
985
|
const onSubmit = formData => {
|
|
959
986
|
try {
|
|
960
987
|
// const record = (await form.validateFields()) as RecordType;
|
|
@@ -975,6 +1002,26 @@ const TableContainerEdit = props => {
|
|
|
975
1002
|
console.log('Validate Failed:', errInfo);
|
|
976
1003
|
}
|
|
977
1004
|
};
|
|
1005
|
+
const onSubmit2 = (formData, newOriginData) => {
|
|
1006
|
+
try {
|
|
1007
|
+
// const record = (await form.validateFields()) as RecordType;
|
|
1008
|
+
const row = {
|
|
1009
|
+
...formData
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
// const newData = [...dataSource]
|
|
1013
|
+
const newData = [...newOriginData];
|
|
1014
|
+
|
|
1015
|
+
// @ts-ignore
|
|
1016
|
+
const index = flattenData(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
|
|
1017
|
+
const rs = updateArrayByKey(newData, row, rowKey);
|
|
1018
|
+
if (index > -1) {
|
|
1019
|
+
triggerChangeData?.(rs);
|
|
1020
|
+
}
|
|
1021
|
+
} catch (errInfo) {
|
|
1022
|
+
console.log('Validate Failed:', errInfo);
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
978
1025
|
const handleCellChange = args => {
|
|
979
1026
|
const {
|
|
980
1027
|
record,
|
|
@@ -1032,30 +1079,111 @@ const TableContainerEdit = props => {
|
|
|
1032
1079
|
onSubmit(record);
|
|
1033
1080
|
}
|
|
1034
1081
|
};
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1082
|
+
const handleCellChangeAndAddRow = args => {
|
|
1083
|
+
const {
|
|
1084
|
+
record,
|
|
1085
|
+
type: changeType,
|
|
1086
|
+
newState,
|
|
1087
|
+
option,
|
|
1088
|
+
field,
|
|
1089
|
+
indexCol,
|
|
1090
|
+
indexRow,
|
|
1091
|
+
key
|
|
1092
|
+
} = args;
|
|
1093
|
+
|
|
1094
|
+
// add new row
|
|
1095
|
+
|
|
1096
|
+
const defaultRowValue = getDefaultValue(defaultValue);
|
|
1097
|
+
const newRowId = newGuid();
|
|
1098
|
+
const newRows = Array.from({
|
|
1099
|
+
length: 1
|
|
1100
|
+
}).map(() => defaultRowValue ? {
|
|
1101
|
+
...defaultRowValue,
|
|
1102
|
+
id: undefined,
|
|
1103
|
+
rowId: newRowId
|
|
1104
|
+
} : {
|
|
1105
|
+
id: undefined,
|
|
1106
|
+
rowId: newRowId
|
|
1107
|
+
});
|
|
1108
|
+
const kkk = getAllRowKey(newRows) ?? [];
|
|
1109
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
1110
|
+
setMergedFilterKeys?.(rs);
|
|
1111
|
+
const newData = originData.concat(newRows);
|
|
1112
|
+
setFocusedCell?.({
|
|
1113
|
+
rowId: newRowId,
|
|
1114
|
+
colId: field
|
|
1115
|
+
});
|
|
1116
|
+
setStartCell?.({
|
|
1117
|
+
rowId: newRowId,
|
|
1118
|
+
colId: field
|
|
1119
|
+
});
|
|
1120
|
+
setEndCell?.({
|
|
1121
|
+
rowId: newRowId,
|
|
1122
|
+
colId: field
|
|
1123
|
+
});
|
|
1124
|
+
setTimeout(() => {
|
|
1125
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
1126
|
+
rowId: newRowId,
|
|
1127
|
+
colId: field
|
|
1128
|
+
}, {
|
|
1129
|
+
rowId: newRowId,
|
|
1130
|
+
colId: field
|
|
1131
|
+
}));
|
|
1132
|
+
});
|
|
1133
|
+
setTimeout(() => {
|
|
1134
|
+
const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
|
|
1135
|
+
const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
|
|
1136
|
+
if (cellFocus) {
|
|
1137
|
+
cellFocus.scrollIntoView({
|
|
1138
|
+
behavior: "smooth",
|
|
1139
|
+
block: "start"
|
|
1140
|
+
});
|
|
1141
|
+
cellFocus.focus();
|
|
1142
|
+
}
|
|
1143
|
+
}, 100);
|
|
1144
|
+
if (changeType === 'blur') {
|
|
1145
|
+
const handleChangeCallback = callbackData => {
|
|
1146
|
+
const callbackRecord = callbackData;
|
|
1147
|
+
onSubmit2(callbackRecord, [...newData]);
|
|
1148
|
+
};
|
|
1149
|
+
if (onCellChange) {
|
|
1150
|
+
if (onCellChange.length > 1) {
|
|
1151
|
+
onCellChange({
|
|
1152
|
+
field,
|
|
1153
|
+
indexCol,
|
|
1154
|
+
type: 'onChange',
|
|
1155
|
+
value: newState,
|
|
1156
|
+
option,
|
|
1157
|
+
indexRow,
|
|
1158
|
+
rowData: record,
|
|
1159
|
+
rowId: key,
|
|
1160
|
+
rowsData: [...newData],
|
|
1161
|
+
sumValue: []
|
|
1162
|
+
}, handleChangeCallback);
|
|
1163
|
+
} else {
|
|
1164
|
+
onCellChange({
|
|
1165
|
+
field,
|
|
1166
|
+
indexCol,
|
|
1167
|
+
type: 'onChange',
|
|
1168
|
+
option,
|
|
1169
|
+
value: newState,
|
|
1170
|
+
indexRow,
|
|
1171
|
+
rowData: record,
|
|
1172
|
+
rowId: key,
|
|
1173
|
+
rowsData: [...newData],
|
|
1174
|
+
sumValue: []
|
|
1175
|
+
}, handleChangeCallback);
|
|
1176
|
+
onSubmit2(record, [...newData]);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1057
1179
|
}
|
|
1058
|
-
|
|
1180
|
+
|
|
1181
|
+
// if (prevState && newState && prevState !== newState && changeType === 'enter') {
|
|
1182
|
+
|
|
1183
|
+
// onSubmit(record)
|
|
1184
|
+
|
|
1185
|
+
// }
|
|
1186
|
+
};
|
|
1059
1187
|
const handleDuplicate = React.useCallback(() => {
|
|
1060
1188
|
// không tính tree
|
|
1061
1189
|
|
|
@@ -1782,10 +1910,6 @@ const TableContainerEdit = props => {
|
|
|
1782
1910
|
ref: topToolbarRef,
|
|
1783
1911
|
className: classNames(`${prefix}-grid-top-toolbar`, {})
|
|
1784
1912
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1785
|
-
style: {
|
|
1786
|
-
textAlign: 'center'
|
|
1787
|
-
}
|
|
1788
|
-
}, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/React.createElement("div", {
|
|
1789
1913
|
style: {
|
|
1790
1914
|
display: 'flex',
|
|
1791
1915
|
justifyContent: 'space-between',
|
|
@@ -1836,7 +1960,11 @@ const TableContainerEdit = props => {
|
|
|
1836
1960
|
columnsGroup: groupColumns,
|
|
1837
1961
|
triggerChangeColumns: triggerChangeColumns,
|
|
1838
1962
|
columnHidden: columnHidden
|
|
1839
|
-
})))
|
|
1963
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
1964
|
+
style: {
|
|
1965
|
+
textAlign: 'center'
|
|
1966
|
+
}
|
|
1967
|
+
}, typeof title === 'function' ? title?.(originData) : title)), /*#__PURE__*/React.createElement("form", {
|
|
1840
1968
|
onSubmit: handleSubmit(onSubmit)
|
|
1841
1969
|
}, /*#__PURE__*/React.createElement(TableContext.Provider, {
|
|
1842
1970
|
value: {
|
|
@@ -1888,6 +2016,7 @@ const TableContainerEdit = props => {
|
|
|
1888
2016
|
setValue,
|
|
1889
2017
|
reset,
|
|
1890
2018
|
handleCellChange,
|
|
2019
|
+
handleCellChangeAndAddRow,
|
|
1891
2020
|
triggerPaste,
|
|
1892
2021
|
handleDeleteContent,
|
|
1893
2022
|
handleAddMulti,
|
|
@@ -227,7 +227,7 @@ const TableBodyCellEdit = props => {
|
|
|
227
227
|
setValue,
|
|
228
228
|
getValues,
|
|
229
229
|
handleCellChange,
|
|
230
|
-
|
|
230
|
+
handleCellChangeAndAddRow,
|
|
231
231
|
dataErrors,
|
|
232
232
|
expanded,
|
|
233
233
|
setExpanded,
|
|
@@ -237,17 +237,13 @@ const TableBodyCellEdit = props => {
|
|
|
237
237
|
isSelectionChange,
|
|
238
238
|
setIsSelectionChange,
|
|
239
239
|
selectionSettings,
|
|
240
|
-
pagination
|
|
240
|
+
pagination,
|
|
241
|
+
handleAddMulti
|
|
241
242
|
} = React.useContext(TableContext);
|
|
242
243
|
const expandIconColumnIndex = expandable?.expandIconColumnIndex;
|
|
243
244
|
const record = cell.row.original;
|
|
244
245
|
const columnMeta = cell.column.columnDef.meta ?? {};
|
|
245
246
|
const [isOpenTooltip, setIsOpenTooltip] = React.useState(false);
|
|
246
|
-
|
|
247
|
-
// const cellContent = columnMeta.type === 'checkbox' ? '' : flexRender(cell.column.columnDef.cell, cell.getContext());
|
|
248
|
-
// const html = ReactDOMServer.renderToStaticMarkup(<>{cellContent}</>);
|
|
249
|
-
// const hasValue = html.trim().length > 0;
|
|
250
|
-
|
|
251
247
|
const rowError = dataErrors ? dataErrors.find(it => it.id === cell.row.id) : undefined;
|
|
252
248
|
const message = rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : undefined;
|
|
253
249
|
const tooltipContent = isOpenTooltip === false ? '' : columnMeta?.tooltipDescription ? typeof columnMeta.tooltipDescription === 'function' ? columnMeta.tooltipDescription({
|
|
@@ -783,6 +779,8 @@ const TableBodyCellEdit = props => {
|
|
|
783
779
|
return;
|
|
784
780
|
}
|
|
785
781
|
if (e.key === 'Enter') {
|
|
782
|
+
e.preventDefault();
|
|
783
|
+
e.stopPropagation();
|
|
786
784
|
handleEdit(e, true);
|
|
787
785
|
return;
|
|
788
786
|
}
|
|
@@ -1038,6 +1036,64 @@ const TableBodyCellEdit = props => {
|
|
|
1038
1036
|
indexRow: currentRowIndex,
|
|
1039
1037
|
type: 'blur'
|
|
1040
1038
|
});
|
|
1039
|
+
} else {}
|
|
1040
|
+
};
|
|
1041
|
+
const handleChangeAndCreateRow = () => {
|
|
1042
|
+
const currentRowIndex = allRows.findIndex(r => r.id === editingKey);
|
|
1043
|
+
const formState = getValues();
|
|
1044
|
+
const itemState = getValues(cell.column.id);
|
|
1045
|
+
const prevState = record[cell.column.id];
|
|
1046
|
+
const newState = itemState;
|
|
1047
|
+
if (newState !== prevState) {
|
|
1048
|
+
// vừa cell change + add new row
|
|
1049
|
+
handleCellChangeAndAddRow?.({
|
|
1050
|
+
key: cell.row.id,
|
|
1051
|
+
field: cell.column.id,
|
|
1052
|
+
record: formState,
|
|
1053
|
+
prevState,
|
|
1054
|
+
newState,
|
|
1055
|
+
option: newState,
|
|
1056
|
+
indexCol: cell.column.getIndex(),
|
|
1057
|
+
indexRow: currentRowIndex,
|
|
1058
|
+
type: 'blur'
|
|
1059
|
+
});
|
|
1060
|
+
} else {
|
|
1061
|
+
// chỉ add new row
|
|
1062
|
+
|
|
1063
|
+
const newRowId = newGuid();
|
|
1064
|
+
handleAddMulti?.({}, 1, newRowId);
|
|
1065
|
+
setFocusedCell?.({
|
|
1066
|
+
rowId: newRowId,
|
|
1067
|
+
colId: cell.column.id
|
|
1068
|
+
});
|
|
1069
|
+
setStartCell?.({
|
|
1070
|
+
rowId: newRowId,
|
|
1071
|
+
colId: cell.column.id
|
|
1072
|
+
});
|
|
1073
|
+
setEndCell?.({
|
|
1074
|
+
rowId: newRowId,
|
|
1075
|
+
colId: cell.column.id
|
|
1076
|
+
});
|
|
1077
|
+
setTimeout(() => {
|
|
1078
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
1079
|
+
rowId: newRowId,
|
|
1080
|
+
colId: cell.column.id
|
|
1081
|
+
}, {
|
|
1082
|
+
rowId: newRowId,
|
|
1083
|
+
colId: cell.column.id
|
|
1084
|
+
}));
|
|
1085
|
+
});
|
|
1086
|
+
setTimeout(() => {
|
|
1087
|
+
const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
|
|
1088
|
+
const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
|
|
1089
|
+
if (cellFocus) {
|
|
1090
|
+
cellFocus.scrollIntoView({
|
|
1091
|
+
behavior: "smooth",
|
|
1092
|
+
block: "start"
|
|
1093
|
+
});
|
|
1094
|
+
cellFocus.focus();
|
|
1095
|
+
}
|
|
1096
|
+
}, 100);
|
|
1041
1097
|
}
|
|
1042
1098
|
};
|
|
1043
1099
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -1110,9 +1166,10 @@ const TableBodyCellEdit = props => {
|
|
|
1110
1166
|
if (!isEditing) {
|
|
1111
1167
|
handleKeyDown(e, cell.row.id, cell.column.id);
|
|
1112
1168
|
} else {
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1169
|
+
if (e.shiftKey && e.key === 'Enter') {
|
|
1170
|
+
e.preventDefault();
|
|
1171
|
+
e.stopPropagation();
|
|
1172
|
+
} else {
|
|
1116
1173
|
if (e.key === 'Enter') {
|
|
1117
1174
|
e.preventDefault();
|
|
1118
1175
|
e.stopPropagation();
|
|
@@ -1141,29 +1198,10 @@ const TableBodyCellEdit = props => {
|
|
|
1141
1198
|
rowVirtualizer.scrollToIndex(nextRow.index, {
|
|
1142
1199
|
align: 'center'
|
|
1143
1200
|
});
|
|
1201
|
+
handleChange();
|
|
1144
1202
|
} else {
|
|
1145
|
-
|
|
1146
|
-
// const newRowId = newGuid()
|
|
1147
|
-
// handleAddMulti?.({}, 1, newRowId)
|
|
1148
|
-
|
|
1149
|
-
// setFocusedCell?.({ rowId: newRowId, colId: cell.column.id });
|
|
1150
|
-
|
|
1151
|
-
// setStartCell?.({ rowId: newRowId, colId: cell.column.id });
|
|
1152
|
-
// setEndCell?.({ rowId: newRowId, colId: cell.column.id });
|
|
1153
|
-
|
|
1154
|
-
// setTimeout(() => {
|
|
1155
|
-
// setRangeState?.(getSelectedCellMatrix(table, { rowId: newRowId, colId: cell.column.id }, { rowId: newRowId, colId: cell.column.id }))
|
|
1156
|
-
// // rowVirtualizer.scrollToIndex(currentRowIndex + 1, { align: 'end', })
|
|
1157
|
-
|
|
1158
|
-
// })
|
|
1159
|
-
|
|
1160
|
-
// setTimeout(() => {
|
|
1161
|
-
|
|
1162
|
-
// rowVirtualizer.scrollToIndex(currentRowIndex + 1, { align: 'center', })
|
|
1163
|
-
|
|
1164
|
-
// }, 100)
|
|
1203
|
+
handleChangeAndCreateRow();
|
|
1165
1204
|
}
|
|
1166
|
-
handleChange();
|
|
1167
1205
|
setEditingKey?.('');
|
|
1168
1206
|
reset?.();
|
|
1169
1207
|
}
|
|
@@ -154,3 +154,5 @@ export declare function countUnselectedChildren(row: Row<any>): number;
|
|
|
154
154
|
export declare function removeDuplicatesByKey(arr: any[], key?: string): any[];
|
|
155
155
|
export declare const getTableHeight: (height?: number, minHeight?: number) => number;
|
|
156
156
|
export declare const convertFlatColumn1: (array: ColumnsTable) => ColumnsTable[];
|
|
157
|
+
export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string[]) => any[];
|
|
158
|
+
export declare const removeColumns: <RecordType>(columns: ColumnTable<RecordType>[], groupColumns: string[]) => ColumnsTable<RecordType>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SELECTION_COLUMN } from "rc-master-ui/es/table/hooks/useSelection"
|
|
1
|
+
// import { SELECTION_COLUMN } from "rc-master-ui/es/table/hooks/useSelection"
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
import { presetPalettes } from "@ant-design/colors";
|
|
4
4
|
// import moment from "moment/moment"
|
|
@@ -263,7 +263,7 @@ export function groupArrayByColumns(arr, columns) {
|
|
|
263
263
|
export const flatColumns2 = columns => {
|
|
264
264
|
return columns.reduce((list, column) => {
|
|
265
265
|
const subColumns = column.children;
|
|
266
|
-
if (column ===
|
|
266
|
+
if (column.field === 'selection_column') {
|
|
267
267
|
return [...list, {
|
|
268
268
|
...column
|
|
269
269
|
}];
|
|
@@ -2180,4 +2180,41 @@ export const convertFlatColumn1 = array => {
|
|
|
2180
2180
|
}
|
|
2181
2181
|
});
|
|
2182
2182
|
return result;
|
|
2183
|
+
};
|
|
2184
|
+
export const updateColumnsByGroup = (columns, columnsGroup) => {
|
|
2185
|
+
return columns.map(column => {
|
|
2186
|
+
const newColumn = {
|
|
2187
|
+
...column
|
|
2188
|
+
};
|
|
2189
|
+
let hasVisibleChild = false;
|
|
2190
|
+
if (!column.field) {
|
|
2191
|
+
return column;
|
|
2192
|
+
}
|
|
2193
|
+
if (newColumn.children) {
|
|
2194
|
+
newColumn.children = updateColumnsByGroup(newColumn.children, columnsGroup);
|
|
2195
|
+
hasVisibleChild = newColumn.children.some(child => child.visible !== false);
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
// Map previous behaviour (hidden = true when field in columnsGroup)
|
|
2199
|
+
// to the new `visible` property: visible = !hidden
|
|
2200
|
+
newColumn.visible = !(newColumn.field && columnsGroup.includes(newColumn.field));
|
|
2201
|
+
|
|
2202
|
+
// For parent columns, visibility depends on whether any child is visible
|
|
2203
|
+
if (newColumn.children && newColumn.children.length > 0) {
|
|
2204
|
+
newColumn.visible = !!hasVisibleChild;
|
|
2205
|
+
}
|
|
2206
|
+
return newColumn;
|
|
2207
|
+
});
|
|
2208
|
+
};
|
|
2209
|
+
export const removeColumns = (columns, groupColumns) => {
|
|
2210
|
+
const ttt = [...columns];
|
|
2211
|
+
return ttt.filter(column => !groupColumns.includes(column.field)).map(column => {
|
|
2212
|
+
const newCol = {
|
|
2213
|
+
...column
|
|
2214
|
+
};
|
|
2215
|
+
if (newCol?.children && newCol?.children.length > 0) {
|
|
2216
|
+
newCol.children = removeColumns(newCol.children, groupColumns);
|
|
2217
|
+
}
|
|
2218
|
+
return newCol;
|
|
2219
|
+
});
|
|
2183
2220
|
};
|
|
@@ -59,6 +59,7 @@ const Grid = props => {
|
|
|
59
59
|
mergedSelectedKeys,
|
|
60
60
|
allowResizing,
|
|
61
61
|
windowSize,
|
|
62
|
+
fullScreenTitle,
|
|
62
63
|
...rest
|
|
63
64
|
} = props;
|
|
64
65
|
const [columnResizeMode] = React.useState('onChange');
|
|
@@ -316,9 +317,7 @@ const Grid = props => {
|
|
|
316
317
|
style: {
|
|
317
318
|
maxWidth: '100%',
|
|
318
319
|
height: '100%'
|
|
319
|
-
}
|
|
320
|
-
// onClose={() => setIsFullScreen(false)}
|
|
321
|
-
,
|
|
320
|
+
},
|
|
322
321
|
onCancel: () => setIsFullScreen(false)
|
|
323
322
|
|
|
324
323
|
// destroyOnClose
|
|
@@ -333,12 +332,16 @@ const Grid = props => {
|
|
|
333
332
|
zIndex: 1050
|
|
334
333
|
}
|
|
335
334
|
},
|
|
335
|
+
title: /*#__PURE__*/React.createElement(React.Fragment, null, " ", typeof fullScreenTitle === 'function' ? fullScreenTitle?.() : fullScreenTitle, " "),
|
|
336
336
|
destroyOnClose: true
|
|
337
337
|
}, /*#__PURE__*/React.createElement("div", {
|
|
338
|
-
style: {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
style: {}
|
|
339
|
+
}, /*#__PURE__*/React.createElement(GridStyle, {
|
|
340
|
+
$prefix: prefix,
|
|
341
|
+
$theme: {
|
|
342
|
+
theme: theme?.theme,
|
|
343
|
+
...theme
|
|
344
|
+
},
|
|
342
345
|
className: classNames(`${prefix}-grid`, {
|
|
343
346
|
[`${prefix}-grid-light`]: !theme || theme.theme === 'light',
|
|
344
347
|
[`${prefix}-grid-dark`]: theme?.theme === 'dark'
|
|
@@ -180,11 +180,9 @@ const TableWrapper = props => {
|
|
|
180
180
|
//our scrollable table container
|
|
181
181
|
position: 'relative',
|
|
182
182
|
//needed for sticky header
|
|
183
|
-
// height: height, //should be a fixed height
|
|
184
183
|
maxHeight: height,
|
|
185
184
|
//should be a fixed height
|
|
186
185
|
minHeight: minHeight ? height : undefined //should be a fixed height
|
|
187
|
-
// minWidth: table.getTotalSize()
|
|
188
186
|
}
|
|
189
187
|
// onScroll={infiniteScroll ? handleScroll : undefined}
|
|
190
188
|
,
|
|
@@ -198,6 +198,7 @@ export type TableProps<RecordType = AnyObject> = {
|
|
|
198
198
|
color?: string;
|
|
199
199
|
};
|
|
200
200
|
title?: ReactNode | ((data: RecordType) => ReactNode);
|
|
201
|
+
fullScreenTitle?: ReactNode | (() => ReactNode);
|
|
201
202
|
editAble?: boolean;
|
|
202
203
|
infiniteScroll?: boolean;
|
|
203
204
|
next?: () => void;
|
|
@@ -48,6 +48,7 @@ export interface IContext<T> {
|
|
|
48
48
|
reset?: any;
|
|
49
49
|
setValue?: any;
|
|
50
50
|
handleCellChange?: (args: ContextCellChange) => void;
|
|
51
|
+
handleCellChangeAndAddRow?: (args: ContextCellChange) => void;
|
|
51
52
|
editingKey?: string;
|
|
52
53
|
setEditingKey?: Dispatch<SetStateAction<string>>;
|
|
53
54
|
rangeState?: RangeState;
|
|
@@ -86,11 +87,12 @@ export declare const TableContext: import("react").Context<IContext<any>>;
|
|
|
86
87
|
export type ContextCellChange = {
|
|
87
88
|
key: string;
|
|
88
89
|
record: any;
|
|
89
|
-
field: string
|
|
90
|
+
field: string;
|
|
90
91
|
option: any;
|
|
91
92
|
indexRow: number;
|
|
92
93
|
indexCol: number;
|
|
93
94
|
newState?: any;
|
|
94
95
|
prevState?: any;
|
|
95
96
|
type: 'enter' | 'blur' | 'outClick';
|
|
97
|
+
addNewRow?: boolean;
|
|
96
98
|
};
|
|
@@ -285,6 +285,7 @@ export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<Re
|
|
|
285
285
|
onRowStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | ((data: RecordType, row: Row<RecordType>) => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
|
|
286
286
|
onRowHeaderStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | (() => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
|
|
287
287
|
onRowFooterStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | (() => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
|
|
288
|
+
fullScreenTitle?: ReactNode | (() => ReactNode);
|
|
288
289
|
}
|
|
289
290
|
export type PaginationConfig = TablePaginationConfig & {
|
|
290
291
|
currentPage?: number;
|
|
@@ -205,10 +205,7 @@ const InternalTable = props => {
|
|
|
205
205
|
triggerSorter: setSorterStates,
|
|
206
206
|
setMergedFilterKeys: setMergedFilterKeys,
|
|
207
207
|
mergedFilterKeys: mergedFilterKeys,
|
|
208
|
-
expanded: expanded
|
|
209
|
-
// onContextMenu={onContextMenu}
|
|
210
|
-
// contextMenuItems={contextMenuItems}
|
|
211
|
-
,
|
|
208
|
+
expanded: expanded,
|
|
212
209
|
editAble: isFullScreen ? false : editAble,
|
|
213
210
|
triggerChangeColumns: triggerChangeColumns,
|
|
214
211
|
setExpanded: setExpanded,
|
|
@@ -192,10 +192,6 @@ const TableContainer = props => {
|
|
|
192
192
|
ref: topToolbarRef,
|
|
193
193
|
className: (0, _classnames.default)(`${prefix}-grid-top-toolbar`, {})
|
|
194
194
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
195
|
-
style: {
|
|
196
|
-
textAlign: 'center'
|
|
197
|
-
}
|
|
198
|
-
}, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/_react.default.createElement("div", {
|
|
199
195
|
style: {
|
|
200
196
|
display: 'flex',
|
|
201
197
|
justifyContent: 'space-between',
|
|
@@ -246,7 +242,11 @@ const TableContainer = props => {
|
|
|
246
242
|
t: t,
|
|
247
243
|
columnsGroup: groupColumns,
|
|
248
244
|
triggerChangeColumns: triggerChangeColumns
|
|
249
|
-
})))
|
|
245
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
246
|
+
style: {
|
|
247
|
+
textAlign: 'center'
|
|
248
|
+
}
|
|
249
|
+
}, typeof title === 'function' ? title?.(originData) : title)), /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
|
|
250
250
|
value: {
|
|
251
251
|
t,
|
|
252
252
|
locale,
|
|
@@ -365,6 +365,9 @@ const TableContainerEdit = props => {
|
|
|
365
365
|
const [isPasting, setIsPasting] = _react.default.useState(false);
|
|
366
366
|
// const [isFullScreen] = React.useState(false);
|
|
367
367
|
const [tableHeight, settableHeight] = _react.default.useState(0);
|
|
368
|
+
|
|
369
|
+
// const [isAddNewRow, setIsAddNewRow] = React.useState(false)
|
|
370
|
+
|
|
368
371
|
const rowsFocus = _react.default.useMemo(() => {
|
|
369
372
|
return startCell && endCell ? (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId) : [];
|
|
370
373
|
}, [endCell, startCell, table]);
|
|
@@ -403,7 +406,7 @@ const TableContainerEdit = props => {
|
|
|
403
406
|
}, [startCell, endCell, table]);
|
|
404
407
|
const triggerChangeData = _react.default.useCallback(newData => {
|
|
405
408
|
onDataChange?.(newData);
|
|
406
|
-
}, [onDataChange]);
|
|
409
|
+
}, [onDataChange, dataSource]);
|
|
407
410
|
const triggerPaste = _react.default.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
|
|
408
411
|
const handlePasteCallback = callbackData => {
|
|
409
412
|
const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...originData]), callbackData);
|
|
@@ -962,6 +965,30 @@ const TableContainerEdit = props => {
|
|
|
962
965
|
mode: 'onChange',
|
|
963
966
|
resolver: validate ? (0, _yup.yupResolver)(validate) : undefined
|
|
964
967
|
});
|
|
968
|
+
const handleAddMulti = _react.default.useCallback((item, n, newId) => {
|
|
969
|
+
if (item.onClick) {
|
|
970
|
+
item.onClick({
|
|
971
|
+
toolbar: item
|
|
972
|
+
});
|
|
973
|
+
} else {
|
|
974
|
+
const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
|
|
975
|
+
const newRows = Array.from({
|
|
976
|
+
length: n
|
|
977
|
+
}).map(() => defaultRowValue ? {
|
|
978
|
+
...defaultRowValue,
|
|
979
|
+
id: undefined,
|
|
980
|
+
rowId: n === 1 && newId ? newId : (0, _utils.newGuid)()
|
|
981
|
+
} : {
|
|
982
|
+
id: undefined,
|
|
983
|
+
rowId: n === 1 && newId ? newId : (0, _utils.newGuid)()
|
|
984
|
+
});
|
|
985
|
+
const kkk = (0, _utils.getAllRowKey)(newRows) ?? [];
|
|
986
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
987
|
+
setMergedFilterKeys?.(rs);
|
|
988
|
+
const newData = dataSource.concat(newRows);
|
|
989
|
+
triggerChangeData?.(newData);
|
|
990
|
+
}
|
|
991
|
+
}, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
|
|
965
992
|
const onSubmit = formData => {
|
|
966
993
|
try {
|
|
967
994
|
// const record = (await form.validateFields()) as RecordType;
|
|
@@ -982,6 +1009,26 @@ const TableContainerEdit = props => {
|
|
|
982
1009
|
console.log('Validate Failed:', errInfo);
|
|
983
1010
|
}
|
|
984
1011
|
};
|
|
1012
|
+
const onSubmit2 = (formData, newOriginData) => {
|
|
1013
|
+
try {
|
|
1014
|
+
// const record = (await form.validateFields()) as RecordType;
|
|
1015
|
+
const row = {
|
|
1016
|
+
...formData
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
// const newData = [...dataSource]
|
|
1020
|
+
const newData = [...newOriginData];
|
|
1021
|
+
|
|
1022
|
+
// @ts-ignore
|
|
1023
|
+
const index = (0, _utils.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
|
|
1024
|
+
const rs = (0, _utils.updateArrayByKey)(newData, row, rowKey);
|
|
1025
|
+
if (index > -1) {
|
|
1026
|
+
triggerChangeData?.(rs);
|
|
1027
|
+
}
|
|
1028
|
+
} catch (errInfo) {
|
|
1029
|
+
console.log('Validate Failed:', errInfo);
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
985
1032
|
const handleCellChange = args => {
|
|
986
1033
|
const {
|
|
987
1034
|
record,
|
|
@@ -1039,30 +1086,111 @@ const TableContainerEdit = props => {
|
|
|
1039
1086
|
onSubmit(record);
|
|
1040
1087
|
}
|
|
1041
1088
|
};
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1089
|
+
const handleCellChangeAndAddRow = args => {
|
|
1090
|
+
const {
|
|
1091
|
+
record,
|
|
1092
|
+
type: changeType,
|
|
1093
|
+
newState,
|
|
1094
|
+
option,
|
|
1095
|
+
field,
|
|
1096
|
+
indexCol,
|
|
1097
|
+
indexRow,
|
|
1098
|
+
key
|
|
1099
|
+
} = args;
|
|
1100
|
+
|
|
1101
|
+
// add new row
|
|
1102
|
+
|
|
1103
|
+
const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
|
|
1104
|
+
const newRowId = (0, _utils.newGuid)();
|
|
1105
|
+
const newRows = Array.from({
|
|
1106
|
+
length: 1
|
|
1107
|
+
}).map(() => defaultRowValue ? {
|
|
1108
|
+
...defaultRowValue,
|
|
1109
|
+
id: undefined,
|
|
1110
|
+
rowId: newRowId
|
|
1111
|
+
} : {
|
|
1112
|
+
id: undefined,
|
|
1113
|
+
rowId: newRowId
|
|
1114
|
+
});
|
|
1115
|
+
const kkk = (0, _utils.getAllRowKey)(newRows) ?? [];
|
|
1116
|
+
const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
|
|
1117
|
+
setMergedFilterKeys?.(rs);
|
|
1118
|
+
const newData = originData.concat(newRows);
|
|
1119
|
+
setFocusedCell?.({
|
|
1120
|
+
rowId: newRowId,
|
|
1121
|
+
colId: field
|
|
1122
|
+
});
|
|
1123
|
+
setStartCell?.({
|
|
1124
|
+
rowId: newRowId,
|
|
1125
|
+
colId: field
|
|
1126
|
+
});
|
|
1127
|
+
setEndCell?.({
|
|
1128
|
+
rowId: newRowId,
|
|
1129
|
+
colId: field
|
|
1130
|
+
});
|
|
1131
|
+
setTimeout(() => {
|
|
1132
|
+
setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
|
|
1133
|
+
rowId: newRowId,
|
|
1134
|
+
colId: field
|
|
1135
|
+
}, {
|
|
1136
|
+
rowId: newRowId,
|
|
1137
|
+
colId: field
|
|
1138
|
+
}));
|
|
1139
|
+
});
|
|
1140
|
+
setTimeout(() => {
|
|
1141
|
+
const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
|
|
1142
|
+
const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
|
|
1143
|
+
if (cellFocus) {
|
|
1144
|
+
cellFocus.scrollIntoView({
|
|
1145
|
+
behavior: "smooth",
|
|
1146
|
+
block: "start"
|
|
1147
|
+
});
|
|
1148
|
+
cellFocus.focus();
|
|
1149
|
+
}
|
|
1150
|
+
}, 100);
|
|
1151
|
+
if (changeType === 'blur') {
|
|
1152
|
+
const handleChangeCallback = callbackData => {
|
|
1153
|
+
const callbackRecord = callbackData;
|
|
1154
|
+
onSubmit2(callbackRecord, [...newData]);
|
|
1155
|
+
};
|
|
1156
|
+
if (onCellChange) {
|
|
1157
|
+
if (onCellChange.length > 1) {
|
|
1158
|
+
onCellChange({
|
|
1159
|
+
field,
|
|
1160
|
+
indexCol,
|
|
1161
|
+
type: 'onChange',
|
|
1162
|
+
value: newState,
|
|
1163
|
+
option,
|
|
1164
|
+
indexRow,
|
|
1165
|
+
rowData: record,
|
|
1166
|
+
rowId: key,
|
|
1167
|
+
rowsData: [...newData],
|
|
1168
|
+
sumValue: []
|
|
1169
|
+
}, handleChangeCallback);
|
|
1170
|
+
} else {
|
|
1171
|
+
onCellChange({
|
|
1172
|
+
field,
|
|
1173
|
+
indexCol,
|
|
1174
|
+
type: 'onChange',
|
|
1175
|
+
option,
|
|
1176
|
+
value: newState,
|
|
1177
|
+
indexRow,
|
|
1178
|
+
rowData: record,
|
|
1179
|
+
rowId: key,
|
|
1180
|
+
rowsData: [...newData],
|
|
1181
|
+
sumValue: []
|
|
1182
|
+
}, handleChangeCallback);
|
|
1183
|
+
onSubmit2(record, [...newData]);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1064
1186
|
}
|
|
1065
|
-
|
|
1187
|
+
|
|
1188
|
+
// if (prevState && newState && prevState !== newState && changeType === 'enter') {
|
|
1189
|
+
|
|
1190
|
+
// onSubmit(record)
|
|
1191
|
+
|
|
1192
|
+
// }
|
|
1193
|
+
};
|
|
1066
1194
|
const handleDuplicate = _react.default.useCallback(() => {
|
|
1067
1195
|
// không tính tree
|
|
1068
1196
|
|
|
@@ -1789,10 +1917,6 @@ const TableContainerEdit = props => {
|
|
|
1789
1917
|
ref: topToolbarRef,
|
|
1790
1918
|
className: (0, _classnames.default)(`${prefix}-grid-top-toolbar`, {})
|
|
1791
1919
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
1792
|
-
style: {
|
|
1793
|
-
textAlign: 'center'
|
|
1794
|
-
}
|
|
1795
|
-
}, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/_react.default.createElement("div", {
|
|
1796
1920
|
style: {
|
|
1797
1921
|
display: 'flex',
|
|
1798
1922
|
justifyContent: 'space-between',
|
|
@@ -1843,7 +1967,11 @@ const TableContainerEdit = props => {
|
|
|
1843
1967
|
columnsGroup: groupColumns,
|
|
1844
1968
|
triggerChangeColumns: triggerChangeColumns,
|
|
1845
1969
|
columnHidden: columnHidden
|
|
1846
|
-
})))
|
|
1970
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
1971
|
+
style: {
|
|
1972
|
+
textAlign: 'center'
|
|
1973
|
+
}
|
|
1974
|
+
}, typeof title === 'function' ? title?.(originData) : title)), /*#__PURE__*/_react.default.createElement("form", {
|
|
1847
1975
|
onSubmit: handleSubmit(onSubmit)
|
|
1848
1976
|
}, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
|
|
1849
1977
|
value: {
|
|
@@ -1895,6 +2023,7 @@ const TableContainerEdit = props => {
|
|
|
1895
2023
|
setValue,
|
|
1896
2024
|
reset,
|
|
1897
2025
|
handleCellChange,
|
|
2026
|
+
handleCellChangeAndAddRow,
|
|
1898
2027
|
triggerPaste,
|
|
1899
2028
|
handleDeleteContent,
|
|
1900
2029
|
handleAddMulti,
|
|
@@ -233,7 +233,7 @@ const TableBodyCellEdit = props => {
|
|
|
233
233
|
setValue,
|
|
234
234
|
getValues,
|
|
235
235
|
handleCellChange,
|
|
236
|
-
|
|
236
|
+
handleCellChangeAndAddRow,
|
|
237
237
|
dataErrors,
|
|
238
238
|
expanded,
|
|
239
239
|
setExpanded,
|
|
@@ -243,17 +243,13 @@ const TableBodyCellEdit = props => {
|
|
|
243
243
|
isSelectionChange,
|
|
244
244
|
setIsSelectionChange,
|
|
245
245
|
selectionSettings,
|
|
246
|
-
pagination
|
|
246
|
+
pagination,
|
|
247
|
+
handleAddMulti
|
|
247
248
|
} = _react.default.useContext(_useContext.TableContext);
|
|
248
249
|
const expandIconColumnIndex = expandable?.expandIconColumnIndex;
|
|
249
250
|
const record = cell.row.original;
|
|
250
251
|
const columnMeta = cell.column.columnDef.meta ?? {};
|
|
251
252
|
const [isOpenTooltip, setIsOpenTooltip] = _react.default.useState(false);
|
|
252
|
-
|
|
253
|
-
// const cellContent = columnMeta.type === 'checkbox' ? '' : flexRender(cell.column.columnDef.cell, cell.getContext());
|
|
254
|
-
// const html = ReactDOMServer.renderToStaticMarkup(<>{cellContent}</>);
|
|
255
|
-
// const hasValue = html.trim().length > 0;
|
|
256
|
-
|
|
257
253
|
const rowError = dataErrors ? dataErrors.find(it => it.id === cell.row.id) : undefined;
|
|
258
254
|
const message = rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : undefined;
|
|
259
255
|
const tooltipContent = isOpenTooltip === false ? '' : columnMeta?.tooltipDescription ? typeof columnMeta.tooltipDescription === 'function' ? columnMeta.tooltipDescription({
|
|
@@ -789,6 +785,8 @@ const TableBodyCellEdit = props => {
|
|
|
789
785
|
return;
|
|
790
786
|
}
|
|
791
787
|
if (e.key === 'Enter') {
|
|
788
|
+
e.preventDefault();
|
|
789
|
+
e.stopPropagation();
|
|
792
790
|
handleEdit(e, true);
|
|
793
791
|
return;
|
|
794
792
|
}
|
|
@@ -1044,6 +1042,64 @@ const TableBodyCellEdit = props => {
|
|
|
1044
1042
|
indexRow: currentRowIndex,
|
|
1045
1043
|
type: 'blur'
|
|
1046
1044
|
});
|
|
1045
|
+
} else {}
|
|
1046
|
+
};
|
|
1047
|
+
const handleChangeAndCreateRow = () => {
|
|
1048
|
+
const currentRowIndex = allRows.findIndex(r => r.id === editingKey);
|
|
1049
|
+
const formState = getValues();
|
|
1050
|
+
const itemState = getValues(cell.column.id);
|
|
1051
|
+
const prevState = record[cell.column.id];
|
|
1052
|
+
const newState = itemState;
|
|
1053
|
+
if (newState !== prevState) {
|
|
1054
|
+
// vừa cell change + add new row
|
|
1055
|
+
handleCellChangeAndAddRow?.({
|
|
1056
|
+
key: cell.row.id,
|
|
1057
|
+
field: cell.column.id,
|
|
1058
|
+
record: formState,
|
|
1059
|
+
prevState,
|
|
1060
|
+
newState,
|
|
1061
|
+
option: newState,
|
|
1062
|
+
indexCol: cell.column.getIndex(),
|
|
1063
|
+
indexRow: currentRowIndex,
|
|
1064
|
+
type: 'blur'
|
|
1065
|
+
});
|
|
1066
|
+
} else {
|
|
1067
|
+
// chỉ add new row
|
|
1068
|
+
|
|
1069
|
+
const newRowId = (0, _utils.newGuid)();
|
|
1070
|
+
handleAddMulti?.({}, 1, newRowId);
|
|
1071
|
+
setFocusedCell?.({
|
|
1072
|
+
rowId: newRowId,
|
|
1073
|
+
colId: cell.column.id
|
|
1074
|
+
});
|
|
1075
|
+
setStartCell?.({
|
|
1076
|
+
rowId: newRowId,
|
|
1077
|
+
colId: cell.column.id
|
|
1078
|
+
});
|
|
1079
|
+
setEndCell?.({
|
|
1080
|
+
rowId: newRowId,
|
|
1081
|
+
colId: cell.column.id
|
|
1082
|
+
});
|
|
1083
|
+
setTimeout(() => {
|
|
1084
|
+
setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
|
|
1085
|
+
rowId: newRowId,
|
|
1086
|
+
colId: cell.column.id
|
|
1087
|
+
}, {
|
|
1088
|
+
rowId: newRowId,
|
|
1089
|
+
colId: cell.column.id
|
|
1090
|
+
}));
|
|
1091
|
+
});
|
|
1092
|
+
setTimeout(() => {
|
|
1093
|
+
const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
|
|
1094
|
+
const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
|
|
1095
|
+
if (cellFocus) {
|
|
1096
|
+
cellFocus.scrollIntoView({
|
|
1097
|
+
behavior: "smooth",
|
|
1098
|
+
block: "start"
|
|
1099
|
+
});
|
|
1100
|
+
cellFocus.focus();
|
|
1101
|
+
}
|
|
1102
|
+
}, 100);
|
|
1047
1103
|
}
|
|
1048
1104
|
};
|
|
1049
1105
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -1116,9 +1172,10 @@ const TableBodyCellEdit = props => {
|
|
|
1116
1172
|
if (!isEditing) {
|
|
1117
1173
|
handleKeyDown(e, cell.row.id, cell.column.id);
|
|
1118
1174
|
} else {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1175
|
+
if (e.shiftKey && e.key === 'Enter') {
|
|
1176
|
+
e.preventDefault();
|
|
1177
|
+
e.stopPropagation();
|
|
1178
|
+
} else {
|
|
1122
1179
|
if (e.key === 'Enter') {
|
|
1123
1180
|
e.preventDefault();
|
|
1124
1181
|
e.stopPropagation();
|
|
@@ -1147,29 +1204,10 @@ const TableBodyCellEdit = props => {
|
|
|
1147
1204
|
rowVirtualizer.scrollToIndex(nextRow.index, {
|
|
1148
1205
|
align: 'center'
|
|
1149
1206
|
});
|
|
1207
|
+
handleChange();
|
|
1150
1208
|
} else {
|
|
1151
|
-
|
|
1152
|
-
// const newRowId = newGuid()
|
|
1153
|
-
// handleAddMulti?.({}, 1, newRowId)
|
|
1154
|
-
|
|
1155
|
-
// setFocusedCell?.({ rowId: newRowId, colId: cell.column.id });
|
|
1156
|
-
|
|
1157
|
-
// setStartCell?.({ rowId: newRowId, colId: cell.column.id });
|
|
1158
|
-
// setEndCell?.({ rowId: newRowId, colId: cell.column.id });
|
|
1159
|
-
|
|
1160
|
-
// setTimeout(() => {
|
|
1161
|
-
// setRangeState?.(getSelectedCellMatrix(table, { rowId: newRowId, colId: cell.column.id }, { rowId: newRowId, colId: cell.column.id }))
|
|
1162
|
-
// // rowVirtualizer.scrollToIndex(currentRowIndex + 1, { align: 'end', })
|
|
1163
|
-
|
|
1164
|
-
// })
|
|
1165
|
-
|
|
1166
|
-
// setTimeout(() => {
|
|
1167
|
-
|
|
1168
|
-
// rowVirtualizer.scrollToIndex(currentRowIndex + 1, { align: 'center', })
|
|
1169
|
-
|
|
1170
|
-
// }, 100)
|
|
1209
|
+
handleChangeAndCreateRow();
|
|
1171
1210
|
}
|
|
1172
|
-
handleChange();
|
|
1173
1211
|
setEditingKey?.('');
|
|
1174
1212
|
reset?.();
|
|
1175
1213
|
}
|
|
@@ -154,3 +154,5 @@ export declare function countUnselectedChildren(row: Row<any>): number;
|
|
|
154
154
|
export declare function removeDuplicatesByKey(arr: any[], key?: string): any[];
|
|
155
155
|
export declare const getTableHeight: (height?: number, minHeight?: number) => number;
|
|
156
156
|
export declare const convertFlatColumn1: (array: ColumnsTable) => ColumnsTable[];
|
|
157
|
+
export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string[]) => any[];
|
|
158
|
+
export declare const removeColumns: <RecordType>(columns: ColumnTable<RecordType>[], groupColumns: string[]) => ColumnsTable<RecordType>;
|
|
@@ -53,6 +53,7 @@ exports.parseClipboardEvent = parseClipboardEvent;
|
|
|
53
53
|
exports.parseExcelClipboard = parseExcelClipboard;
|
|
54
54
|
exports.parseExcelClipboardText = parseExcelClipboardText;
|
|
55
55
|
exports.parseExcelText = parseExcelText;
|
|
56
|
+
exports.removeColumns = void 0;
|
|
56
57
|
exports.removeDuplicatesByKey = removeDuplicatesByKey;
|
|
57
58
|
exports.sortByType = exports.shouldInclude = exports.removeVietnameseTones = void 0;
|
|
58
59
|
exports.sortData = sortData;
|
|
@@ -60,14 +61,15 @@ exports.sumSize = void 0;
|
|
|
60
61
|
exports.toggleRowAndChildren = toggleRowAndChildren;
|
|
61
62
|
exports.updateArrayByKey = exports.unFlattenData = void 0;
|
|
62
63
|
exports.updateColumnWidthsRecursive = updateColumnWidthsRecursive;
|
|
63
|
-
exports.updateColumns1 = void 0;
|
|
64
|
+
exports.updateColumnsByGroup = exports.updateColumns1 = void 0;
|
|
64
65
|
exports.updateOrInsert = updateOrInsert;
|
|
65
66
|
exports.updateWidthsByOther = updateWidthsByOther;
|
|
66
|
-
var _useSelection = require("rc-master-ui/es/table/hooks/useSelection");
|
|
67
67
|
var _uuid = require("uuid");
|
|
68
68
|
var _colors = require("@ant-design/colors");
|
|
69
69
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
70
70
|
var _moment = _interopRequireDefault(require("moment"));
|
|
71
|
+
// import { SELECTION_COLUMN } from "rc-master-ui/es/table/hooks/useSelection"
|
|
72
|
+
|
|
71
73
|
// import moment from "moment/moment"
|
|
72
74
|
|
|
73
75
|
const newGuid = () => {
|
|
@@ -343,7 +345,7 @@ function groupArrayByColumns(arr, columns) {
|
|
|
343
345
|
const flatColumns2 = columns => {
|
|
344
346
|
return columns.reduce((list, column) => {
|
|
345
347
|
const subColumns = column.children;
|
|
346
|
-
if (column ===
|
|
348
|
+
if (column.field === 'selection_column') {
|
|
347
349
|
return [...list, {
|
|
348
350
|
...column
|
|
349
351
|
}];
|
|
@@ -2304,4 +2306,43 @@ const convertFlatColumn1 = array => {
|
|
|
2304
2306
|
});
|
|
2305
2307
|
return result;
|
|
2306
2308
|
};
|
|
2307
|
-
exports.convertFlatColumn1 = convertFlatColumn1;
|
|
2309
|
+
exports.convertFlatColumn1 = convertFlatColumn1;
|
|
2310
|
+
const updateColumnsByGroup = (columns, columnsGroup) => {
|
|
2311
|
+
return columns.map(column => {
|
|
2312
|
+
const newColumn = {
|
|
2313
|
+
...column
|
|
2314
|
+
};
|
|
2315
|
+
let hasVisibleChild = false;
|
|
2316
|
+
if (!column.field) {
|
|
2317
|
+
return column;
|
|
2318
|
+
}
|
|
2319
|
+
if (newColumn.children) {
|
|
2320
|
+
newColumn.children = updateColumnsByGroup(newColumn.children, columnsGroup);
|
|
2321
|
+
hasVisibleChild = newColumn.children.some(child => child.visible !== false);
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
// Map previous behaviour (hidden = true when field in columnsGroup)
|
|
2325
|
+
// to the new `visible` property: visible = !hidden
|
|
2326
|
+
newColumn.visible = !(newColumn.field && columnsGroup.includes(newColumn.field));
|
|
2327
|
+
|
|
2328
|
+
// For parent columns, visibility depends on whether any child is visible
|
|
2329
|
+
if (newColumn.children && newColumn.children.length > 0) {
|
|
2330
|
+
newColumn.visible = !!hasVisibleChild;
|
|
2331
|
+
}
|
|
2332
|
+
return newColumn;
|
|
2333
|
+
});
|
|
2334
|
+
};
|
|
2335
|
+
exports.updateColumnsByGroup = updateColumnsByGroup;
|
|
2336
|
+
const removeColumns = (columns, groupColumns) => {
|
|
2337
|
+
const ttt = [...columns];
|
|
2338
|
+
return ttt.filter(column => !groupColumns.includes(column.field)).map(column => {
|
|
2339
|
+
const newCol = {
|
|
2340
|
+
...column
|
|
2341
|
+
};
|
|
2342
|
+
if (newCol?.children && newCol?.children.length > 0) {
|
|
2343
|
+
newCol.children = removeColumns(newCol.children, groupColumns);
|
|
2344
|
+
}
|
|
2345
|
+
return newCol;
|
|
2346
|
+
});
|
|
2347
|
+
};
|
|
2348
|
+
exports.removeColumns = removeColumns;
|
|
@@ -63,6 +63,7 @@ const Grid = props => {
|
|
|
63
63
|
mergedSelectedKeys,
|
|
64
64
|
allowResizing,
|
|
65
65
|
windowSize,
|
|
66
|
+
fullScreenTitle,
|
|
66
67
|
...rest
|
|
67
68
|
} = props;
|
|
68
69
|
const [columnResizeMode] = _react.default.useState('onChange');
|
|
@@ -320,9 +321,7 @@ const Grid = props => {
|
|
|
320
321
|
style: {
|
|
321
322
|
maxWidth: '100%',
|
|
322
323
|
height: '100%'
|
|
323
|
-
}
|
|
324
|
-
// onClose={() => setIsFullScreen(false)}
|
|
325
|
-
,
|
|
324
|
+
},
|
|
326
325
|
onCancel: () => setIsFullScreen(false)
|
|
327
326
|
|
|
328
327
|
// destroyOnClose
|
|
@@ -337,12 +336,16 @@ const Grid = props => {
|
|
|
337
336
|
zIndex: 1050
|
|
338
337
|
}
|
|
339
338
|
},
|
|
339
|
+
title: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, " ", typeof fullScreenTitle === 'function' ? fullScreenTitle?.() : fullScreenTitle, " "),
|
|
340
340
|
destroyOnClose: true
|
|
341
341
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
342
|
-
style: {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
342
|
+
style: {}
|
|
343
|
+
}, /*#__PURE__*/_react.default.createElement(_style.GridStyle, {
|
|
344
|
+
$prefix: prefix,
|
|
345
|
+
$theme: {
|
|
346
|
+
theme: theme?.theme,
|
|
347
|
+
...theme
|
|
348
|
+
},
|
|
346
349
|
className: (0, _classnames.default)(`${prefix}-grid`, {
|
|
347
350
|
[`${prefix}-grid-light`]: !theme || theme.theme === 'light',
|
|
348
351
|
[`${prefix}-grid-dark`]: theme?.theme === 'dark'
|
|
@@ -189,11 +189,9 @@ const TableWrapper = props => {
|
|
|
189
189
|
//our scrollable table container
|
|
190
190
|
position: 'relative',
|
|
191
191
|
//needed for sticky header
|
|
192
|
-
// height: height, //should be a fixed height
|
|
193
192
|
maxHeight: height,
|
|
194
193
|
//should be a fixed height
|
|
195
194
|
minHeight: minHeight ? height : undefined //should be a fixed height
|
|
196
|
-
// minWidth: table.getTotalSize()
|
|
197
195
|
}
|
|
198
196
|
// onScroll={infiniteScroll ? handleScroll : undefined}
|
|
199
197
|
,
|
|
@@ -198,6 +198,7 @@ export type TableProps<RecordType = AnyObject> = {
|
|
|
198
198
|
color?: string;
|
|
199
199
|
};
|
|
200
200
|
title?: ReactNode | ((data: RecordType) => ReactNode);
|
|
201
|
+
fullScreenTitle?: ReactNode | (() => ReactNode);
|
|
201
202
|
editAble?: boolean;
|
|
202
203
|
infiniteScroll?: boolean;
|
|
203
204
|
next?: () => void;
|
|
@@ -48,6 +48,7 @@ export interface IContext<T> {
|
|
|
48
48
|
reset?: any;
|
|
49
49
|
setValue?: any;
|
|
50
50
|
handleCellChange?: (args: ContextCellChange) => void;
|
|
51
|
+
handleCellChangeAndAddRow?: (args: ContextCellChange) => void;
|
|
51
52
|
editingKey?: string;
|
|
52
53
|
setEditingKey?: Dispatch<SetStateAction<string>>;
|
|
53
54
|
rangeState?: RangeState;
|
|
@@ -86,11 +87,12 @@ export declare const TableContext: import("react").Context<IContext<any>>;
|
|
|
86
87
|
export type ContextCellChange = {
|
|
87
88
|
key: string;
|
|
88
89
|
record: any;
|
|
89
|
-
field: string
|
|
90
|
+
field: string;
|
|
90
91
|
option: any;
|
|
91
92
|
indexRow: number;
|
|
92
93
|
indexCol: number;
|
|
93
94
|
newState?: any;
|
|
94
95
|
prevState?: any;
|
|
95
96
|
type: 'enter' | 'blur' | 'outClick';
|
|
97
|
+
addNewRow?: boolean;
|
|
96
98
|
};
|