mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 16:55:59 +00:00
datagrid: clone rows #309
This commit is contained in:
@@ -52,6 +52,16 @@
|
||||
onClick: () => getCurrentDataGrid().insertNewRow(),
|
||||
});
|
||||
|
||||
registerCommand({
|
||||
id: 'dataGrid.cloneRows',
|
||||
category: 'Data grid',
|
||||
name: 'Clone rows',
|
||||
toolbarName: 'Clone',
|
||||
keyText: 'CtrlOrCommand+Shift+C',
|
||||
testEnabled: () => getCurrentDataGrid()?.getGrider()?.editable,
|
||||
onClick: () => getCurrentDataGrid().cloneRows(),
|
||||
});
|
||||
|
||||
registerCommand({
|
||||
id: 'dataGrid.setNull',
|
||||
category: 'Data grid',
|
||||
@@ -418,16 +428,44 @@
|
||||
}
|
||||
|
||||
export async function insertNewRow() {
|
||||
if (grider.canInsert) {
|
||||
const rowIndex = grider.insertRow();
|
||||
const cell = [rowIndex, (currentCell && currentCell[1]) || 0];
|
||||
// @ts-ignore
|
||||
currentCell = cell;
|
||||
// @ts-ignore
|
||||
selectedCells = [cell];
|
||||
await tick();
|
||||
scrollIntoView(cell);
|
||||
if (!grider.canInsert) return;
|
||||
const rowIndex = grider.insertRow();
|
||||
const cell = [rowIndex, (currentCell && currentCell[1]) || 0];
|
||||
// @ts-ignore
|
||||
currentCell = cell;
|
||||
// @ts-ignore
|
||||
selectedCells = [cell];
|
||||
await tick();
|
||||
scrollIntoView(cell);
|
||||
}
|
||||
|
||||
export async function cloneRows() {
|
||||
if (!grider.canInsert) return;
|
||||
|
||||
let rowIndex = null;
|
||||
grider.beginUpdate();
|
||||
for (const index of _.sortBy(getSelectedRowIndexes(), x => x)) {
|
||||
if (_.isNumber(index)) {
|
||||
rowIndex = grider.insertRow();
|
||||
|
||||
for (const column of display.columns) {
|
||||
if (column.uniquePath.length > 1) continue;
|
||||
if (column.autoIncrement) continue;
|
||||
|
||||
grider.setCellValue(rowIndex, column.uniqueName, grider.getRowData(index)[column.uniqueName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
grider.endUpdate();
|
||||
|
||||
if (rowIndex == null) return;
|
||||
const cell = [rowIndex, (currentCell && currentCell[1]) || 0];
|
||||
// @ts-ignore
|
||||
currentCell = cell;
|
||||
// @ts-ignore
|
||||
selectedCells = [cell];
|
||||
await tick();
|
||||
scrollIntoView(cell);
|
||||
}
|
||||
|
||||
export function setFixedValue(value) {
|
||||
@@ -1171,7 +1209,20 @@
|
||||
|
||||
handleCursorMove(event);
|
||||
|
||||
if (event.shiftKey && event.keyCode != keycodes.shift && event.keyCode != keycodes.tab) {
|
||||
if (
|
||||
event.shiftKey &&
|
||||
event.keyCode != keycodes.shift &&
|
||||
event.keyCode != keycodes.tab &&
|
||||
event.keyCode != keycodes.ctrl &&
|
||||
event.keyCode != keycodes.leftWindowKey &&
|
||||
event.keyCode != keycodes.rightWindowKey &&
|
||||
!(
|
||||
(event.keyCode >= keycodes.a && event.keyCode <= keycodes.z) ||
|
||||
(event.keyCode >= keycodes.n0 && event.keyCode <= keycodes.n9) ||
|
||||
(event.keyCode >= keycodes.numPad0 && event.keyCode <= keycodes.numPad9) ||
|
||||
event.keyCode == keycodes.dash
|
||||
)
|
||||
) {
|
||||
selectedCells = getCellRange(shiftDragStartCell || currentCell, currentCell);
|
||||
}
|
||||
}
|
||||
@@ -1432,6 +1483,7 @@
|
||||
{ command: 'dataGrid.revertAllChanges', hideDisabled: true },
|
||||
{ command: 'dataGrid.deleteSelectedRows' },
|
||||
{ command: 'dataGrid.insertNewRow' },
|
||||
{ command: 'dataGrid.cloneRows' },
|
||||
{ command: 'dataGrid.setNull' },
|
||||
{ placeTag: 'edit' },
|
||||
{ divider: true },
|
||||
|
||||
@@ -56,8 +56,8 @@ export default {
|
||||
y: 89,
|
||||
z: 90,
|
||||
leftWindowKey: 91,
|
||||
rightWindowKey: 92,
|
||||
selectKey: 93,
|
||||
rightWindowKey: 93,
|
||||
// selectKey: 93,
|
||||
numPad0: 96,
|
||||
numPad1: 97,
|
||||
numPad2: 98,
|
||||
|
||||
Reference in New Issue
Block a user