Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Stop scrolling to top when grid store is reloaded

  1. #1
    Sencha - Support Team keckeroo's Avatar
    Join Date
    Mar 2008
    Location
    Winnipeg, Canada
    Posts
    387

    Default Stop scrolling to top when grid store is reloaded

    I have a grid which is periodically being refreshed using a task runner which calls the store to reload.

    I find that when i'm looking at the grid (say scrolling down halfway through the page) if new data arrives and is placed at the start of the grid (where it should be according to my sort) the grid automatically 'autoscrolls' me to the top of the list again making me lose my place in the list where i was viewing.

    Is there anyway to update the contents of the grid *without* if affecting my current visual position in the grid ?

    I tried looking through the forums - but have yet to find anyone else who asked this yet.

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,250

    Default

    Before you refresh the store, you can save the scroll top value of the grid. Once it reloads, you can restore it.

  3. #3
    Sencha - Support Team keckeroo's Avatar
    Join Date
    Mar 2008
    Location
    Winnipeg, Canada
    Posts
    387

    Default

    I'm floored by how fast I received a response - I will endevour to get it working with the info you provide (I like learning first without the standard 'well - how do i do that ?!' response) ... but rest assured - if I am stumped - I'll be back asking ;-)

    Thank you x 1000 :-)

  4. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,250

    Default

    Actually, it's probably easier to subscribe to the body scroll event on the grid. When it gets scrolled, you can save the value.

  5. #5
    Sencha - Support Team keckeroo's Avatar
    Join Date
    Mar 2008
    Location
    Winnipeg, Canada
    Posts
    387

    Default

    Before i do put this together a logical question arises ... if i save the scroll position - reload and, in theory, alter the size of the grid would not the scroll position of the original row i was looking at not change as a result ? I'm just wondering if i would be scrolling to a different offset equal to the number of rows inserted or removed from the grid.

    Kev

  6. #6

    Default

    hi, keckeroo,try this at 'load' event:

    Code:
    grid.getView().focusRow(ds.indexOfId(cId)
    where cId is recorded at 'rowselect' event:
    Code:
    	function onRowSelect(grid, rowIndex, e) {
    	     cId = selModel.getSelections()[0].data.id;
    	}

  7. #7
    Sencha - Support Team keckeroo's Avatar
    Join Date
    Mar 2008
    Location
    Winnipeg, Canada
    Posts
    387

    Default

    That assumes that a row is selected...

    I guess what i'm trying to achieve is exactly the same result as if you were in a mail program with split panes - the top pane has a list of your messages (you may or may not have one selected) and if you are scrolled down the list, you do not normally get scrolled back up when new mail arrives into your list ... but if you scroll up - the new record is magically there at the top of the list..

    Basically the main viewing area should be 'frozen' regardless of any underlying activity to the grid data unless, of course, you're at the top of the grid, in which case new arrivals do show.

    I see this type of 'list growth' in many programs which allow you to scroll through a dynamic list of values (chat room occupants, email lists, etc). New arrivals go on top but do not disturb the view if you have scrolled away from the top of the view.

    Kev

  8. #8
    Sencha - Support Team keckeroo's Avatar
    Join Date
    Mar 2008
    Location
    Winnipeg, Canada
    Posts
    387

    Default

    Ok - I think I've logically figured out how to do this - I'm just stuck with one last item
    I cannot figure out how to apply the scroll() method to my grid to scroll to the saved values before the reload.

    mygrid = new ext.grid {
    id: 'me',

    Ext.get('me').scroll('down', savedvalue);
    }

    doesn't give errors - but doesn't seem to scroll. I've figured the pixel amount perfectly adjusting for additions but i can't issue a scroll :-(

    How do I scroll a grid using extjs ?

    That will solve my problem.

  9. #9
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,250

    Default

    Try:

    Code:
    myGrid.getView().scroller.dom.scrollTop = val;

  10. #10
    Sencha - Support Team keckeroo's Avatar
    Join Date
    Mar 2008
    Location
    Winnipeg, Canada
    Posts
    387

    Default

    hmmm

    this is what I have as part of my grids viewConfig :

    Code:
    var messageList = new Ext.GridPanel({
    .....
    snip
    ...
            viewConfig: { 
               cRow: 0,
               saveRow: 0,
               listeners: {
                   beforerefresh: function(gridview) {
                       this.saveRow = this.cRow;
                   },
                   refresh: function(gridview) {
                       this.saveRow = this.saveRow + 11;
                       alert('scroll to ' + this.saveRow);
                       messageList.getView().scroller.dom.scrollTop = this.saveRow;
                   }
               }
            },
            listeners: {
               bodyscroll: function(sl, st) {
                  this.getView().cRow = st;  
               }
            },
    alert comes up with 'scroll to 355' , nothing has yet refreshed ... I click the alert then the
    screen refreshes at the top :-( Please note that the alert appears BEFORE the grid is refreshed!! Docs seem to imply
    'refesh' is fired AFTER grid is refreshed.

    I'm obviously doing this in the incorrect place ...

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •