E - the bean type@Tag(value="vaadin-crud")
@NpmPackage(value="@vaadin/vaadin-crud",
version="1.1.0")
@JsModule(value="@vaadin/vaadin-crud/src/vaadin-crud.js") @JsModule(value="@vaadin/vaadin-crud/src/vaadin-crud-edit-column.js")
@HtmlImport(value="frontend://bower_components/vaadin-crud/src/vaadin-crud.html") @HtmlImport(value="frontend://bower_components/vaadin-crud/src/vaadin-crud-edit-column.html")
public class Crud<E>
extends com.vaadin.flow.component.Component
implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasTheme
Basic usage
Crud<Person> crud = new Crud<>(Person.class, personEditor);
crud.setDataProvider(personDataProvider);
// Handle save and delete events.
crud.addSaveListener(e -> save(e.getItem()));
crud.addDeleteListener(e -> delete(e.getItem()));
| Modifier and Type | Class and Description |
|---|---|
static class |
Crud.CancelEvent<E>
Event fired when the user cancels the creation of a new item
or modifications to an existing item.
|
static class |
Crud.DeleteEvent<E>
Event fired when the user tries to delete an existing item.
|
static class |
Crud.EditEvent<E>
Event fired when the user starts to edit an existing item.
|
static class |
Crud.EditMode
Determines whether an item presented for editing is to be treated
as a new item or an existing item.
|
static class |
Crud.NewEvent<E>
Event fired when the user starts to create a new item.
|
static class |
Crud.SaveEvent<E>
Event fired when the user tries to save a new item or modifications to an existing item.
|
| Constructor and Description |
|---|
Crud()
Instantiates a new Crud with no grid, editor and runtime bean type information.
|
Crud(Class<E> beanType,
CrudEditor<E> editor)
Instantiates a new Crud for the given bean type and uses the supplied editor.
|
Crud(Class<E> beanType,
com.vaadin.flow.component.grid.Grid<E> grid,
CrudEditor<E> editor)
Instantiates a new Crud using a custom grid.
|
| Modifier and Type | Method and Description |
|---|---|
com.vaadin.flow.shared.Registration |
addCancelListener(com.vaadin.flow.component.ComponentEventListener<Crud.CancelEvent<E>> listener)
Registers a listener to be notified when the user cancels a new item creation or existing item
modification in progress.
|
com.vaadin.flow.shared.Registration |
addDeleteListener(com.vaadin.flow.component.ComponentEventListener<Crud.DeleteEvent<E>> listener)
Registers a listener to be notified when the user tries to delete an existing item.
|
static void |
addEditColumn(com.vaadin.flow.component.grid.Grid grid)
A helper method to add an edit column to a grid.
|
static void |
addEditColumn(com.vaadin.flow.component.grid.Grid grid,
CrudI18n crudI18n)
A helper method to add an edit column to a grid.
|
com.vaadin.flow.shared.Registration |
addEditListener(com.vaadin.flow.component.ComponentEventListener<Crud.EditEvent<E>> listener)
Registers a listener to be notified when the user starts to edit an existing item.
|
com.vaadin.flow.shared.Registration |
addNewListener(com.vaadin.flow.component.ComponentEventListener<Crud.NewEvent<E>> listener)
Registers a listener to be notified when the user starts to create a new item.
|
com.vaadin.flow.shared.Registration |
addSaveListener(com.vaadin.flow.component.ComponentEventListener<Crud.SaveEvent<E>> listener)
Registers a listener to be notified when the user tries to save a new item
or modifications to an existing item.
|
void |
addThemeVariants(CrudVariant... variants)
Adds theme variants to the component.
|
void |
edit(E item,
Crud.EditMode editMode)
Initiates an item edit from the server-side.
|
Class<E> |
getBeanType()
Gets the runtime bean type information
|
com.vaadin.flow.data.provider.DataProvider<E,?> |
getDataProvider()
Gets the data provider supplying the grid data.
|
CrudEditor<E> |
getEditor()
Gets the crud editor.
|
CrudEditorPosition |
getEditorPosition()
Gets the current editor position on the desktop screen.
|
com.vaadin.flow.component.grid.Grid<E> |
getGrid()
Gets the grid
|
static boolean |
hasEditColumn(com.vaadin.flow.component.grid.Grid grid)
Checks if an edit column has been added to the Grid using
Crud.addEditColumn(Grid) |
boolean |
isEditOnClick()
Gets whether click on row to edit item is enabled or not.
|
static void |
removeEditColumn(com.vaadin.flow.component.grid.Grid grid)
Removes the crud edit column from a grid
|
void |
removeThemeVariants(CrudVariant... variants)
Removes theme variants from the component.
|
void |
setBeanType(Class<E> beanType)
Sets the runtime bean type information.
|
void |
setDataProvider(com.vaadin.flow.data.provider.DataProvider<E,?> provider)
Sets the data provider for the grid.
|
void |
setDirty(boolean dirty)
Set the dirty state of the Crud.
|
void |
setEditOnClick(boolean editOnClick)
Sets the option to open item to edit by row click.
|
void |
setEditor(CrudEditor<E> editor)
Sets the editor.
|
void |
setEditorPosition(CrudEditorPosition editorPosition)
Sets how editor will be presented on desktop screen.
|
void |
setGrid(com.vaadin.flow.component.grid.Grid<E> grid)
Sets the grid
|
void |
setI18n(CrudI18n i18n)
Sets the internationalized messages to be used by this crud instance.
|
void |
setOpened(boolean opened)
Opens or closes the editor.
|
void |
setToolbar(com.vaadin.flow.component.Component... components)
Sets the content of the toolbar.
|
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisibleclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetHeight, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, setHeight, setHeightFull, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFullpublic Crud(Class<E> beanType, com.vaadin.flow.component.grid.Grid<E> grid, CrudEditor<E> editor)
beanType - the class of itemsgrid - the grid with which the items listing should be displayededitor - the editor for manipulating individual itemsCrud(Class, CrudEditor)public Crud(Class<E> beanType, CrudEditor<E> editor)
beanType - the class of itemseditor - the editor for manipulating individual itemsCrudGrid,
Crud(Class, Grid, CrudEditor)public Crud()
Example:
@Id
Crud<Person> crud;
@Id
private TextField firstName;
@Id
private TextField lastName;
@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
Binder<Person> binder = new Binder<>(Person.class);
binder.bind(firstName, Person::getFirstName, Person::setFirstName);
binder.bind(lastName, Person::getLastName, Person::setLastName);
crud.setEditor(new BinderCrudEditor<>(binder));
crud.setBeanType(Person.class);
crud.setDataProvider(new PersonCrudDataProvider());
}
setEditor(CrudEditor),
setBeanType(Class)public void edit(E item, Crud.EditMode editMode)
item - the item to be editededitMode - the edit modepublic void setOpened(boolean opened)
opened - true to open or false to closepublic void setDirty(boolean dirty)
dirty - true if dirty and false if otherwise.public Class<E> getBeanType()
public void setBeanType(Class<E> beanType)
Crud with @Id this method must be called
before the crud is put into use.beanType - the bean typepublic com.vaadin.flow.component.grid.Grid<E> getGrid()
public void setGrid(com.vaadin.flow.component.grid.Grid<E> grid)
grid - the gridpublic CrudEditor<E> getEditor()
public void setEditor(CrudEditor<E> editor)
Crud with @Id this method must be called
before the crud is put into use.editor - the editorpublic void setEditorPosition(CrudEditorPosition editorPosition)
The default position is CrudEditorPosition.OVERLAY.
editorPosition - the editor position, never
nullCrudEditorPositionpublic CrudEditorPosition getEditorPosition()
The default position is CrudEditorPosition.OVERLAY.
public void setEditOnClick(boolean editOnClick)
If enabled, it removes the edit column created by CrudGrid.
editOnClick - true to enable it (false, by default).public boolean isEditOnClick()
false otherwisepublic void setToolbar(com.vaadin.flow.component.Component... components)
components - the content to be setpublic void setI18n(CrudI18n i18n)
i18n - the internationalized messagesCrudI18n.createDefault()public void addThemeVariants(CrudVariant... variants)
variants - theme variants to addpublic void removeThemeVariants(CrudVariant... variants)
variants - theme variants to removepublic com.vaadin.flow.shared.Registration addNewListener(com.vaadin.flow.component.ComponentEventListener<Crud.NewEvent<E>> listener)
listener - a listener to be notifiedpublic com.vaadin.flow.shared.Registration addEditListener(com.vaadin.flow.component.ComponentEventListener<Crud.EditEvent<E>> listener)
listener - a listener to be notifiedpublic com.vaadin.flow.shared.Registration addSaveListener(com.vaadin.flow.component.ComponentEventListener<Crud.SaveEvent<E>> listener)
listener - a listener to be notifiedpublic com.vaadin.flow.shared.Registration addCancelListener(com.vaadin.flow.component.ComponentEventListener<Crud.CancelEvent<E>> listener)
listener - a listener to be notifiedpublic com.vaadin.flow.shared.Registration addDeleteListener(com.vaadin.flow.component.ComponentEventListener<Crud.DeleteEvent<E>> listener)
listener - a listener to be notifiedpublic com.vaadin.flow.data.provider.DataProvider<E,?> getDataProvider()
public void setDataProvider(com.vaadin.flow.data.provider.DataProvider<E,?> provider)
provider - the data provider for the gridpublic static void addEditColumn(com.vaadin.flow.component.grid.Grid grid)
grid - the grid in which to add the edit columnaddEditColumn(Grid, CrudI18n),
removeEditColumn(Grid),
hasEditColumn(Grid)public static void addEditColumn(com.vaadin.flow.component.grid.Grid grid,
CrudI18n crudI18n)
grid - the grid in which to add the edit columncrudI18n - the i18n object for localizing the accessibility of the edit columnpublic static void removeEditColumn(com.vaadin.flow.component.grid.Grid grid)
grid - the grid from which to remove the edit columnaddEditColumn(Grid),
hasEditColumn(Grid)public static boolean hasEditColumn(com.vaadin.flow.component.grid.Grid grid)
Crud.addEditColumn(Grid)grid - the grid to checkaddEditColumn(Grid)Copyright © 2018–2019 Vaadin Ltd. All rights reserved.