Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-1183 in a recent build.
  1. #1
    Sencha User
    Join Date
    Mar 2009
    Posts
    240
    Vote Rating
    0
    r_honey is on a distinguished road

      0  

    Default Ext.mixin.Selectable should refresh selections on store load

    Ext.mixin.Selectable should refresh selections on store load


    If a dataview has mode set to 'MULTIPLE', you select some rows and load data as follows:

    Code:
    dataview.getStore().loadData(jsonArray, false);
    and then call dataView.getSelected(), records that are no longer in the store from previous selections are still returned. The mixin needs to refresh selections when store is loaded.
    (This is related to my previous bug report requesting a new event when loadRecords is called, without doing that, resolving this can lead to multiple invocations of refreshSelections unnecessarily).

    Here's my current work-around:

    Code:
    Ext.data.Store.prototype.loadRecords = Ext.Function.createSequence(Ext.data.Store.prototype.loadRecords, function (records, options) {
        this.fireEvent('loadrecords', this, records, options);
    });
    
    
    
    
    
    
    Ext.dataview.DataView.prototype.onSelectionStoreLoadRecords = function () {
        this.refreshSelection();
    }
    
    
    Ext.dataview.DataView.prototype.applyStore = Ext.Function.createSequence(Ext.dataview.DataView.prototype.applyStore, function (store) {
        store.on('loadrecords', this.onSelectionStoreLoadRecords, this);
    });
    
    
    Ext.dataview.DataView.prototype.updateStore = Ext.Function.createSequence(Ext.dataview.DataView.prototype.updateStore, function (newStore, oldStore) {
        if (oldStore && Ext.isObject(oldStore) && oldStore.isStore) {
            store.un('loadrecords', this.onSelectionStoreLoadRecords);
        }
    });
    Because the DataView class has already been created by the time my code executed, I had to sequence DataView methods (instead of being able to do it on Selectable mixin).

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    18
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    Sounds correct, thank you for the report.

    Sencha Inc

    Jamie Avins

    @jamieavins

  3. #3
    Sencha User
    Join Date
    Mar 2009
    Posts
    240
    Vote Rating
    0
    r_honey is on a distinguished road

      0  

    Default


    Whoa, that was a pretty quick time to resolve the issue

  4. #4
    Sencha User
    Join Date
    Mar 2009
    Posts
    240
    Vote Rating
    0
    r_honey is on a distinguished road

      0  

    Default


    Hi Jamie, this still doesn't seem to be fixed in Preview 3 (although it was marked fixed well before that).
    Here are the steps to reproduce this:
    1. Load data into store bound to a dataview.
    2. Click on a row to select it.
    3. Load data again, e.g.
      store.loadData(someJsonArray, false);
      Ensure the second argument is false.
    4. Click a row again and in the listener for selectionchanged on dataview, note that it reports 2 rows as selected.

  5. #5
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    18
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    This has been fixed for the next release. Here is an override:
    Code:
    Ext.ClassManager.onCreated(function() {
        Ext.override(Ext.mixin.Selectable, {
            onSelectionStoreClear: function() {
                var me = this,
                    selected = me.getSelected();
                if (selected.getCount() > 0) {
                    selected.clear();
                    me.setLastSelected(null);
                    me.setLastFocused(null);
                    me.fireSelectionChange(true);
                }
            }
        });
    }, null, 'Ext.mixin.Selectable');

    Sencha Inc

    Jamie Avins

    @jamieavins

Thread Participants: 1