Documentation versions (currently viewingVaadin 8)

Vaadin 8 reached End of Life on February 21, 2022. Discover how to make your Vaadin 8 app futureproof →

Tables Within Spreadsheets

A cell range in a worksheet can be configured as a table, which adds popup menu buttons in the header row of the range. The popup menus contain Vaadin components, which you can use to implement various functionalities in the table, such as sorting or filtering. Vaadin Spreadsheet does not include any implementations of such features, merely the UI elements to enable them.

Such a table is defined by a SpreadsheetTable or a SpreadsheetFilterTable added to the spreadsheet.

Creating a Table

For example, let us assume that you have a sheet with some data in a cell region. The first row of the region should contain column captions for the region.

Spreadsheet sheet = new Spreadsheet();

// Have a header row in a region of the sheet
sheet.createCell(1, 1, "First Name");
sheet.createCell(1, 2, "Last Name");
sheet.createCell(1, 3, "Born");
sheet.createCell(1, 4, "Died");

... insert the data ...

// Define the range
CellRangeAddress range =
    new CellRangeAddress(1, 7, 1, 4);

A table is created for a cell range and then registered in the spreadsheet with registerTable(); you can unregister it with unregisterTable(). The first row of the cell range should contain the table captions.

// Create a table in the range
SpreadsheetTable table = new SpreadsheetTable(sheet, range);

// Enable hiding each column in the popup
for (int col = range.getFirstColumn();
         col <= range.getLastColumn(); col++) {
    final int c = col; // For access in the lambda
        new Button("Hide Column", e -> { // Java 8
            sheet.setColumnHidden(c, true);

The popup buttons are typically used for performing operations on columns, such as sorting.

Filtering With a Table

SpreadsheetFilterTable is a spreadsheet table that allows filtering the rows in the table in the popup menus. The menu is filled with checkboxes for each unique value in the column. Deselecting the items causes hiding the respective rows in the spreadsheet.