Is there a way to enable/disable buttons upon grid selection

I have more than a few buttons which need to only be available upon the selection of a table row, is there a way to link the selection to the available buttons? or do I have to code each one individually?

protected void onInit(InitEvent event) {
        btnDownload.setEnabled(false);
}    

public void onTblMainSelection(Table.SelectionEvent<PatientFile> event) {
        btnDownload.setEnabled(true);
}

Hi,

If your buttons are connected to actions, you can use install “Enabled Rule” to an action like it is described here.

@Inject
private GroupTable<Customer> customersTable;

@Install(to = "customersTable.remove", subject = "enabledRule")
private boolean customersTableRemoveEnabledRule() {
    Set<Customer> customers = customersTable.getSelected();
    return canBeRemoved(customers);
}

thank you for your response, we’ve been trying it out. Is there a way to do this WITHOUT actions??

Hi,

Unfortunately, we cannot bind any UI control property to any object property from the data container. Therefore, you have two options: either use actions and define rules for them (which is the recommended way of dealing with buttons) or enable and disable buttons manually.

Could you elaborate more on the topic of actions please? Do you have any issues with defining actions in your screens?