Skip to content

Commit

Permalink
feat: add EditOnClick feature (#480)
Browse files Browse the repository at this point in the history
Add API to enable edit mode to Grid Pro with a single click on the cell.

Fix vaadin/vaadin-grid-pro#73
  • Loading branch information
DiegoCardoso committed Dec 3, 2020
1 parent cdbdfca commit cda6c84
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void initView() {
customEditorType();
enterNextRow();
singleCellEdit();
editOnClick();
}

private void basicGridPro() {
Expand Down Expand Up @@ -208,6 +209,36 @@ private void singleCellEdit() {
addCard("Single Cell Edit", grid);
}

private void editOnClick() {
// begin-source-example
// source-example-heading: Single Cell Edit
GridPro<Person> grid = new GridPro<>();
grid.setItems(createItems());

/*
* It is possible to discard edit mode when moving to the next cell by using grid pro method setSingleCellEdit.
*/
grid.setEditOnClick(true);

grid.addEditColumn(Person::getName)
.text((item, newValue) ->
item.setName(newValue))
.setHeader("Name (editable)");

grid.addEditColumn(Person::getEmail)
.text((item, newValue) ->
item.setEmail(newValue))
.setHeader("Email (editable)");

grid.addEditColumn(Person::isSubscriber)
.checkbox((item, newValue) ->
item.setSubscriber(newValue))
.setHeader("Subscriber (editable)");
// end-source-example

addCard("Edit on Click", grid);
}

private static List<Person> createItems() {
Random random = new Random(0);
return IntStream.range(1, 500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import elemental.json.JsonObject;

@Tag("vaadin-grid-pro")
@NpmPackage(value = "@vaadin/vaadin-grid-pro", version = "2.2.2")
@NpmPackage(value = "@vaadin/vaadin-grid-pro", version = "2.3.0-alpha1")
@JsModule("@vaadin/vaadin-grid-pro/src/vaadin-grid-pro.js")
@JsModule("@vaadin/vaadin-grid-pro/src/vaadin-grid-pro-edit-column.js")
@JsModule("./gridProConnector.js")
Expand Down Expand Up @@ -400,6 +400,31 @@ public boolean getSingleCellEdit() {
return getElement().getProperty("singleCellEdit", false);
}

/**
* Sets the value of the webcomponent's property editOnClick. Default values is false.
* When true, cell edit mode gets activated on a single click instead of the default
* double click.
*
* @param editOnClick
* when <code>true</code>, cell edit mode gets activated on a single
* click instead of the default double click
*/
public void setEditOnClick(boolean editOnClick) {
getElement().setProperty("editOnClick", editOnClick);
}

/**
* Gets the value of the webcomponent's property editOnClick. Default values is false.
* When true, cell edit mode gets activated on a single click instead of the default
* double click.
*
* @return editOnClick value
*/
@Synchronize("edit-on-click-changed")
public boolean getEditOnClick() {
return getElement().getProperty("editOnClick", false);
}

/**
* Creates a new edit column instance for this {@link GridPro} instance.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ public void setEnterNextRow_getEnterNextRow() {
@Test
public void setSingleCellEdit_getSingleCellEdit() {
grid.setSingleCellEdit(true);
Assert.assertEquals(grid.getSingleCellEdit(), true);
Assert.assertTrue(grid.getSingleCellEdit());
}

@Test
public void setEditOnClick_getEditOnClick() {
grid.setEditOnClick(true);
Assert.assertTrue(grid.getEditOnClick());
}

@Test
Expand Down

0 comments on commit cda6c84

Please sign in to comment.