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