diff --git a/selection-grid-flow/src/main/java/com/vaadin/componentfactory/selectiongrid/SelectionGrid.java b/selection-grid-flow/src/main/java/com/vaadin/componentfactory/selectiongrid/SelectionGrid.java index 378bcc8..0542a8f 100644 --- a/selection-grid-flow/src/main/java/com/vaadin/componentfactory/selectiongrid/SelectionGrid.java +++ b/selection-grid-flow/src/main/java/com/vaadin/componentfactory/selectiongrid/SelectionGrid.java @@ -112,8 +112,8 @@ public void focusOnCell(T item) { */ public void focusOnCell(T item, Column column) { int index = getIndexForItem(item); - if (index > 0) { - int colIndex = (column != null) ? getColumns().indexOf(column) : 0; + if (index >= 0) { + int colIndex = (column != null) ? getColumns().indexOf(column) : 1; // delay the call of focus on cell if it's used on the same round trip (grid creation + focusCell) this.getElement().executeJs("setTimeout(function() { $0.focusOnCell($1, $2) });", getElement(), index, colIndex); } @@ -241,4 +241,4 @@ public void removeThemeVariants(SelectionGridVariant... variants) { getThemeNames().removeAll(Stream.of(variants) .map(SelectionGridVariant::getVariantName).collect(Collectors.toList())); } -} +} \ No newline at end of file diff --git a/selection-grid-flow/src/main/resources/META-INF/resources/frontend/src/selection-grid.js b/selection-grid-flow/src/main/resources/META-INF/resources/frontend/src/selection-grid.js index ca1fdd1..67dc3ab 100644 --- a/selection-grid-flow/src/main/resources/META-INF/resources/frontend/src/selection-grid.js +++ b/selection-grid-flow/src/main/resources/META-INF/resources/frontend/src/selection-grid.js @@ -20,6 +20,24 @@ customElements.whenDefined("vaadin-selection-grid").then(() => { const Grid = customElements.get("vaadin-selection-grid"); if (Grid) { + const oldOnContextMenuHandler = Grid.prototype._onContextMenu; + Grid.prototype._onContextMenu = function _onContextMenu(e) { + + const tr = e.composedPath().find((p) => p.nodeName === "TR"); + if (tr && typeof tr.index != 'undefined') { + const item = tr._item; + const index = tr.index; + if (this.selectedItems && this.selectedItems.some((i) => i.key === item.key)) { + // in case current row selected, do nothing, else + } else { + this._selectionGridSelectRow(e); + } + } + + const boundOnConextMenuHandler = oldOnContextMenuHandler.bind(this); + boundOnConextMenuHandler(e); + } + const oldClickHandler = Grid.prototype._onClick; Grid.prototype._onClick = function _click(e) { const boundOldClickHandler = oldClickHandler.bind(this);