DataGrid selection event behaviors

Hi Jmix team,

There is an issue that occurred to me while using SelectionEvent for DataGrid components. Currently my users will perform a “double-click” onto any item on the DataGrid to trigger and EditAction, but there are some scenarios where we program some handling during the SelectionEvent itself and not customizing the EditAction.

I found out that in Jmix’s DataGrid, selecting(clicking) on an already selected item on the DataGrid will deselect it instead, which sometimes occurs when user performs a “double-click” on an item. In our SelectionEvent we usually use methods like dataGrid.getSingleSelectedItem() and this will hit a null error because “deselecting” the item would also trigger the SelectionEvent or the itemClickListener event.

My question is, is there any good solution for this other than having a null checking on the dataGrid.getSingleSelectedItem() function, can we prevent items from being “deselected” on the DataGrid? Or maybe something to prevent the SelectionEvent from triggering twice if the user is double-clicking to trigger an EditAction?

Hi!

Checking for null is a good way to avoid an exceptions.

You can disable double-click editing if needed using StandardListView#setSelectionHandler method.

I also suggest that you familiarize yourself with the code for implementing double-click editing in the framework: AbstractGridDelegate#handleDoubleClickAction. Here you can see the following line with comment:

        if (item != null) {
            // have to select clicked item to make action work, otherwise
            // consecutive clicks on the same item deselect it
            // selection from client is mandatory due to programmatic selection ignores selectableProvider
            component.getSelectionModel().selectFromClient(item);
        }

This way, our framework gets around the problem of the selected element being nullable when double-clicking.
I hope my answer helped you.

Best regards,
Dmitriy