1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    4
    Vote Rating
    0
    Leowill is on a distinguished road

      0  

    Default Unanswered: Force the selected row in the grid to scroll to the center

    Unanswered: Force the selected row in the grid to scroll to the center


    I want to make the row in the center of gird. I try code like this:
    Code:
    myGridView.ensureVisible(rowIndex, 0, true);
    or
    Code:
    myGridView.focusRow(rowIndex);
    It just makes the row visible, sometimes the row is on the bottom of the grid.
    Is there any method to make the row in the center of the gird.
    I know that ,we should call scroller.setScrollTop() function, but I don't know the value to set.

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Answers
    109
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      1  

    Default


    This should be some simple math - take the offset of the row you want (using getOffsetTop), and add half of the height of the scroller (getOffsetHeight), minus half of the height of the *row* (again, getOffsetHeight). This will center the row within the grid's scroller.

    I've not tested this, but that would be my first move. Note that this is nearly what GridView.ensureVisible is doing, plus other math to account for the column and whether or not to scroll horizontally.

Thread Participants: 1