Move selected row cursor using keyboard up/down keys in data grid

Hello Community,

I am using ItemChangeListener to retrieve on single click in data grid but is there a workaround to move the selected row cursor using keyboard keys because it takes too many clicks to move from row to row.

Let me know if there is a workaround.

Thanks,
Sanchit

Hi,

Could you describe in more details what you want to achieve?

Hey,

I have a split screen with two data grid’s, the row selection on the above data grid shows the related results in the lower grid. (related topic: Update column based on row selection - CUBA.Platform)
Everything works fine as it retrieve on single clicks but I also want to control the row selection by keyboard to work along with the same functionality.

Is there a way to do it.

Thanks for the explanation, now it’s clear to me. I would recommend using SelectionListener to get rid of clicks.

I tried that but doesn’t help

An example would be helpful.

Could you attach a code of your listener?

(a) Old approach:

`// ItemChangeListener to retrieve on single click
        annotationsDs.addItemChangeListener(event -> {

            annotationFieldVar = AnnotationFieldDataGrid.getSingleSelected();


            if(annotationFieldVar!= null){

                aliasDataGrid.setVisible(true);     // set visibility back to true on annotation selection

                aliasesDs.setQuery("select e from zeusv2$Alias e where  e.annotation.id='" + annotationFieldVar.getId() + "\'");

                aliasesDs.refresh();


            }
        });`

(b) With selection listener:

    'AnnotationFieldDataGrid.addSelectionListener(e -> {
            annotationFieldVar = AnnotationFieldDataGrid.getSingleSelected();


            if(annotationFieldVar!= null){

                aliasDataGrid.setVisible(true);     // set visibility back to true on annotation selection

                aliasesDs.setQuery("select e from zeusv2$Alias e where  e.annotation.id='" + annotationFieldVar.getId() + "\'");

                aliasesDs.refresh();


            }
        });

So, I suppose that you use keyboard arrows and selection isn’t changed? If so, that is not an issue, due to DataGrid default behavior. You have to press Space Bar to trigger row selection.

wow I didn’t knew about the default dataGrid behaviour to trigger rows.

Perfect. Thanks

1 Like

Good afternoon. Faced with this problem, can I somehow get around it, for example, by processing keystrokes?

1 Like

Hi,

As I mentioned above this is by design and can’t be changed easily.

Gleb