Excel Export action for Vaadin Grids, (programmatically)

Jmix version: 2.2.3
Jmix Studio plugin version: 2.2.3-241
IntelliJ IDEA 2024.1 (Ultimate Edition)

I want to use jmix export excel action for my programmatically created vaadin grid component. How can i do this. My grid is not created through xml, rather hard coded with Vaadin grid component:

JmixGrid<?> simpleGrid = uiComponents.create(JmixGrid.class);
Action excelExportAction = ...
simpleGrid.addAction(excelExportAction);
          

Is this even possible? If so, what is the optimal way?

Note:
Grid is not built around some entity. it’s just some DTO class.

1 Like

Hello Otabek.

Actions can be created via io.jmix.flowui.Actions service.
Autowire it to your screen and call

ExcelExportAction excelExportAction = actions.create(ExcelExportAction.ID);

But the ExcelExportAction requires ListDataComponent as a target so it will not work with JmixGrid.
To be able to use ExcelExportAction you need DataGrid instead of JmixGrid.

And there is also additional notice:
Before Jmix 2.3 Export All doesn’t work with load delegate (which is required if you use DTO), only with database directly. This is fixed within ExportAll action doesn’t use LoadDelegate · Issue #3313 · jmix-framework/jmix · GitHub.

Regards,
Ivan

Hello Ivan.

Thanks for your efforts, and I appreciate it.
Your answer seems promising. However, my SQL query is quite complex and includes more than one query to the database. In this case, I cannot use any loaders directly in my XML config file.
I only set items to the grid and later add columns dynamically according to some specific conditions.

In Cuba applications, it’s easy to print table values by extending the Table.PrintableColumnGenerator class. Can I do the same in Jmix?

Hopefully, you understand my situation better. Thanks for your response