Reputation: 11
I'm trying to load store with params in order to filter my data (as "where" in SQL) however I didn't find how to do that ... Therefore, I made a filter on store load in order to make this but when there are many data, lags appears because it load all data and then filter them.
Is it possible to load store with params ? I tried for example :
store.load({
params: { id : '300'},
});
But it's not working ..
Here is my code; (I'm using ExtJS3.4 in a GroupOffice module (MVC model) that's why you can see "GO.", ... ).
I declare my store
GO.gestionfrais.storeAffichageMesFrais = new GO.data.JsonStore({
url: GO.url('gestionfrais/frais/store'), // URL to my model
fields: ['id',...],
// method: 'POST', // Have I to write this line ?
// read: 'POST',
model: 'GO\\Gestionfrais\\Model\\Frais',
});
Then I created my filter:
GO.gestionfrais.storeAffichageMesFrais.on('load', function(){
GO.gestionfrais.storeAffichageMesFrais.filterBy( function(record, id) {
if(record.get("id_user") == id_currentUser && record.get('archive') == 'Non' ) {
return true;
}
return false;
}, this);
});
And finally I load my store
GO.gestionfrais.storeAffichageMesFrais.load( /*{params ?}*/ );
Thanks for reading me.
I have modify the Store declaration by following mindparse link :
GO.gestionfrais.storeAffichageMesFrais = new GO.data.JsonStore({
// store configs
autoDestroy: true,
url: GO.url('gestionfrais/frais/store'),
storeId: 'storeAffichageMesFrais',
// reader configs
root: 'results',
idProperty: 'results',
fields: ['id', 'id_user', 'user', 'id_resp','demandeur', 'mois', 'prixTotal', {name: 'dateCreation', type: 'date', dateFormat: 'd-m-Y'}, 'etat', {name: 'dateSoumission', type: 'date', dateFormat:'d-m-Y'}, 'archive', {name: 'dateValidation', type: 'date', dateFormat: 'd-m-Y'}], // On récupère les champs qui nous intéressent (soit ceux à afficher).
//Added
model: 'GO\\Gestionfrais\\Model\\Frais',
});
Then I tried to load store with params (id=320) and I can see this in the header :
Query String Parameter
--> r:gestionfrais/frais/store
--> security_token:ITy...Form Data
--> id:320
--> sort:id
--> dir:ASC --> security_token:ITyc ....
My param isn't in "Query String Parameters", is it normal ?
Upvotes: 1
Views: 10565
Reputation: 776
Use proxy configuration to send extra params to your controller :
store.proxy.extraParams = { id1 : '300', id2: '22', ... };
store.load();
Upvotes: 3