Directory

← Back

Enhanced Grid

This component is an extended version of Grid with integrated complex filtering and other features

Author

Rating

Popularity

300+

This component is an extended version of Grid to add support to the following features:

Features

set a predicate to indicate which rows/items can be selected

EnhancedGrid#setSelectionPredicate(SerializablePredicate)

set a predicate to indicate which rows/items can be edited

EnhancedGrid#setEditablePredicate(SerializablePredicate)

check if a item is editable

EnhancedGrid#isEditable(T)

edit an item and cancel the edit

EnhancedGrid#editItem(T)
EnhancedGrid#cancelEdit()

set a flag to indicate if a cancel edit confirmation dialog should be display if user navigates away from current editing row

EnhancedGrid#setShowCancelEditDialog(boolean)

Each column can define a filter field/dialog through

EnhancedColumn#setHeader(String, HasValueAndElement)
EnhancedColumn#setHeader(Component, HasValueAndElement)

Major pieces of development of this add-on has been sponsored by multiple customers of Vaadin. Read more about Expert on Demand at: Support and Pricing

Sample code

// create grid
EnhancedGrid<Person> grid = new EnhancedGrid<>();

// set selection predicate to indicate which items can be selected
grid.setSelectionPredicate(p -> p.getAge() > 18);

// set items
grid.setItems(personService.fetchAll());

// add columns
// first name column with filtering button on header
EnhancedColumn<Person> firstNameColumn = grid.addColumn(Person::getFirstName).setHeader("First Name", new TextFilterField());
// last name column with filtering button and pre-selected filter by last name = "Allen"
grid.addColumn(Person::getLastName).setHeader("Last Name", new TextFilterField(new TextFieldFilterDto("Allen")));
// age column with renderer
NumberRenderer<Person> ageRenderer = new NumberRenderer<Person>(Person::getAge, "Age: %d");
EnhancedColumn<Person> ageColumn = grid.addColumn(ageRenderer, PersonSort.AGE).setHeader("Age", new TextFilterField());
ageColumn.setValueProvider(p -> String.valueOf(p.getAge()));

// add pre-selected descendent order for first name column
List<GridSortOrder<Person>> sortByFirstName = new GridSortOrderBuilder<Person>()
	  .thenDesc(firstNameColumn).build();
grid.sort(sortByFirstName);

// set selection mode
grid.setSelectionMode(Grid.SelectionMode.SINGLE);

// can pre-select items
grid.select(personList.get(0));
	   
// set editable predicate to indicate which items can be edited
grid.setEditablePredicate(p -> p.getAge() > 18);        

// add binder and editor for grid
Binder<Person> binder = new Binder<>(Person.class);
Editor<Person> editor = grid.getEditor();
editor.setBinder(binder);
editor.setBuffered(true);
 
// define editor components for columns
TextField firstNameField = new TextField();
binder.bind(firstNameField, Person::getFirstName, Person::setFirstName);
firstNameColumn.setEditorComponent(firstNameField);
	   
// call edit
grid.addItemDoubleClickListener(event -> {
	grid.editItem(event.getItem());
	firstNameField.focus();
});
        

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Bugfixes

  • Fix client side sorting indicator issue (#8)
Released
2021-08-03
Maturity
BETA
License
Apache License 2.0

Compatibility

Framework
Vaadin 14
Vaadin 24 in 4.0.1
Vaadin 23 in 3.2.0
Vaadin 22 in 2.0.1
Vaadin 21 in 2.0.1
Browser
Firefox
Opera
Safari
Google Chrome
iOS Browser
Android Browser

Vaadin Add-on Directory

Find open-source widgets, add-ons, themes, and integrations for your Vaadin application. Vaadin Add-on Directory
The channel for finding, promoting, and distributing Vaadin add-ons.
Online