es-grid-template 1.9.50 → 1.9.52
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/ali-table/utils/convertColumnsChoose.d.ts +2 -2
- package/es/group-component/hook/utils.d.ts +8 -8
- package/es/table-component/TableContainerEdit.js +73 -56
- package/es/table-component/body/EditableCell.d.ts +3 -0
- package/es/table-component/body/EditableCell.js +122 -36
- package/es/table-component/body/TableBodyCellEdit.js +70 -9
- package/es/table-component/hook/useColumns.js +3 -2
- package/es/table-component/hook/utils.d.ts +3 -0
- package/es/table-component/hook/utils.js +33 -1
- package/es/table-component/style.js +1 -1
- package/es/table-component/style.scss +6 -0
- package/lib/ali-table/utils/convertColumnsChoose.d.ts +2 -2
- package/lib/table-component/TableContainerEdit.js +71 -55
- package/lib/table-component/body/EditableCell.d.ts +3 -0
- package/lib/table-component/body/EditableCell.js +122 -36
- package/lib/table-component/body/TableBodyCellEdit.js +69 -8
- package/lib/table-component/hook/useColumns.js +3 -2
- package/lib/table-component/hook/utils.d.ts +3 -0
- package/lib/table-component/hook/utils.js +38 -4
- package/lib/table-component/style.js +1 -1
- package/lib/table-component/style.scss +6 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TreeDataNode } from "antd";
|
|
2
|
-
import { ColumnTable } from "../../grid-component";
|
|
1
|
+
import type { TreeDataNode } from "antd";
|
|
2
|
+
import type { ColumnTable } from "../../grid-component";
|
|
3
3
|
export declare function convertColumnsToTreeData(columns: ColumnTable[], groupColumns?: string[], t?: any): TreeDataNode[];
|
|
4
4
|
export declare function filterColumnsByField(columns: ColumnTable[], fieldList: string[]): ColumnTable[];
|
|
5
5
|
export declare function filterVisibleColumns(columns: ColumnTable[]): ColumnTable[];
|
|
@@ -166,7 +166,7 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
|
|
|
166
166
|
haveSum?: boolean;
|
|
167
167
|
isSummary?: boolean;
|
|
168
168
|
sumGroup?: boolean;
|
|
169
|
-
summaryTemplate?: (data: number, key: string) => import("react").
|
|
169
|
+
summaryTemplate?: (data: number, key: string) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
|
|
170
170
|
sorter?: boolean;
|
|
171
171
|
allowFiltering?: boolean;
|
|
172
172
|
allowSortering?: boolean;
|
|
@@ -178,26 +178,26 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
|
|
|
178
178
|
showFilterSearch?: boolean;
|
|
179
179
|
hidden?: boolean;
|
|
180
180
|
visible?: boolean;
|
|
181
|
-
headerTooltip?: string | boolean | (() => import("react").
|
|
181
|
+
headerTooltip?: string | boolean | (() => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
|
|
182
182
|
columnGroupText?: string;
|
|
183
183
|
headerTextAlign?: import("./../../grid-component/type").ITextAlign;
|
|
184
|
-
headerTemplate?: import("react").
|
|
184
|
+
headerTemplate?: import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | ((column: ColumnTable<RecordType>) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
|
|
185
185
|
fixedType?: import("./../../grid-component/type").FixedType;
|
|
186
186
|
headerTextWrap?: boolean;
|
|
187
187
|
ellipsis?: boolean;
|
|
188
188
|
allowResizing?: boolean;
|
|
189
189
|
align?: import("./../../grid-component/type").ITextAlign;
|
|
190
190
|
textAlign?: import("./../../grid-component/type").ITextAlign;
|
|
191
|
-
template?: import("react").
|
|
191
|
+
template?: import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
|
|
192
192
|
showTooltip?: boolean;
|
|
193
193
|
tooltipDescription?: string | ((args: {
|
|
194
194
|
value: any;
|
|
195
195
|
rowData: RecordType;
|
|
196
|
-
}) => import("react").
|
|
197
|
-
onCellStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
198
|
-
onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
196
|
+
}) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
|
|
197
|
+
onCellStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
|
|
198
|
+
onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
|
|
199
199
|
onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
|
|
200
|
-
onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
200
|
+
onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
|
|
201
201
|
getValue?: (row: any, rowIndex: number) => any;
|
|
202
202
|
getCellProps?: (value: any, row: any, rowIndex: number) => import("./../../grid-component/type").CellProps;
|
|
203
203
|
headerCellProps?: import("./../../grid-component/type").CellProps;
|
|
@@ -3,7 +3,8 @@ import React, { Fragment } from "react";
|
|
|
3
3
|
import { useCopyToClipboard } from 'usehooks-ts';
|
|
4
4
|
import { checkDecimalSeparator, checkThousandSeparator,
|
|
5
5
|
// convertDateToDayjs,
|
|
6
|
-
detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween,
|
|
6
|
+
detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween,
|
|
7
|
+
// getDatepickerFormat,
|
|
7
8
|
// getDatepickerFormat,
|
|
8
9
|
getDefaultValue, getEditType, getFormat, getRowIdsBetween, getSelectedCellMatrix, getTableHeight, isDateValue, isEditable, isEmpty, isFormattedNumber, newGuid, parseExcelClipboard,
|
|
9
10
|
// parseExcelClipboardText,
|
|
@@ -256,39 +257,6 @@ const TableContainerEdit = props => {
|
|
|
256
257
|
const rowsFocus = React.useMemo(() => {
|
|
257
258
|
return startCell && endCell ? getRowIdsBetween(table, startCell.rowId, endCell.rowId) : [];
|
|
258
259
|
}, [endCell, startCell, table]);
|
|
259
|
-
const copySelectionToClipboard = React.useCallback(() => {
|
|
260
|
-
if (!startCell || !endCell) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// const allRows = table.getRowModel().rows;
|
|
265
|
-
const allRows = table.getRowModel().flatRows;
|
|
266
|
-
// const allColumns = table.getAllLeafColumns();
|
|
267
|
-
|
|
268
|
-
const rowIds = getRowIdsBetween(table, startCell.rowId, endCell.rowId);
|
|
269
|
-
const colIds = getColIdsBetween(table, startCell.colId, endCell.colId);
|
|
270
|
-
const dataToCopy = [];
|
|
271
|
-
rowIds.forEach(rowId => {
|
|
272
|
-
const row = allRows.find(r => r.id === rowId);
|
|
273
|
-
if (!row) return;
|
|
274
|
-
const rowData = [];
|
|
275
|
-
colIds.forEach(colId => {
|
|
276
|
-
const cellll = row.getVisibleCells().find(c => c.column.id === colId);
|
|
277
|
-
const value = cellll?.getValue();
|
|
278
|
-
rowData.push(value !== undefined ? String(value) : '');
|
|
279
|
-
});
|
|
280
|
-
dataToCopy.push(rowData);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
// Convert to TSV string
|
|
284
|
-
const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
|
|
285
|
-
|
|
286
|
-
// Copy to clipboard
|
|
287
|
-
// navigator.clipboard.writeText(tsv).then(() => {
|
|
288
|
-
// });
|
|
289
|
-
|
|
290
|
-
copy(tsv).then(() => {}).catch(() => {});
|
|
291
|
-
}, [startCell, endCell, table]);
|
|
292
260
|
const triggerChangeData = React.useCallback((newData, args) => {
|
|
293
261
|
onDataChange?.(newData, args);
|
|
294
262
|
}, [onDataChange, dataSource]);
|
|
@@ -329,6 +297,55 @@ const TableContainerEdit = props => {
|
|
|
329
297
|
});
|
|
330
298
|
}
|
|
331
299
|
}, [onCellPaste, originData, triggerChangeData]);
|
|
300
|
+
|
|
301
|
+
// Copy
|
|
302
|
+
|
|
303
|
+
const copySelectionToClipboard = React.useCallback(() => {
|
|
304
|
+
if (!startCell || !endCell) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// const allRows = table.getRowModel().rows;
|
|
309
|
+
const allRows = table.getRowModel().flatRows;
|
|
310
|
+
// const allColumns = table.getAllLeafColumns();
|
|
311
|
+
|
|
312
|
+
const rowIds = getRowIdsBetween(table, startCell.rowId, endCell.rowId);
|
|
313
|
+
const colIds = getColIdsBetween(table, startCell.colId, endCell.colId);
|
|
314
|
+
const dataToCopy = [];
|
|
315
|
+
rowIds.forEach(rowId => {
|
|
316
|
+
const row = allRows.find(r => r.id === rowId);
|
|
317
|
+
if (!row) return;
|
|
318
|
+
const rowData = [];
|
|
319
|
+
colIds.forEach(colId => {
|
|
320
|
+
const cellll = row.getVisibleCells().find(c => c.column.id === colId);
|
|
321
|
+
const value = cellll?.getValue();
|
|
322
|
+
rowData.push(value !== undefined ? String(value) : '');
|
|
323
|
+
});
|
|
324
|
+
dataToCopy.push(rowData);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// Convert to TSV string
|
|
328
|
+
const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
|
|
329
|
+
|
|
330
|
+
// Copy to clipboard
|
|
331
|
+
// navigator.clipboard.writeText(tsv).then(() => {
|
|
332
|
+
// });
|
|
333
|
+
|
|
334
|
+
copy(tsv).then(() => {}).catch(() => {});
|
|
335
|
+
}, [startCell, endCell, table]);
|
|
336
|
+
React.useEffect(() => {
|
|
337
|
+
const handleKeyDown = e => {
|
|
338
|
+
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
|
|
339
|
+
e.preventDefault();
|
|
340
|
+
copySelectionToClipboard();
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
344
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
345
|
+
}, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
|
|
346
|
+
|
|
347
|
+
// Paste
|
|
348
|
+
|
|
332
349
|
const handlePasted = React.useCallback(pasteData => {
|
|
333
350
|
if (!startCell) {
|
|
334
351
|
return;
|
|
@@ -336,7 +353,8 @@ const TableContainerEdit = props => {
|
|
|
336
353
|
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
337
354
|
|
|
338
355
|
// const allRows = table.getRowModel().rows;
|
|
339
|
-
const
|
|
356
|
+
const flatRows = table.getRowModel().flatRows;
|
|
357
|
+
const allRows = flatRows.filter((item, index, self) => index === self.findIndex(x => x.id === item.id));
|
|
340
358
|
const allCols = table.getVisibleLeafColumns();
|
|
341
359
|
const startRowIdx = allRows.findIndex(r => r.id === startCell.rowId);
|
|
342
360
|
const startColIdx = allCols.findIndex(c => c.id === startCell.colId);
|
|
@@ -360,7 +378,7 @@ const TableContainerEdit = props => {
|
|
|
360
378
|
const targetRow = startRow + rowIndex;
|
|
361
379
|
|
|
362
380
|
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
363
|
-
if (targetRow
|
|
381
|
+
if (targetRow > newData.length) {
|
|
364
382
|
const newID = newGuid();
|
|
365
383
|
const defaultRowValue = getDefaultValue(defaultValue);
|
|
366
384
|
newData.push(defaultValue ? {
|
|
@@ -416,11 +434,14 @@ const TableContainerEdit = props => {
|
|
|
416
434
|
}
|
|
417
435
|
} else if (columnOri.type === 'data' || columnOri.type === 'datatime' || columnOri.editType === 'date' || columnOri.editType === 'datetime') {
|
|
418
436
|
const isDate = isDateValue(cellValue.trim());
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
const
|
|
422
|
-
const
|
|
423
|
-
const
|
|
437
|
+
|
|
438
|
+
// const colFormat = typeof columnOri?.format === 'function' ? columnOri?.format(record) : columnOri?.format
|
|
439
|
+
// const cellFormat = getFormat(colFormat, format)
|
|
440
|
+
// const editType = getEditType(columnOri as any)
|
|
441
|
+
// const dateFormat = getDatepickerFormat(editType, cellFormat)
|
|
442
|
+
// const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim(), dateFormat, true).format() : null
|
|
443
|
+
|
|
444
|
+
const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim()).format() : null;
|
|
424
445
|
newData[targetRow] = {
|
|
425
446
|
...newData[targetRow],
|
|
426
447
|
[columnKey]: date
|
|
@@ -521,11 +542,17 @@ const TableContainerEdit = props => {
|
|
|
521
542
|
}
|
|
522
543
|
} else if (columnOri.type === 'data' || columnOri.type === 'datatime' || columnOri.editType === 'date' || columnOri.editType === 'datetime') {
|
|
523
544
|
const isDate = isDateValue(cellValue.trim());
|
|
524
|
-
|
|
525
|
-
const
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
const
|
|
545
|
+
|
|
546
|
+
// const colFormat = typeof columnOri?.format === 'function' ? columnOri?.format(record) : columnOri?.format
|
|
547
|
+
// const cellFormat = getFormat(colFormat, format)
|
|
548
|
+
|
|
549
|
+
// const editType = getEditType(columnOri as any)
|
|
550
|
+
|
|
551
|
+
// const dateFormat = getDatepickerFormat(editType, cellFormat)
|
|
552
|
+
|
|
553
|
+
// const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim(), dateFormat).format("YYYY-MM-DDTHH:mm:ssZ") : null
|
|
554
|
+
|
|
555
|
+
const date = isDate && !isEmpty(cellValue.trim()) ? moment(cellValue.trim()).format() : null;
|
|
529
556
|
childData[targetRow] = {
|
|
530
557
|
...childData[targetRow],
|
|
531
558
|
[columnKey]: date
|
|
@@ -600,16 +627,6 @@ const TableContainerEdit = props => {
|
|
|
600
627
|
handlePasted(rowsPasted);
|
|
601
628
|
}
|
|
602
629
|
}, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
|
|
603
|
-
React.useEffect(() => {
|
|
604
|
-
const handleKeyDown = e => {
|
|
605
|
-
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
|
|
606
|
-
e.preventDefault();
|
|
607
|
-
copySelectionToClipboard();
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
document.addEventListener('keydown', handleKeyDown);
|
|
611
|
-
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
612
|
-
}, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
|
|
613
630
|
React.useEffect(() => {
|
|
614
631
|
const handlePaste = e => {
|
|
615
632
|
if (startCell && !editingKey) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { EditType } from "rc-master-ui";
|
|
3
3
|
import type { ColumnTable, IFormat } from "../../grid-component/type";
|
|
4
|
+
import type { Column } from "@tanstack/react-table";
|
|
4
5
|
interface EditableCellProps<DataType> extends React.HTMLAttributes<HTMLElement> {
|
|
5
6
|
t?: any;
|
|
6
7
|
dataIndex: string;
|
|
@@ -11,6 +12,8 @@ interface EditableCellProps<DataType> extends React.HTMLAttributes<HTMLElement>
|
|
|
11
12
|
indexRow: number;
|
|
12
13
|
indexCol: number;
|
|
13
14
|
cellEditing?: any;
|
|
15
|
+
visibleColumns?: Column<DataType>[];
|
|
16
|
+
handleNextCell?: () => void;
|
|
14
17
|
}
|
|
15
18
|
declare const EditableCell: <T>(props: EditableCellProps<T>) => JSX.Element;
|
|
16
19
|
export default EditableCell;
|
|
@@ -43,7 +43,9 @@ const EditableCell = props => {
|
|
|
43
43
|
// children,
|
|
44
44
|
column,
|
|
45
45
|
indexRow,
|
|
46
|
-
indexCol
|
|
46
|
+
indexCol,
|
|
47
|
+
// visibleColumns,
|
|
48
|
+
handleNextCell
|
|
47
49
|
// cellEditing,
|
|
48
50
|
// ...restProps
|
|
49
51
|
} = props;
|
|
@@ -61,8 +63,7 @@ const EditableCell = props => {
|
|
|
61
63
|
} = useContext(TableContext);
|
|
62
64
|
const datePickerRef = React.useRef(null);
|
|
63
65
|
const dateTimePickerRef = React.useRef(null);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
const timePickerRef = React.useRef(null);
|
|
66
67
|
const colFormat = typeof column?.format === 'function' ? column?.format(record) : column?.format;
|
|
67
68
|
const cellFormat = getFormat(colFormat, format);
|
|
68
69
|
const inputNode = (value, onChange) => {
|
|
@@ -99,7 +100,24 @@ const EditableCell = props => {
|
|
|
99
100
|
const options = validateOption ? validateOption(record, column.field) : selectOptions ?? [];
|
|
100
101
|
const optionsTree = validateOption ? convertArrayWithIndent(validateOption(record, column.field)) : selectOptions ? convertArrayWithIndent(selectOptions) : [];
|
|
101
102
|
|
|
102
|
-
// const
|
|
103
|
+
// const focusToken = (token: FormatToken, fmt: string) => {
|
|
104
|
+
// const input: HTMLInputElement | null =
|
|
105
|
+
// timePickerRef.current?.nativeElement?.querySelector('input') ??
|
|
106
|
+
// timePickerRef.current?.input;
|
|
107
|
+
|
|
108
|
+
// if (!input) return;
|
|
109
|
+
|
|
110
|
+
// const start = fmt.indexOf(token);
|
|
111
|
+
// if (start === -1) return;
|
|
112
|
+
|
|
113
|
+
// input.focus();
|
|
114
|
+
|
|
115
|
+
// input.setSelectionRange(start, start + token.length - 1);
|
|
116
|
+
|
|
117
|
+
// requestAnimationFrame(() => {
|
|
118
|
+
// input.setSelectionRange(start, start + token.length);
|
|
119
|
+
// });
|
|
120
|
+
// };
|
|
103
121
|
|
|
104
122
|
switch (editType) {
|
|
105
123
|
case 'date':
|
|
@@ -324,6 +342,7 @@ const EditableCell = props => {
|
|
|
324
342
|
const maxTime = maxTimeValue ? dayjs(maxTimeValue, timeFormat) : undefined;
|
|
325
343
|
const minTime = minTimeValue ? dayjs(minTimeValue, timeFormat) : undefined;
|
|
326
344
|
return /*#__PURE__*/React.createElement(TimePicker, {
|
|
345
|
+
ref: timePickerRef,
|
|
327
346
|
format: {
|
|
328
347
|
format: timeFormat,
|
|
329
348
|
type: 'mask'
|
|
@@ -344,8 +363,79 @@ const EditableCell = props => {
|
|
|
344
363
|
"data-tooltip-content": message,
|
|
345
364
|
"data-tooltip-id": `${id}-tooltip-error`,
|
|
346
365
|
autoFocus: column.field === startCell?.colId,
|
|
347
|
-
defaultOpen: column.field === startCell?.colId
|
|
348
|
-
|
|
366
|
+
defaultOpen: column.field === startCell?.colId
|
|
367
|
+
|
|
368
|
+
// onChange={(newDate, dateString) => {
|
|
369
|
+
|
|
370
|
+
// if (typeTime === 'time') {
|
|
371
|
+
|
|
372
|
+
// onChange(dateString)
|
|
373
|
+
|
|
374
|
+
// } else {
|
|
375
|
+
|
|
376
|
+
// // const datetime = dayjs(dateString as string, timeFormat, true);
|
|
377
|
+
|
|
378
|
+
// const newVal = newDate ? moment(newDate.toDate()).format() : undefined
|
|
379
|
+
|
|
380
|
+
// // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
|
|
381
|
+
// onChange(newVal)
|
|
382
|
+
|
|
383
|
+
// }
|
|
384
|
+
|
|
385
|
+
// setTimeout(() => {
|
|
386
|
+
// // @ts-ignore
|
|
387
|
+
// dateTimePickerRef.current?.focus()
|
|
388
|
+
// }, 0)
|
|
389
|
+
|
|
390
|
+
// }}
|
|
391
|
+
|
|
392
|
+
// onBlur={() => {
|
|
393
|
+
// const formState = getValues()
|
|
394
|
+
// const itemState = getValues(dataIndex)
|
|
395
|
+
// // @ts-ignore
|
|
396
|
+
// const prevState = record[dataIndex]
|
|
397
|
+
// const newState = itemState
|
|
398
|
+
|
|
399
|
+
// let newValue = newState
|
|
400
|
+
|
|
401
|
+
// if (typeTime === 'time') {
|
|
402
|
+
|
|
403
|
+
// newValue = newState
|
|
404
|
+
|
|
405
|
+
// } else {
|
|
406
|
+
|
|
407
|
+
// const datetime = dayjs(newState as string, timeFormat, true);
|
|
408
|
+
|
|
409
|
+
// const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : undefined
|
|
410
|
+
// onChange(newVal)
|
|
411
|
+
|
|
412
|
+
// newValue = newVal
|
|
413
|
+
|
|
414
|
+
// }
|
|
415
|
+
|
|
416
|
+
// if (prevState !== newState) {
|
|
417
|
+
// handleCellChange?.({
|
|
418
|
+
// key: key as any,
|
|
419
|
+
// field: column.field ?? column.field as any,
|
|
420
|
+
// record: formState,
|
|
421
|
+
// prevState,
|
|
422
|
+
// newState: newValue,
|
|
423
|
+
// option: newValue,
|
|
424
|
+
// indexCol,
|
|
425
|
+
// indexRow,
|
|
426
|
+
// type: 'blur'
|
|
427
|
+
// })
|
|
428
|
+
// }
|
|
429
|
+
// }}
|
|
430
|
+
|
|
431
|
+
// needConfirm={false}
|
|
432
|
+
,
|
|
433
|
+
|
|
434
|
+
onCalendarChange: (newDate, dateString) => {
|
|
435
|
+
// const newDateValue = dateString ? moment(convertDayjsToDate(dateString as string, dateFormat)).format() : null
|
|
436
|
+
|
|
437
|
+
// onChange(newDateValue)
|
|
438
|
+
|
|
349
439
|
if (typeTime === 'time') {
|
|
350
440
|
onChange(dateString);
|
|
351
441
|
} else {
|
|
@@ -358,38 +448,34 @@ const EditableCell = props => {
|
|
|
358
448
|
}
|
|
359
449
|
setTimeout(() => {
|
|
360
450
|
// @ts-ignore
|
|
361
|
-
|
|
362
|
-
}
|
|
451
|
+
timePickerRef.current?.focus();
|
|
452
|
+
});
|
|
363
453
|
},
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
454
|
+
onOpenChange: open => {
|
|
455
|
+
if (!open) {
|
|
456
|
+
const formState = getValues();
|
|
457
|
+
const itemState = getValues(dataIndex);
|
|
458
|
+
// @ts-ignore
|
|
459
|
+
const prevState = record[dataIndex];
|
|
460
|
+
const newState = itemState;
|
|
461
|
+
if (prevState !== newState) {
|
|
462
|
+
handleCellChange?.({
|
|
463
|
+
key: key,
|
|
464
|
+
field: column.field ?? column.field,
|
|
465
|
+
record: formState,
|
|
466
|
+
prevState,
|
|
467
|
+
newState,
|
|
468
|
+
option: newState,
|
|
469
|
+
indexCol,
|
|
470
|
+
indexRow,
|
|
471
|
+
type: 'blur'
|
|
472
|
+
});
|
|
473
|
+
}
|
|
379
474
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
field: column.field ?? column.field,
|
|
385
|
-
record: formState,
|
|
386
|
-
prevState,
|
|
387
|
-
newState: newValue,
|
|
388
|
-
option: newValue,
|
|
389
|
-
indexCol,
|
|
390
|
-
indexRow,
|
|
391
|
-
type: 'blur'
|
|
392
|
-
});
|
|
475
|
+
},
|
|
476
|
+
onKeyDown: e => {
|
|
477
|
+
if (e?.code === "Tab") {
|
|
478
|
+
handleNextCell?.();
|
|
393
479
|
}
|
|
394
480
|
}
|
|
395
481
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Space from "rc-master-ui/es/space";
|
|
2
2
|
import Command from "../components/command/Command";
|
|
3
|
-
import { addRowsDown, addRowsDownWithCtrl, addRowsUp, addRowsUpWithCtrl, findFirst, flattenArray, flattenData, getColIdsBetween, getCommonPinningStyles, getEditType, getFormat, getRowIdsBetween, getSelectedCellMatrix, isEditable, isObjEmpty, isObjEqual, newGuid, unFlattenData, updateOrInsert } from "../hook/utils";
|
|
3
|
+
import { addRowsDown, addRowsDownWithCtrl, addRowsUp, addRowsUpWithCtrl, findFirst, flattenArray, flattenData, getColIdsBetween, getCommonPinningStyles, getEditType, getFormat, getNextEditableColumn, getRowIdsBetween, getSelectedCellMatrix, isEditable, isObjEmpty, isObjEqual, newGuid, unFlattenData, updateOrInsert } from "../hook/utils";
|
|
4
4
|
import Checkbox from "rc-master-ui/es/checkbox/Checkbox";
|
|
5
5
|
import classNames from "classnames";
|
|
6
6
|
import React from "react";
|
|
@@ -232,6 +232,7 @@ const TableBodyCellEdit = props => {
|
|
|
232
232
|
format
|
|
233
233
|
} = React.useContext(TableContext);
|
|
234
234
|
const expandIconColumnIndex = expandable?.expandIconColumnIndex;
|
|
235
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
235
236
|
const record = cell.row.original;
|
|
236
237
|
const columnMeta = cell.column.columnDef.meta ?? {};
|
|
237
238
|
const [isOpenTooltip, setIsOpenTooltip] = React.useState(false);
|
|
@@ -309,7 +310,9 @@ const TableBodyCellEdit = props => {
|
|
|
309
310
|
}
|
|
310
311
|
}, [cell, columnMeta, isOpenTooltip, record, valueCellString]);
|
|
311
312
|
const triggerDragPaste = (pasteState, ctrlKey) => {
|
|
312
|
-
const tmpCols =
|
|
313
|
+
const tmpCols = {
|
|
314
|
+
...visibleColumns
|
|
315
|
+
};
|
|
313
316
|
const rowPasteIds = getRowIdsBetween(table, startPasteCell?.rowId ?? '', endPasteCell?.rowId ?? '');
|
|
314
317
|
const colPasteds = getColIdsBetween(table, startPasteCell?.colId ?? '', endPasteCell?.colId ?? '');
|
|
315
318
|
const rowSelectIds = getRowIdsBetween(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
|
|
@@ -383,7 +386,9 @@ const TableBodyCellEdit = props => {
|
|
|
383
386
|
setRangePasteState?.(undefined);
|
|
384
387
|
};
|
|
385
388
|
const triggerPointPaste = (pasteState, cellStart, cellEnd, ctrlKey) => {
|
|
386
|
-
const tmpCols =
|
|
389
|
+
const tmpCols = {
|
|
390
|
+
...visibleColumns
|
|
391
|
+
};
|
|
387
392
|
const rowPasteIds = getRowIdsBetween(table, cellStart?.rowId ?? '', cellEnd?.rowId ?? '');
|
|
388
393
|
const colPasteds = getColIdsBetween(table, cellStart?.colId ?? '', cellEnd?.colId ?? '');
|
|
389
394
|
const rowSelectIds = getRowIdsBetween(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
|
|
@@ -584,7 +589,9 @@ const TableBodyCellEdit = props => {
|
|
|
584
589
|
function handleKeyDown(e, rowId, colId) {
|
|
585
590
|
if (e.key === 'Tab') {
|
|
586
591
|
e.preventDefault();
|
|
587
|
-
const allCols =
|
|
592
|
+
const allCols = {
|
|
593
|
+
...visibleColumns
|
|
594
|
+
};
|
|
588
595
|
const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
|
|
589
596
|
const nextCol = allCols[currentColIndex + 1];
|
|
590
597
|
if (nextCol) {
|
|
@@ -648,7 +655,7 @@ const TableBodyCellEdit = props => {
|
|
|
648
655
|
if (e.key === 'ArrowRight') {
|
|
649
656
|
e.preventDefault();
|
|
650
657
|
e.stopPropagation();
|
|
651
|
-
const allCols =
|
|
658
|
+
const allCols = visibleColumns.filter(it => !nonActionColumn.includes(it.id));
|
|
652
659
|
const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
|
|
653
660
|
const nextCol = allCols[currentColIndex + 1];
|
|
654
661
|
if (nextCol) {
|
|
@@ -679,7 +686,7 @@ const TableBodyCellEdit = props => {
|
|
|
679
686
|
}
|
|
680
687
|
if (e.key === 'ArrowLeft') {
|
|
681
688
|
e.preventDefault();
|
|
682
|
-
const allCols =
|
|
689
|
+
const allCols = visibleColumns.filter(it => !nonActionColumn.includes(it.id));
|
|
683
690
|
|
|
684
691
|
// const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
|
|
685
692
|
const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
|
|
@@ -827,7 +834,7 @@ const TableBodyCellEdit = props => {
|
|
|
827
834
|
}
|
|
828
835
|
const handleMouseDownIndex = rowId => {
|
|
829
836
|
setIsSelecting?.(true);
|
|
830
|
-
const allColumns =
|
|
837
|
+
const allColumns = visibleColumns.filter(it => !nonActionColumn.includes(it.id));
|
|
831
838
|
const firstCOlSpin = findFirst(allColumns);
|
|
832
839
|
const startCol = allColumns[0].id;
|
|
833
840
|
const endCol = allColumns[allColumns.length - 1].id;
|
|
@@ -861,7 +868,7 @@ const TableBodyCellEdit = props => {
|
|
|
861
868
|
};
|
|
862
869
|
const handleMouseEnterIndex = rowId => {
|
|
863
870
|
if (isSelecting) {
|
|
864
|
-
const allColumns =
|
|
871
|
+
const allColumns = visibleColumns.filter(it => !nonActionColumn.includes(it.id));
|
|
865
872
|
|
|
866
873
|
// const firstCOl = findFirst(allColumns)
|
|
867
874
|
|
|
@@ -1111,6 +1118,58 @@ const TableBodyCellEdit = props => {
|
|
|
1111
1118
|
}, 100);
|
|
1112
1119
|
}
|
|
1113
1120
|
};
|
|
1121
|
+
const handleNextCell = () => {
|
|
1122
|
+
const allCols = visibleColumns;
|
|
1123
|
+
|
|
1124
|
+
// const colId = cell.column.id
|
|
1125
|
+
const rowId = cell.row.id;
|
|
1126
|
+
|
|
1127
|
+
// const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
|
|
1128
|
+
// const currentColIndex = indexCol;
|
|
1129
|
+
|
|
1130
|
+
const isNextCol = allCols[colIndex + 1];
|
|
1131
|
+
const nextCol = getNextEditableColumn(visibleColumns, colIndex, record);
|
|
1132
|
+
if (isNextCol && nextCol) {
|
|
1133
|
+
setFocusedCell?.({
|
|
1134
|
+
rowId,
|
|
1135
|
+
colId: nextCol.id
|
|
1136
|
+
});
|
|
1137
|
+
setStartCell?.({
|
|
1138
|
+
rowId,
|
|
1139
|
+
colId: nextCol.id
|
|
1140
|
+
});
|
|
1141
|
+
setEndCell?.({
|
|
1142
|
+
rowId,
|
|
1143
|
+
colId: nextCol.id
|
|
1144
|
+
});
|
|
1145
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
1146
|
+
rowId,
|
|
1147
|
+
colId: nextCol.id
|
|
1148
|
+
}, {
|
|
1149
|
+
rowId,
|
|
1150
|
+
colId: nextCol.id
|
|
1151
|
+
}));
|
|
1152
|
+
columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
|
|
1153
|
+
align: 'center'
|
|
1154
|
+
});
|
|
1155
|
+
const nextItem = document.querySelector(`.ui-rc-grid-row .cell-editing[data-row-key="${rowId}"].cell-editing[data-col-key="${nextCol.id}"] input`);
|
|
1156
|
+
|
|
1157
|
+
// const input = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${startSelectedCells.current.row}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] input`) as HTMLInputElement
|
|
1158
|
+
// const textarea = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowNumber}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] textarea`) as any
|
|
1159
|
+
|
|
1160
|
+
const textarea = document.querySelector(`.ui-rc-grid-row .cell-editing[data-row-key="${rowId}"].cell-editing[data-col-key="${nextCol.id}"] textarea`);
|
|
1161
|
+
setTimeout(() => {
|
|
1162
|
+
if (textarea) {
|
|
1163
|
+
textarea.focus();
|
|
1164
|
+
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
if (nextItem) {
|
|
1168
|
+
nextItem.focus();
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1114
1173
|
const cellValue = cell.getValue();
|
|
1115
1174
|
const rowIndex = cell.row.index;
|
|
1116
1175
|
const colFormat = typeof columnMeta?.format === 'function' ? columnMeta?.format(record) : columnMeta?.format;
|
|
@@ -1246,7 +1305,9 @@ const TableBodyCellEdit = props => {
|
|
|
1246
1305
|
editType: getEditType(cell.column.columnDef.meta, record),
|
|
1247
1306
|
indexCol: cell.column.getIndex(),
|
|
1248
1307
|
indexRow: cell.row.index,
|
|
1249
|
-
record: record
|
|
1308
|
+
record: record,
|
|
1309
|
+
visibleColumns: visibleColumns,
|
|
1310
|
+
handleNextCell: handleNextCell
|
|
1250
1311
|
// rowKey={rowKey}
|
|
1251
1312
|
}) : /*#__PURE__*/React.createElement("div", {
|
|
1252
1313
|
className: classNames('ui-rc_cell-content', {
|
|
@@ -38,9 +38,10 @@ export const renderValueCell = (column, value, record, rowIndex, colIndex, forma
|
|
|
38
38
|
case 'date':
|
|
39
39
|
return value ? dayjs(value).format(format?.dateFormat ?? 'DD/MM/YYYY') : '';
|
|
40
40
|
case 'time':
|
|
41
|
-
const timeFormat = format?.timeFormat
|
|
41
|
+
const timeFormat = format?.timeFormat;
|
|
42
|
+
console.log('timeFormat', timeFormat);
|
|
42
43
|
const abc = convertToDate(value, timeFormat);
|
|
43
|
-
const timeValue = value ? dayjs(abc).format(timeFormat) : '';
|
|
44
|
+
const timeValue = value ? dayjs(abc).format(timeFormat ?? 'HH:mm') : '';
|
|
44
45
|
return timeValue ?? '';
|
|
45
46
|
case 'year':
|
|
46
47
|
const year = value ? moment(value).format('yyyy') : '';
|
|
@@ -81,6 +81,7 @@ export declare function sortData(data: any[], sorter: Sorter[]): any[];
|
|
|
81
81
|
export declare function filterDataByColumns(data: any[], queries: FilterItem[] | undefined, sorter: Sorter[] | undefined, keysFilter: string[] | undefined, ignoreAccents?: boolean): any[];
|
|
82
82
|
export declare const getAllRowKey: (data: any[]) => any[];
|
|
83
83
|
export declare const isEditable: <RecordType>(column: ColumnTable, rowData: RecordType) => boolean | ((rowData: any) => boolean);
|
|
84
|
+
export declare const getNextEditableColumn: (columns: any[], currentIndex: number, rowData: any) => any;
|
|
84
85
|
export declare const checkFieldKey: (key: string | undefined) => string;
|
|
85
86
|
export declare const convertArrayWithIndent: (inputArray: any[], parentIndent?: number) => any[];
|
|
86
87
|
export declare const convertLabelToTitle: (data: any[]) => any[];
|
|
@@ -167,3 +168,5 @@ export declare const removeColumns: <RecordType>(columns: ColumnTable<RecordType
|
|
|
167
168
|
export declare function sumFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
|
|
168
169
|
export declare function sumNumberFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
|
|
169
170
|
export declare const getTreeDepth: (rows: any[]) => number;
|
|
171
|
+
export type FormatToken = 'YYYY' | 'MM' | 'DD' | 'HH' | 'mm' | 'ss';
|
|
172
|
+
export declare const isDateChanged: (oldDate: string | Date, newDate: string | Date, format: string) => FormatToken | null;
|