You found a bug! We've classified it as
TOUCH-4343
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
-
store load event seems to fire before filter on localstorage
Let me jump straight into some code. The model has a localstorage proxy.
Code:
Ext.create('Ext.data.Store', {
model: 'MyApp.model.MyModel',
autoLoad: true,
pageSize: 1000,
filters: [
// any kind of filter in here
],
listeners: {
scope: this,
load: function (store) {
console.log(store.getCount());
Ext.defer(function () { console.log(store.getCount()); }, 1, this);
}
}
});
The first console.log outputs the total number of records in the localstorage for this model. The second, the number of filtered records. I'd say a developer would expect the second result immediately without having to defer to let the filter run - especially since there is no filter event on Ext.data.Store, and in the docs the getCount method explicitly says this count does not include filtered records: "Gets the number of cached records. Note that filtered records are not included in this count. If using paging, this may not be the total size of the dataset."
This is also changing the behaviour compared to the sqlite proxy. I've seen on that proxy that the sql query changes depending on the filter defined on the store. Therefore the same example is filtered from the start - the all index of the data object has the same as the items one immediately after load.
I would throw my two cents towards the sqlite proxy behaviour. This is what I'd expect as the developer and I really dislike that all localstorage store loads put every single record of that type into the store and then filter. I don't want these records hanging around in the memory - in the above example, the filter is on the store from the start! Or perhaps an additional config, something that works similarly to remoteFilter, might be of use here?
-
I'm going to open a bug to see what we can do about this.
-
Thanks Mitchell, appreciate it.
In using the sql proxy a bit more, I've also discovered that it fails on models with array or object fields. This is another issue where there I guess there should be more consistency between the localstorage and sql behaviors.
I've written an override that handles these fields by encoding them to json in the database. It's a little messy but I'm happy to share with anyone who would like this functionality.
-
Sencha User
-
Sencha Premium User
4 years and it's still a bug, great job sencha