You are viewing documentation for Vaadin Framework 8 and related products View documentation for Vaadin Framework 7 ›
Tables Within Spreadsheets · Vaadin
Vaadin Spreadsheet - Tables Within Spreadsheets
 Edit This Page

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);
sheet.registerTable(table);

// 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
    table.getPopupButton(col).addComponent(
        new Button("Hide Column", e -> { // Java 8
            sheet.setColumnHidden(c, true);
            table.getPopupButton(c).closePopup();
        }));
}

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.