PDA

View Full Version : [CLOSED] Focus selected row in Gridpanel



Jurke
Nov 04, 2020, 9:14 AM
Hi
I have a gridpanel that I set one selected row in on Page_Load.
This row some times needs to be scrolled to, to be visible, this I can´t get to work.
I have tried with FocusRow() which works if I set the rowIndex manually, but I don´t know the rowIndex in the code.
I need to use FocusRow() with the recordId as I do with the SelectedRows




rowSelReskont.SelectedRows.Add(new SelectedRow(Reskont_recnum.ToString())); //rowSelReskont selection model of gpReskont
rowSelReskont.UpdateSelection();
gpReskont.GetView().FocusRow(Reskont_recnum.ToStri ng()); //Does not work with recordId


Best regards
Mikael

fabricio.murta
Nov 04, 2020, 4:56 PM
Hello Mikael!

You need some things to scroll to any row in a grid panel:

- The grid's store containing the records
- The record itself (or its index in the store)
- The grid's view containing the row you want to scroll to
- The grid view's "scrollable" handle to issue the scroll() command.

If using this example: Grid Panel > Array Grid > Simple (https://examples5.ext.net/#/GridPanel/ArrayGrid/Simple/)

The following is enough to scroll down to the "Verizon Communications" row at any time:



var store = App.GridPanel1.getStore(),
view = App.GridPanel1.getView(),
scroller = view.getScrollable(),
recordIdx = store.find("company", "Verizon Communications"),
record = store.getAt(recordIdx),
row = view.getRowByRecord(record);

scroller.scrollIntoView(row);


Notice this won't switch pages if you are using paging and may fail in case you are using infinite scrolling / remote data. This may also fail if you got a grid with many rows and enable buffered rendering, simply because the row won't be rendered at the view. Grids have buffered rendering enabled by default (this eases on the client for having rendered only whats close to the view area of the grid), so you may want to disable it in case it doesn't reliably scroll to the selected record. If paging you need to ensure you are in the page the record is prior to getting the row and scrolling it into view.

Hope this helps!

Jurke
Nov 05, 2020, 11:13 AM
Hi
Thanks for a very detailed answer, it works great.

Regards
Mikael

fabricio.murta
Nov 05, 2020, 12:19 PM
Thanks for the feedback, Mikael, and glad it helped you make the selection work the way you needed!