0

I have a buffered, grouped grid and I want to scroll into view a certain row (I have both the record and the record's/row's index at hand).

I have tried the undocumented

grid.getView().scrollRowIntoView(index)

but this only works in unbuffered grids, because it calls

view.getRow(row)

which only returns rows that are currently rendered, not the ones that are not rendered.

Is there an official function available I overlooked or what else can I do to scroll to the correct record?

Alexander
  • 19,906
  • 19
  • 75
  • 162

2 Answers2

5

bufferedRenderer plugin has a function scrollTo(recordIdx).

There is no function in gridpanel or gridview or dataview that calls bufferedRenderer.scrollTo, so I guess you have to call getView().bufferedRenderer.scrollTo directly from your grid.

Update: Please note that scrollTo may not be called if the store is empty, as this causes an error in the framework. Reason is that scrollTo takes the record index; if the index is below 0, it will be set to 0, if it is store.Count() or greater, it will be set to store.Count()-1 (which is -1 if the store is empty). Then, the record is fetched from the store (getAt(index)), which returns null if and only if the store is empty, and then it is checked that the record is indeed a model:

if(record.isModel)

which then causes the error

Uncaught TypeError: Cannot read property 'isModel' of null

So you have to always check that the store is not empty before calling scrollTo:

if(view.store.getCount()) view.bufferedRenderer.scrollTo(index);
Alexander
  • 19,906
  • 19
  • 75
  • 162
2

The question has been crossposted in Sencha forum, where Gary Schlosberg of the Sencha Support team answered:

Have you tried the ensureVisible config? The callback option mentions usage with a BufferedStore.

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • It's not a config, it's a method call - but it works perfectly. Just add code like this to a load event handler for your store: `var selection = grid.getSelection(); if (selection && selection.length > 0) grid.ensureVisible(selection[0]);` Then anytime the store loads you'll be sure the selcted record is visible. – John A Nov 14 '17 at 17:56