Scroll to selection in an ExtJS Grid

无人久伴 提交于 2019-12-05 09:09:14

This also seems to work:

grid.getView().focusRow(rowIdx);

Unfortunately ensureVisible() was removed from ExtJS 4. The most straight-forward solution I found is to use scrollIntoView(). In my case, this was after selecting the row based on a value I loaded.

var rowIndex = store.find('fieldName', value);
grid.getSelectionModel().select(rowIndex);
Ext.fly(grid.getView().getNode(rowIndex)).scrollIntoView();

This will show the selected row at the bottom of the grid. More work would need to be done to have it at the top or middle of the grid.

This also seems to work:

    grid.getView().getRow(rowIdx).scrollIntoView();

Worked for me on ExtJS 6, even with bufferedRenderer turned on.

        var record = grid.getSelectionModel().selected.getRange()[0];
        grid.getView().focusRow(record);

This also seems to work

grid.getView().getNode(rowIndex).scrollIntoViewIfNeeded();

In case of ExtJs 4.X No need to use Ext.fly

Sorry, I'm being really dumb. I just tried ensureVisible and it works fine.

To save you all a lot of hair pulling, you should know that the solutions in this thread for scrolling into view will not work if grid bufferedRenderer is turned on.

It is my understanding that in Ext JS 5, bufferedRenderer is turned on by default.

It took me a couple hours before I realized this.

grid.getView().getNode(rowIndex) will return NULL if the indexed row is outside the buffered rows.

In 4.2 at least, using scrollIntoViewIfNeeded fails if you're outside of the buffered range in a bufferedRenderer. The bufferedRenderer has a handy scrollTo method to help with this task though:

grid.getView().bufferedRenderer.scrollTo(index, true);

Scrolls to and optionlly selects the specified row index in the total dataset.

http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.grid.plugin.BufferedRenderer-method-scrollTo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!