Directory

← Back

Grid Helpers Add-on

Several grid recipes for Vaadin 23+ (and 22), ready to use

Author

Contributors

Rating

Several grid recipes for Vaadin 23+ (and 22), ready to use. DOES NOT require extending Grid.

Features

  • Remove multiselect selection column
  • Freeze a grid's selection (checkbox) column
  • Create Grid with conditional selection (with the following limitations: #11, #12)
  • Select Grid rows automatically using up/down arrow keys
  • Show a Vaadin Grid with compact row styling
  • Show a meaningful message instead of an empty Grid
  • Show a menu to toggle the visibility of grid columns

Sample code

    Grid<Person> grid = new Grid<>();
    grid.setItems(TestData.initializeData());

    grid.setSelectionMode(SelectionMode.MULTI);

    grid.addColumn(Person::getFirstName).setHeader("First name");
    grid.addColumn(Person::getLastName).setHeader("Last name");
    grid.addColumn(Person::getTitle).setHeader("Title");
    grid.addColumn(Person::getCountry).setHeader("Country");
    grid.addColumn(Person::getCity).setHeader("City");
    grid.addColumn(Person::getStreetAddress).setHeader("Street Address");
    grid.addColumn(Person::getPhoneNumber).setHeader("Phone Number");
    grid.getColumns().forEach(c -> c.setAutoWidth(true));

    GridHelper.setSelectionColumnFrozen(grid, true);
    Grid<Person> grid = new Grid<>();
    grid.setItems(TestData.initializeData());

    grid.setSelectionMode(SelectionMode.MULTI);

    grid.addColumn(Person::getFirstName).setHeader("First name");
    grid.addColumn(Person::getLastName).setHeader("Last name");
    grid.addColumn(Person::getCountry).setHeader("Country");

    GridHelper.setSelectionColumnHidden(grid, true);
    Grid<Person> grid = new Grid<>();
    grid.setItems(TestData.initializeData());

    grid.setSelectionMode(SelectionMode.MULTI);

    grid.addColumn(Person::getFirstName).setHeader("First name");
    grid.addColumn(Person::getLastName).setHeader("Last name");
    grid.addColumn(p -> p.isActive() ? "Yes" : "No").setHeader("Active");

    GridHelper.setSelectionFilter(grid, Person::isActive);
    Grid<Person> grid = new Grid<>();
    grid.setItems(TestData.initializeData());

    grid.setSelectionMode(SelectionMode.MULTI);

    grid.addColumn(Person::getFirstName).setHeader("First name");
    grid.addColumn(Person::getLastName).setHeader("Last name");
    grid.addColumn(Person::getCountry).setHeader("Country");

    GridHelper.setSelectOnClick(grid, true);
    Grid<Person> grid = new Grid<>();
    grid.setItems(TestData.initializeData());

    grid.setSelectionMode(SelectionMode.SINGLE);

    grid.addColumn(Person::getFirstName).setHeader("First name");
    grid.addColumn(Person::getLastName).setHeader("Last name");
    grid.addColumn(Person::getCountry).setHeader("Country");

    GridHelper.setArrowSelectionEnabled(grid, true);
    Grid<Person> grid = new Grid<>();
    grid.setItems(TestData.initializeData());

    grid.setSelectionMode(SelectionMode.SINGLE);

    grid.addColumn(Person::getFirstName).setHeader("First name");
    grid.addColumn(Person::getLastName).setHeader("Last name");
    grid.addColumn(Person::getCountry).setHeader("Country");

    grid.addThemeName(GridHelper.DENSE_THEME);
    Grid<Person> grid = new Grid<>();
    grid.setItems(TestData.initializeData());

    Column<Person> firstNameColumn = grid.addColumn(Person::getFirstName).setHeader("First name");
    Column<Person> lastNameColumn = grid.addColumn(Person::getLastName).setHeader("Last name");
    Column<Person> countryColumn = grid.addColumn(Person::getCountry).setHeader("Country");

    GridHelper.setHidingToggleCaption(firstNameColumn, "First name");
    GridHelper.setHidingToggleCaption(lastNameColumn, "Last name");
    GridHelper.setHidingToggleCaption(countryColumn, "Country");

    GridHelper.setColumnToggleVisible(grid, isVisible());

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

New features:

  • add feature for hiding header and footers (#14)
  • add support for styling headers and footers
  • add support for heightByRows
  • add support for responsive steps
Released
2023-07-05
Maturity
TESTED
License
Apache License 2.0

Compatibility

Framework
Vaadin 23
Vaadin 24
Vaadin 22 in 0.3.5
Browser
N/A
Online