PDA

View Full Version : Store rebuid url with parameters



iooK
18 Oct 2012, 9:14 AM
Hello all,

I want to retrieve all parameters of a store to recreate my own uri.
Please take a look of my store :


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

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'listeArticleStore',
remoteFilter: true,
remoteSort: true,
pageSize: 50,
proxy: {
type: 'ajax',
pageParam: 'p',
url: '/XmlView/ListeArticle',
reader: {
type: 'xml',
idProperty: 'ART_ID',
totalProperty: 'totalProperty',
record: 'row'
}
},
fields: [
{mapping: 'ART_ID', name: 'ART_ID', type: 'int'},
{mapping: 'ART_LIBELLE', name: 'v_art_articles_formats.art_libelle', type: 'string'},
{mapping: 'ART_CODE_ALTIUS', name: 'v_art_articles_formats.art_code_altius', type: 'string'},
{mapping: 'ART_MILLESIME', name: 'v_art_articles_formats.art_millesime', type: 'string'},
{mapping: 'ART_AGE', name: 'v_art_articles_formats.art_age', type: 'string'},
{mapping: 'FOR_CL', name: 'v_art_articles_formats.for_cl', type: 'string'},
{mapping: 'STOCK_PANIERS', name: 'v_art_stock_paniers.stock_paniers', type: 'int'},
{mapping: 'STOCK_RAYON', name: 'v_art_stock_rayon.stock_rayon', type: 'int'},
{mapping: 'STOCK_RESERVE', name: 'v_art_stock_reserve.stock_reserve', type: 'int'},
{mapping: 'STOCK_TOTAL', name: 'v_art_stock_total.stock_total', type: 'int'},
{mapping: 'PRO_ID', name: 'PRO_ID', type: 'int'},
{mapping: 'ART_EN_LIGNE', name: 'ART_EN_LIGNE', type: 'boolean'}
]
}, cfg)]);
}
});


Url is '/XmlView/ListeArticle', when this store is called, plenty of parameters are sent with it (thanks to POST method).
The page parameter named 'p' or a user search named 'my_search' in my application, ....

I would like to rebuild a uri with this parameters thanks to GET method like this example '/XmlView/ListeArticle?p=1&limit=25&my_search=wine&...'
I want to do this to create an excel extract with the same parameters of my gridpanel.

Thanks in advance.

nb: Sorry for my poor english.

mitchellsimoens
23 Oct 2012, 6:25 AM
Why are you trying to create your own url? THe url can be built auto for you and you can change the param names

James Goddard
23 Oct 2012, 7:02 AM
What he is trying to do is call a different service based on the parameters the store is using.

For example, if he fills his store with:

/xyz/?page=X&start=Y&limit=Z&sort=field1&dir=ASC

He wants to call an Excel export service with the same paremters (probably from an iframe so he can download the excel file without replacing his workspace):

/xyz/export/?page=X&start=Y&limit=Z&sort=field1&dir=ASC&format=excel


To do this you're going to need to do a little work on your own. There is no "store.getParams" function. First if you look at the load function on store you'll see:



options.groupers = options.groupers || me.groupers.items;
options.page = options.page || me.currentPage;
options.start = (options.start !== undefined) ? options.start : (options.page - 1) * me.pageSize;
options.limit = options.limit || me.pageSize;
options.addRecords = options.addRecords || false;


That should show you where to get grouping and paging params. The filters and sorters come from the AbstractStore load function:



options = Ext.apply({
action: 'read',
filters: me.filters.items,
sorters: me.getSorters()
}, options);


With those you should be able to build an object with the appropriate properties. From there a simple Ext.Object.toQueryString should do.