PDA

View Full Version : Dynamic Store



kaddah
4 Mar 2015, 6:44 AM
Hello,

I want to change the store dynamically.

When I try it the following way, it works perfectly with one item in location

Ext.define('app.store.LocationViewStore', { extend: 'Ext.data.Store',


requires: [
'app.model.Location',
'Ext.data.proxy.Sql',
'Ext.util.Filter'
],


config: {
model: 'app.model.Location',
pageSize: 5000,
storeId: 'LocationViewStore',
proxy: {
type: 'sql',
database: 'DATABASE',
table: 'LOCATION'
},
filters: {
filterFn: function(item) {


var itemLocation = item.data.location; // for example it is NY,LA,CA
var location = app.auth.Session.model().getLocation(); // for example it is NY


if(itemLocation == location){
return itemLocation;
}


}
}
}
});

But, when I have more item than one in my location variable and I want to split it, then it does not work any more.

Ext.define('app.store.LocationViewStore', { extend: 'Ext.data.Store',


requires: [
'app.model.Location',
'Ext.data.proxy.Sql',
'Ext.util.Filter'
],


config: {
model: 'app.model.Location',
pageSize: 5000,
storeId: 'LocationViewStore',
proxy: {
type: 'sql',
database: 'DATABASE',
table: 'LOCATION'
},
filters: {
filterFn: function(item) {

var itemLocation = item.data.location; // for example it is NY,LA,CA
var location = app.auth.Session.model().getLocation(); // for example it is NY,LA


// when more location than one is set in usersettings
var splittedLocations = [];
splittedLocations = location.split(",");


splittedLocations.forEach(function(arrayLocation) {
if(arrayLocation == itemLocation){
return itemLocation;
}
});


}
}
}
});

hope you can help me, that I can change the store dynamically.

It is a store for a Selectfield

skirtle
4 Mar 2015, 5:58 PM
The return in your second example is returning from the forEach function, not the filterFn.

kaddah
9 Mar 2015, 4:11 AM
ok thank you, I understand. But how can I do it better?