Option to preserve existing data/selections on DataView.refresh

January 8th, 2009
  • I'm playing with the DataView and have found that I can't get it to keep the selections when I dynamically change template (tpl) and then doing a refresh()


  • The data is getting reloaded from the store when you call refresh and could have changed since the original load. I guess you could argue that it should have the option of either monitoring store changes or otherwise keeping track of the state of the data, but that would not be a bug, but an enhancement request. It's working as intended currently.

    The grouping grid uses a specific store subclass (GroupingStore) that has special logic to handle local data grouping (as in the example) differently from remote grouping -- in the remote case it actually does do a full reload just like DataView since the data could have changed. Also, regrouping existing rows is a different use case than refreshing the underlying data of a view, so I'm not sure that they're directly comparable.

    Maybe if you can explain the use case that you are trying to achieve, it would be clearer why it might make sense to preserve selections across data reloads?


  • Thanks Brian! It works great!

    However... I'm still currious if Jack will agree with me that it should be implemented into the API... Jack?


  • Why would you expect it to maintain selection after changing the template and refreshing? You could probably save the selections yourself and reload it manually. However, this is not a bug as it doesn't try to preserve selections across refresh currently.


  • I don't agree.... by changing the template I just want to show my data in another way. I haven't changed any criteria for what to view from the store, so I must say that I would presume that it should maintain the selection.

    I would say that this is "just like" what is going on in a grouping grid (http://extjs.com/deploy/dev/examples/grid/grouping.html).


  • Actually, I re-read your post and I think I see what you mean -- when changing templates, it might be handy to have an option for whether or not to reload everything vs. just binding the existing data/selections to a new template. As currently implemented, it always assumes that everything gets reloaded when you call refresh.

    This is not a bug (it currently works as advertised) but it is a valid feature request. I will move the thread accordingly. Thanks.


  • Maybe something like this? The code is sort of a hack (it still reloads the data from the store), but it might suit your purposes for keeping the selections. A true refactoring would require changes to some of the other existing code, so I'll let Jack decide whether or not this is a useful idea before taking it much further.

    Ext.override(Ext.DataView, {
    setTemplate : function(tpl, refresh){
    this.tpl = tpl;
    if(refresh){
    this.refresh();
    }else{
    var sel = this.getSelectedIndexes();
    this.tpl.overwrite(this.el, this.collectData(this.store.getRange(), 0));
    this.all.fill(Ext.query(this.itemSelector, this.el.dom));
    this.updateIndexes(0);
    this.select(sel);
    }
    }
    });







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Option to preserve existing data/selections on DataView.refresh , Please add it free.