Control inline editor for DataGrid

I would like control whether the inline editor is started based on a status field in the entity, in a DataGrid.

E.g. if status=“N”, can edit record else cannot edit the record.

How can I control this for a datagrid ?

CK

Hello,

Take a look at DataGrid Editor events. You can subscribe to EditorOpenEvent, check entity property, and close editor:

@Subscribe("customersDataGrid")
public void onCustomersDataGridEditorOpen(DataGrid.EditorOpenEvent event) {
    Customer customer = (Customer) event.getItem();
    if (!customer.isEditable()) {
        customersDataGrid.unwrap(CubaGrid.class).getEditor().cancel();
    }
}

DataGrid doesn’t have a method for getting Editor, so we have to unwrap it with Vaadin type.

1 Like

Thanks. The code works.