[CLOSED] Focus selected row in Gridpanel

  1. #1

    [CLOSED] Focus selected row in Gridpanel

    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
                        gpReskont.GetView().FocusRow(Reskont_recnum.ToString()); //Does not work with recordId
    Best regards
    Last edited by fabricio.murta; Nov 05, 2020 at 12:19 PM.
  2. #2
    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

    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);
    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!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thanks for a very detailed answer, it works great.

  4. #4
    Thanks for the feedback, Mikael, and glad it helped you make the selection work the way you needed!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] [#603] GridPanel focus row
    By RCN in forum 3.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 14, 2015, 12:12 PM
  2. Replies: 1
    Last Post: Jun 27, 2014, 10:52 AM
  3. [CLOSED] How to Focus to the Next Editor in a GridPanel Row?
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 22, 2010, 9:18 PM
  4. Replies: 2
    Last Post: Dec 25, 2009, 2:56 PM
  5. [CLOSED] GridPanel selected focus
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 16, 2009, 9:08 AM

Posting Permissions