PDA

View Full Version : how to force the grid to scroll to the selected row



aminef
15 Dec 2010, 1:01 PM
I am trying to force the grid to scroll down to the selected row, and I can't figure it out.
I tried

grid.getView().focusRow(index); Witch seems to be the most obvious method for that kind of request.
I even tried to override the storeDataChanged according to a thread that was talking about the same issue

store.addStoreListener(new StoreListener<PersInfo>() {
public void storeDataChanged(StoreEvent<PersInfo> se) {
DeferredCommand.addCommand(new Command() {
@Override
public void execute() {
focus();
}
});
}
});


and still nothing...

sven
15 Dec 2010, 1:03 PM
Simple calling focus wont scroll any row into view.
grid.getView().focusRow(index); Works fine for me. I am using it in a couple of places in own applications. Please post a fully working testcase implementing EntryPoint and demonstrating your problem.

aminef
15 Dec 2010, 1:05 PM
you mean this
Code:
grid.getView().focusRow(index);

works fine for you?

sven
15 Dec 2010, 1:05 PM
Yes

aminef
15 Dec 2010, 1:07 PM
that's weird... because I am calling these 2 methods:


grid.getSelectionModel().select(index, false);
grid.getView().focusRow(index);
the selection goes through and does select the indexed row, but the focus doesn't and I have to scroll manually to see the selected line

sven
15 Dec 2010, 1:08 PM
Which version of GXT are you using? Have you tried to reproduce this in a small, standalone testcase?

aminef
15 Dec 2010, 1:13 PM
2.2.0
and my case is pretty simple, I use a costomised gridview, even overriding the onRowSelect by adding
focusRow(rowIndex); doesn't work

sven
15 Dec 2010, 1:16 PM
I cannot help you much if you dont post any testcase here. Try putting the focusROw into a DeferredCommand.

kosaco
1 Jun 2011, 11:33 PM
You can try this:

myGrid.getSelectionModel().select(myModel, false);
myGrid().getView().refresh(false);
myGrid.getView().focusRow(7);

Regards!

Julien.hu
7 Jul 2011, 5:40 AM
I have the same problem. focusRow() does not work. Anybody has another solution for scrolling to the new created row ?

vceban
1 May 2013, 6:47 AM
this solved it for me

DeferredCommand.add(new Command() {
public void execute() {
listGrid.getView().refresh(false);
listGrid.getView().focusRow(rowIndex);
}
});

ravikiran1226
31 May 2013, 2:42 AM
listView.getSelectionModel().select(sM, false);
Element elem = listView.getElement(listView.getStore().indexOf(sM));
if (elem != null)
listView.fly(elem).scrollIntoView(listView.getElement(), false);
listView.focus();

Where 'sM' is the modeldata object

poseidonjm
14 Jun 2013, 2:46 PM
Thanks guys
This work for me

gridSolicitud.getSelectionModel().select(bm, false);
final Integer index = gridSolicitud.getStore().indexOf(bm);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {

@Override
public void execute() {
gridSolicitud.getView().refresh(false);
gridSolicitud.getView().focusRow(index);
}
});