gwtgwtpscrollpane

scrollToView() brings the element at the bottom. How to scroll element to the TOP


I have many elements in a list (table). I want to auto scroll to one specific element.

Using table.getRowElement(50).scrollIntoView(); scrolls the list to the desired element but just enough to be visible in the scrollPanel i.e. at the bottom.

How to scroll element to the top?


Solution

  • able to achieve it by scrolling to bottom first and then to the desired element

    scrollToTop(CellTable table, int position){
        if(table.getRowCount() > 0 && position >=0){
            //first - Scroll to bottom
            table.getRowElement(table.getRowCount() - 1).scrollIntoView();
            //second - scroll to element
            table.getRowElement(position).scrollIntoView();
        }
    }