[CLOSED] Scroll to selected row in GridPanel

  1. #1

    [CLOSED] Scroll to selected row in GridPanel

    I have a DropDownField that shows a gridpanel with a id and a text. The dropdownfield has a start value which I select in the gridpanel (this works) by this code:
    App.gpEditUtforare.getSelectionModel().select(App.storeEditUtforare.find('ID', this.getValue()))
    Then I want the gridpanel to scroll to that selected row.
    I tried with focusRow(), but I can't get it to work. I hope you can give me some help without a full example.

    <ext:DropDownField runat="server">
                                                                        <Expand Handler="this.picker.setWidth(300); App.gpEditUtforare.getSelectionModel().select(App.storeEditUtforare.find('ID', this.getValue()))" />
                                                                                        <ext:Model runat="server">
                                                                                                <ext:ModelField Name="ID" Type="String" />
                                                                                                <ext:ModelField Name="NAMN" Type="String" />
                                                                            <ColumnModel runat="server">
                                                                                    <ext:Column runat="server" Header="ID" Width="100" DataIndex="ID"></ext:Column>
                                                                                    <ext:Column runat="server" Header="Namn" Flex="1" DataIndex="NAMN"></ext:Column>             
                                                                                <RowClick Handler="this.dropDownField.setValue(record.data.ID);"></RowClick>
    Last edited by fabricio.murta; Mar 26, 2020 at 7:18 PM.
  2. #2
    Hello Mikael!

    If you get one and only one record selected in the grid every time, you can use the grid view's getRow() method to scroll the grid to the record you have selected -- as long as it is rendered and in the page you are.

    If your grid uses buffered rendering and is long enough to have the record not rendered at all times, it may become unable to determine where to scroll to. If you have paging feature in the grid, you'd need also to ensure the selected record is in the current page before you can try to scroll.

    Given the context you provided, this should be enough to scroll to the selected entry, when you do the selection in the code you shown first:

    var grid = App.gpEditUtforare,
        store = grid.getStore(),
        view = grid.getView();
    view.getRow(store.getAt(store.find("ID", this.getValue())).scrollIntoView();
    You may want to double check whether store.getAt() can return something valid, i.e. store.find() result is an index >= 0.

    The scrollIntoView() bit comes from browser implementation; the getRow() method returns a DOM Element. Documentation on Element.scrollIntoView().

    I believe this is as far and deep we can get with the provided information. If still in trouble, I am afraid we would require a test case.

    Hope this helps, nevertheless!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    That worked perfectly, thanks a lot!

  4. #4
    Hello Mikael!

    Glad we could help with the tips provided, thanks for the feedback!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. LiveSearch and scroll to selected row
    By SaleCar in forum 3.x Help
    Replies: 5
    Last Post: Mar 03, 2015, 5:04 PM
  2. Replies: 2
    Last Post: Jan 07, 2015, 7:07 PM
  3. Replies: 2
    Last Post: Dec 25, 2009, 2:56 PM
  4. [CLOSED] How to scroll to selected row
    By tansu in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: May 17, 2009, 3:55 PM
  5. Replies: 0
    Last Post: Mar 16, 2009, 8:46 AM

Posting Permissions