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.
-
<action id="excelExport" type="grdexp_excelExport"/>
<button id="excelExportBtn" action="tSitesDataGrid.excelExport"/>
→ the button is always visible ! -
<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
Best regards
Felix