Export Actions

ExportAction

ExportAction is a base list action designed for exporting data grid contents using a specified exporter. An instance of DataGridExporter is required for this action.

This action can be configured for use with both dataGrid and treeDataGrid components.

Within ExportAction, there are methods available for managing functions that extract values from DataGrid columns:

  • addColumnValueProvider() adds a function to retrieve values from a column.

  • removeColumnValueProvider() removes a column value provider function by column id.

Export Modes

ExportAction has three export modes: all rows, the current page, and selected rows.

export action
  • The All rows option exports all database records matching the applied filter and the initial query used to populate the view’s data.

    Data loading and export happen in batches to optimize performance and manage memory usage. The batch size is configurable via the jmix.gridexport.export-all-batch-size application property. The default batch size is 1000.

    When exporting all records, the default pagination strategy is keyset. To change this, use the jmix.gridexport.export-all-pagination-strategy application property.

  • The Current page option exports only the content displayed on the current page of the data grid.

  • The Selected rows option export only records selected in the data grid.

The set of export options can be defined by a particular action using its setAvailableExportModes() method and corresponding availableExportModes property in XML. The default set of options is defined by the jmix.gridexport.default-export-modes application property.

You can override the header and message of the dialog by adding messages with exportConfirmationDialog.header and exportConfirmationDialog.message keys to your message bundle.

Columns Exporting

You can control which columns are included in the export using three different filtering options:

  1. Predefined Column Filter Predicate (Enumeration)

    This option allows you to select from a predefined set of filtering behaviors to determine which columns are exported. Configure this using the jmix.gridexport.default-columns-to-export application property or the columnsToExport additional property directly on the export action. The available options are:

    • ALL_COLUMNS: Exports all columns, regardless of visibility.

    • VISIBLE_COLUMNS: Exports only the columns currently visible in the DataGrid. Columns marked as visible using the gridColumnVisibility component are included in the list of exported columns. This means that hidden columns will be excluded.

      The default value for new projects is VISIBLE_COLUMNS. Existing projects will have their previous export behavior (likely ALL_COLUMNS) migrated to the application.properties file.

      Below is an example showing how to configure the export of all columns for a customer dataGrid.

      <dataGrid id="customersDataGrid" dataContainer="customersDc"
                width="100%"
                minHeight="20em">
          <actions>
              <action id="excelExport" type="grdexp_excelExport">
                  <properties>
                      <property name="columnsToExport" value="ALL_COLUMNS"/>
                  </properties>
              </action>
          </actions>
          <columns>
              <column property="firstName"/>
              <column property="lastName"/>
              <column property="email"/>
              <column property="age"/>
          </columns>
      </dataGrid>
      This method has the lowest priority; more specific methods will override this setting.
  2. Flexible Filtering Predicate (Extension Point)

    This provides a mechanism for highly customized column selection logic. Create a method annotated with @Install, targeting the export action. This method receives a Grid.Column object and returns true if the column should be exported, false otherwise.

    @Install(to = "customersDataGrid.excelExport", subject = "columnsExportFilter")
    private boolean customersDataGridExcelExportColumnsExportFilter(
            final Grid.Column<Customer> column) {
        return column.getKey().contains("firstName")
                || column.getKey().contains("email");
    }

    Чтобы сгенерировать заглушку обработчика в Jmix Studio, используйте вкладку Handlers панели инспектора Jmix UI, или команду Generate Handler, доступную на верхней панели контроллера экрана и через меню CodeGenerate (Alt+Insert / Cmd+N).

    This approach has medium priority, meaning it will override the predefined column filter predicate but will be overridden by explicitly specifying column keys.
  3. Explicit Column Key Specification (List of Keys):

    This provides the most direct control over which columns are exported. Use the columnKeysToExport additional property of the export action to define a comma-separated list of column keys to export within the <action> definition:

    <action id="excel" type="grdexp_excelExport">
        <properties>
            <property name="columnKeysToExport" value="email, firstName, lastName"/>
        </properties>
    </action>
    This option has the highest priority and will override any other settings.

Priority Order. So, the filtering options are processed in this order:

  1. Explicit column key specification.

  2. Flexible filtering predicate.

  3. Predefined column filter predicate.

ExcelExportAction

ExcelExportAction is an action extending ExportAction and designed to export the data grid content in XLSX format.

The action is implemented by the io.jmix.gridexportflowui.action.ExcelExportAction class and should be defined in XML using type="grdexp_excelExport" action’s attribute for a list component. Common action parameters can be configured through XML attributes within the action element. For more information, refer to the Declarative Actions documentation.

For example:

<actions>
    <action id="excelExport" type="grdexp_excelExport"/>
</actions>

Alternatively, you can inject the action into the view controller and customize its settings using setter methods:

@ViewComponent("customersDataGrid.excelExport")
private ExcelExportAction customersDataGridExcelExport;

@Subscribe
public void onInit(final InitEvent event) {
    customersDataGridExcelExport.setText("Export data grid to Excel");
}

You can also override localized data format strings. The default format string settings for Excel export are as follows:

excelExporter.label=Excel
excelExporter.true=Yes
excelExporter.false=No
excelExporter.empty=[Empty]
excelExporter.bytes=<bytes>
excelExporter.timeFormat=h:mm
excelExporter.dateFormat=m/d/yy
excelExporter.dateTimeFormat=m/d/yy h:mm
excelExporter.integerFormat=#,##0
excelExporter.doubleFormat=#,##0.00##############
excelExporter.decimalFormat=#,##0.00

JsonExportAction

JsonExportAction is an action extending ExportAction and designed to export the data grid content in JSON format.

The action is implemented by the io.jmix.gridexportflowui.action.JsonExportAction class and should be defined in XML using type="grdexp_jsonExport" action’s attribute for a list component. Common action parameters can be configured through XML attributes within the action element. For more information, refer to the Declarative Actions documentation.

For example:

<actions>
    <action id="jsonExport" type="grdexp_jsonExport"/>
</actions>

Alternatively, you can inject the action into the view controller and customize its settings using setter methods:

@ViewComponent("customersDataGrid.jsonExport")
private JsonExportAction customersDataGridJsonExport;

@Subscribe
public void onInit(final InitEvent event) {
    customersDataGridJsonExport.setText("Export data grid to JSON");
}

Limitations

  • When exporting TreeDataGrid, the column containing the hierarchy property will not include any padding.

  • Exporting entities with a composite primary key is not supported.