3.2. Exporting PivotTable Data

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

An instance of the extension should be created in the screen controller using the class constructor (i.e., not the ComponentsFactory bean), for example:

@Inject
private PivotTable pivotTable;

private PivotTableExtension extension;

@Override
public void init(Map<String, Object> params) {
    extension = new WebPivotTableExtension(pivotTable);
}
Tip

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:

extension.exportTableToXls();

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

extension.setFileName("Orders of " + new Date());
Tip

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:

  • the JSON representation:

    extension.getPivotDataJSON();
  • the serialized object of PivotData class:

    extension.getPivotData();