Button only enable if there is a selection in the datagrid not working in grdexp_excelExport

The documentation (AI) writes

To make a button enabled only when an entity is selected in a Jmix DataGrid, you should connect your button to a DataGrid action such as “edit”, “remove”, or a custom action. Buttons bound to DataGrid actions will automatically be disabled unless a DataGrid row is selected.

This is not fully true.

  1. <action id="excelExport" type="grdexp_excelExport"/>
    <button id="excelExportBtn" action="tSitesDataGrid.excelExport"/>
    → the button is always visible !

  2. <action id="exportToMap"/>
    <button id="exportToMap" action="tSitesDataGrid.exportToMap"/>
    → the button is always visible !

In case 1) the button has to be set enabled="false" and we have to add programmatically an event listener

tSitesDataGrid.addSelectionListener(selectionEvent -> {
   excelExportBtn.setEnabled(!tSitesDataGrid.getSelectedItems().isEmpty());
});

In case 2) it will work if you add type="list_itemTracking"

I think, case 1) is a bug and case 2) should be better documented for example at Actions :: Jmix Documentation

The reply of the AI on my question was not fully correct, but based on this information I found the correct solution :wink:

Best regards

Felix

1 Like

Hi,

The first case is not a bug, not all list actions must be disabled if no item is selected in the corresponding list component (e.g. DataGrid). For example, list_create, grdexp_excelExport work even if nothing is selected.

As for documentation, we have as issue to improve it (Detailed info about standard actions · Issue #554 · jmix-framework/jmix-docs · GitHub). Feel free to drop a comment to prioritize it.

Regards,
Gleb