3.2.0

calling refresh when scrolled down resets view to top

I have, say, 20 rows, but only want to display 10 at a time.
I'm updating my data and calling .refresh() every 5 seconds.
If I'm scrolled down to roll 18 when the refresh is triggered, the grid will lose focus and the view of the grid will be reset to the top.

Is there anything I can do about this?
Sebastian
March 30,
OK, I figured out that calling
obj.getTemplate("row", i).refresh();
will do what I want, but when I add or remove data, this is not reflected by the above command (i.e. the rows remain as they were before, instead of being removed/adding more). I have to do an obj.refresh() (which is undesireable since I lose position and focus, and there is a flicker) in order to reflect the changes.

Am I missing something, or is there a way around this?
Sebastian
March 30,
:-(
That's a bug - grid should keep scroll position and focus on refresh. I will try to fix it in the next release. For now, when you can refresh only one row - do that. Otherwise, here is a nasty hack to restore your scroll position and focus:

var scrollbars = obj.getTemplate("layout").getContent("scrollbars");

var x = scrollbars.element().scrollLeft;
var y = scrollbars.element().scrollTop;

obj.refresh();

window.setTimeout(function(){
scrollbars.element().scrollLeft = x;
scrollbars.element().scrollTop = y;
obj.element().focus();
}, 0 );

It will flicker - but I cannot suggest anything better now.
Alex (ActiveWidgets)
March 30,
I tried the hack. See the function below that gets called every 15 seconds. If I remove the table.request(); call, your hack works, but it doesn't update the table data. If I leave it in, the hack doesn't work, but I get an updated table.

function doRefresh() {
      var scrollbars = obj.getTemplate("layout").getContent("scrollbars");

      var x = scrollbars.element().scrollLeft;
      var y = scrollbars.element().scrollTop;

      table.request();
      obj.refresh();

      scrollbars = obj.getTemplate("layout").getContent("scrollbars");
                
      window.setTimeout(function(){
                scrollbars.element().scrollLeft = x;
                scrollbars.element().scrollTop = y;
                obj.element().focus();
      }, 0 );
        
      setTimeout("doRefresh();", 15000);
}


Any suggestions on how I might get the table data refreshed while remembering the scroll bar positions? (Ideally, it wouldn't display the message while it is refreshing, it would continue to work with the data updating nicely, but I'd be happy just restoring the scrollbars.)

Thx.
dh
September 21,
In your code the table.request() triggers another grid refresh after the data has arrived. So you have to separate them

var _refresh = obj.refresh;

obj.refresh = function(){

    var scrollbars = this.getTemplate("layout").getContent("scrollbars");

    var x = scrollbars.element().scrollLeft;
    var y = scrollbars.element().scrollTop;

    _refresh.call(this);

    this.element().runtimeStyle.visibility = "hidden";

    var _obj = this;

    window.setTimeout(function(){
        scrollbars.element().scrollLeft = x;
        scrollbars.element().scrollTop = y;
        _obj.element().runtimeStyle.visibility = "visible";
        _obj.element().focus();
    }, 0 );

}


and also

setTimeout(function(){
  table.request();
}, 15000);

Alex (ActiveWidgets)
September 25,

This topic is archived.

See also:


Back to support forum