Exporting PivotTable Data

PivotTableExtension is the extension of the PivotTable component that provides an API for downloading a table with aggregated data in the XLS format.

An instance of the extension should be created in the screen controller using the class constructor, for example:

@Autowired
private PivotTable pivotTable;

@Autowired
protected ObjectProvider<PivotExcelExporter> excelExporterObjectProvider;

private PivotTableExtension extension;

@Subscribe
protected void onInit(InitEvent event) {
    extension = new PivotTableExtensionImpl(pivotTable, excelExporterObjectProvider.getObject());
}
The extension works only for the following renderers types: TABLE, TABLE_BAR_CHART, HEATMAP, COL_HEATMAP, ROW_HEATMAP, and doesn’t get the color of cells.

The exportTableToXls() method allows you to download the table data as an XLS file, for example, on a button click:

private PivotTableExtension extension;

@Subscribe("exportBtn")
protected void onExportBtnClick(Button.ClickEvent event) {
    extension.exportTableToXls();
}

By default, the downloaded file name matches the localized caption of the entity in the PivotTable data container. The file name can be defined using the setFileName() method:

extension.setFileName("Tips");
The XLS format implies the limitation for 65536 table rows. If PivotTable contains more than 65536 rows, its content will be cut by the last row, and you will see the corresponding warning message.

Additionally, the PivotTableExtension provides two more ways to get the PivotTable data:

  • extension.getPivotDataJSON() - gets the JSON representation.

  • extension.getPivotData() - gets the serialized object of PivotData class.