json - Overriding default parameter names in ExtJS 4 Store -
i'm trying override default parameter name limitparam in proxy store. want make jsonp call http://search.twitter.com/search.json?q=kathmandu&rpp=2 instead of setting rpp directly want map limitparam , set it's value. it's not setting through limitparam. reason i'm doing parameter keys store sends (sort, dir, etc) not match parameters on server side (which i've no control over). in advance.
ext.require('ext.grid.view'); ext.require('ext.util.point'); ext.application({ name: 'helloext', launch: function() { /*ext.create('ext.container.viewport', { layout: 'fit', items: [ { title: 'hello ext', html : 'hello! welcome ext js.' } ] });*/ console.log('ok1'); ext.define('video', { extend: 'ext.data.model', fields: ['from_user', 'from_user_id'] }); var mystore2 = ext.create('ext.data.store', { model: 'video', storeid : 'restfulstore', proxy: { type: 'jsonp', url : 'http://search.twitter.com/search.json?q=kathmandu', reader: { type: 'json', //root: 'data.items' root: 'results' }, limitparam: 'rpp', pageparam: 'page' }, listeners: { load: function(store, records) { ext.each(records, function(rec) { console.log(rec.get('from_user')); }); } }, sorters: [{ property: 'from_user', direction: 'desc' }, { property: 'from_user_id', direction: 'asc' }], //autoload: true, remotesort: true }); var p = mystore2.getproxy(); p.limitparam = 2; mystore2.load(); console.log('loads anyway??? loaded store ...'); ext.create('ext.grid.panel', { title: 'restful grid', store: ext.data.storemanager.lookup('restfulstore'), columns: [ {header: "from user", width: 200, sortable: true, dataindex: 'from_user'}, {header: "from user id", width: 200, sortable: true, dataindex: 'from_user_id'} ], height: 400, width: 400, renderto: ext.getbody() }); console.log('store loaded!!'); } });
your proxy configuration fine want do. problem in way load store. should not change limitparam
config option name of param. affect number of results, use limit
option of load method, can configure in store pagesize
option.
so, remove this:
var p = mystore2.getproxy(); p.limitparam = 2;
and instead, use limit
option when loading store:
mystore2.load({ limit: 2 });
alternatively, can set in store config pagesize
option:
ext.create('ext.data.store', { // ... pagesize: 2 ,autoload: true });
you can mix both setting default pagesize
, , changing @ loading time limit
.
as side note, tweeter api doesn't seem support sorting, sorters
configuration won't have effect on returned results. should switch remotesort
false
have returned results sorted on client side according configuration.
Comments
Post a Comment