Daniel Faro
Daniel Faro

Reputation: 327

ListGrid put focus in the FilterEditor

I have a ListGrid defined like this:

ListGrid lgrid = new ListGrid();
ListGridField first  = new ListGridField("first",first");
ListGridField second = new ListGridField("second ",second ");
lgrid.setFields(first, second);
lgrid.setShowFilterEditor(true);

¿How can i put the keyboard focus in the first filter editor field after i call show() in the layout?

Thxs in advance.

Upvotes: 1

Views: 357

Answers (2)

carlossierra
carlossierra

Reputation: 4707

Depending on what your use case is (which would be useful to provide a more focused answer), the solution you posted might not be what you really need, because if you scroll on your ListGrid, it could trigger a new data fetch (if there are more records to show), and move the cursor to the filter editor as a result (if your user is editing some records at that point, the cursor moving to the filter row is not what she would want to happen!!).

In such a case, you probably just want to call grid.focusInFilterEditor("fieldToFocus") after the listGrid.show() statement or in the ClickHandler of some button you use to fetch the data, etc.

Anyway, you don't need the Timer either. This works:

listGrid.addDataArrivedHandler(new DataArrivedHandler() {
    @Override
    public void onDataArrived(DataArrivedEvent event) {
        grid.focusInFilterEditor("fieldToFocus");
    }
});

Upvotes: 1

Daniel Faro
Daniel Faro

Reputation: 327

I got the solution, its focusInFilterEditor, this is an example to set the focus after the data arrived to the grid:

   // Put the focus on the first listGrid field when is loaded    
    listGrid.addDataArrivedHandler(new DataArrivedHandler() {
        @Override
        public void onDataArrived(DataArrivedEvent event) {
                Timer t = new Timer() {
                    public void run() {     
                        if(listGrid.getFilterEditorCriteria() == null){
                            listGrid.focusInFilterEditor("fieldToFocus");
                        }
                    }
                };
                t.schedule(600);
        }
    });

Upvotes: 0

Related Questions