View Full Version : [FIXED] Ext.mixin.Selectable should refresh selections on store load

5 Dec 2011, 10:50 AM
If a dataview has mode set to 'MULTIPLE', you select some rows and load data as follows:

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 (http://www.sencha.com/forum/showthread.php?159923-Store.loadRecords-should-fire-an-additional-event-apart-from-add-datachanged) 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:

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 () {

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).

Jamie Avins
5 Dec 2011, 11:05 AM
Sounds correct, thank you for the report.

5 Dec 2011, 1:47 PM
Whoa, that was a pretty quick time to resolve the issue :)

14 Dec 2011, 3:57 AM
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:
Load data into store bound to a dataview.
Click on a row to select it.
Load data again, e.g.
store.loadData(someJsonArray, false);
Ensure the second argument is false.
Click a row again and in the listener for selectionchanged on dataview, note that it reports 2 rows as selected.

Jamie Avins
14 Dec 2011, 3:36 PM
This has been fixed for the next release. Here is an override:

Ext.ClassManager.onCreated(function() {
Ext.override(Ext.mixin.Selectable, {
onSelectionStoreClear: function() {
var me = this,
selected = me.getSelected();
if (selected.getCount() > 0) {
}, null, 'Ext.mixin.Selectable');