Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid scroll position reseted after redraw

    Hi,

    We want to implement simple routing - HLayout with left and right member (we call it just page). Left member (navigation menu) contains buttons, which when clicked will set the chosen right member (feature page).
    Feature pages are supposed to be created only once - when user opens featurePage second time we show the feature page as he left it.

    Some feature page contains listGrid with paging. We have opened this page and scrolled the grid to middle. Then we switch to other feature page and then back to original. It draws again the original feature page and the listGrid in it. But the listGrid is scrolled to the top showing no records. The grid's scrollbar is supposed to be set to the middle. I was trying to call ListGrid.markForRedraw() in the callback of page redraw, but this refreshes grid to the first data page - scrolled back to the row 1.

    Do you have any suggestion how to make grid to be drawn properly on the right scroll position?

    Code:
    private void showPage(FeaturePage featurePage) {
        Canvas page = cachedPages.get(featurePage);
    
        if (page == null) {
            switch (featurePage) {
            case page1:
                page = getPage1();
                break;
            case page2:
                page = getPage2();
                break;
            case page3:
                page = getPage3();
                break;
            }
            cachedPages.put(featurePage, page);
        }
    
        if (activePage != page) {
            if (activePage != null) {
                removeMember(activePage);
            }
    
            addMember(page);
            activePage = page;
        }
    }

    SmartClient Version: v10.0p_2017-11-10/PowerEdition Deployment (built 2017-11-10)
    GC Version 64.0.3282.167 (Official Build) (64-bit)

    #2
    I found following solution. But still I would like to hear your suggestion...

    On the feature page
    Code:
    private ListGrid createListGrid() {
        final MyGrid grid = new MyGrid();
        grid.addScrolledHandler(new ScrolledHandler() {
            @Override
            public void onScrolled(ScrolledEvent scrolledEvent) {
                gridBodyScrollLeft = grid.getBodyScrollLeft();
                gridBodyScrollTop = grid.getBodyScrollTop();
            }
        });
        return grid;
    }
    And then in DrawHandler of the feature page for the case when page is reopened.
    Code:
    addDrawHandler(new DrawHandler() {
        @Override
        public void onDraw(DrawEvent drawEvent) {
            if (listGrid != null) {
                listGrid.scrollBodyTo(gridBodyScrollLeft, gridBodyScrollTop);
            }
        }
    });

    Comment


      #3
      That's the correct way to restore the grid's scroll position if what you are doing is completely drawing the grid from scratch - because you are either clear()d or destroy()d it.

      Another approach would be to simply hide(), in which case this would not be necessary, and returning to the page would be quicker. But if you choose to hide() pages, you should implement some kind of LRU mechanism to avoid eventually slowing down the browser (which happens when there is too much hidden DOM content).

      Comment

      Working...
      X