mirror of
https://github.com/t8y2/dbx.git
synced 2026-11-01 00:25:38 +00:00
feat(grid): add Clone Row to row context menu (closes #227)
Copy the selected row as a new row with primary key columns set to null so auto-increment values are generated on save.
This commit is contained in:
@@ -365,6 +365,25 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
});
|
||||
}
|
||||
|
||||
function cloneRow(rowId: number) {
|
||||
const item = getRowItem(rowId);
|
||||
if (!item) return;
|
||||
const primaryKeys = tableMeta.value?.primaryKeys ?? [];
|
||||
const columns = result.value.columns;
|
||||
const clonedData = item.data.map((val, i) => (primaryKeys.includes(columns[i]) ? null : val));
|
||||
rowStatusFilter.value = rowStatusFilterAfterAddingRow(rowStatusFilter.value);
|
||||
newRows.value.push(clonedData);
|
||||
if (useTransaction.value && !transactionActive.value) {
|
||||
enterTransaction();
|
||||
}
|
||||
const newRowId = -newRows.value.length;
|
||||
nextTick(() => {
|
||||
const el = getScrollerElement();
|
||||
if (el) el.scrollTop = el.scrollHeight;
|
||||
startEdit(newRowId, initialEditColumn?.value ?? 0);
|
||||
});
|
||||
}
|
||||
|
||||
function applyDeleteRow(rowId: number) {
|
||||
const item = getRowItem(rowId);
|
||||
if (!item) return;
|
||||
@@ -622,6 +641,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
cancelEdit,
|
||||
onEditKeydown,
|
||||
addRow,
|
||||
cloneRow,
|
||||
applyDeleteRow,
|
||||
showDeleteRowConfirm,
|
||||
pendingDeleteRowId,
|
||||
|
||||
Reference in New Issue
Block a user