开发者

ExtJS 4: Changing Store param names

Right now I'm running into a problem where I can't seem to change the param names page, start, limit, and dir for a Ext.data.Store开发者_运维百科.

In ExtJS 3 I could do this:

paramNames : 
{
    start : 'startIndex',
    limit : 'pageSize',
    sort : 'sortCol',
    dir : 'sortDir'
}

I tried adding this configuration to the Ext.data.Store for ExtJS 4 however 'start', 'limit', 'sort', and 'dir' still show up as the default param names. I need to be able to change this as the server side functionality requires these param names. This also causes paging and remote sorting to not work since the param names don't match what the server side resource is expecting.

So is there a new way in ExtJS 4 to change these param names like in ExtJS 3?


take a look at Proxy, see http://docs.sencha.com/ext-js/4-0/#/api/Ext.data.proxy.Server directionParam,limitParam...


To dynamically modify the parameters just before the load of a store you can do this:

/* set an additional parameter before loading, not nice but effective */
    var p = store.getProxy();
    p.extraParams.searchSomething = search;
    p.extraParams.somethingelse   = 'This works too';

    store.load({
        scope   : this,
        callback: function() {
            // do something useful here with the results 
        }
    });


Use this code:

proxy: {
    type: 'ajax',
    url: '/myurl',
    method: 'GET',
    **extraParams: { myKeyword: 'abcd' },**
    reader: {
        type: 'json',
        root: 'rows'
    }
}

Now you can change your myKeyword value from abcd to xyz in following way.

gridDataStore.proxy.extraParams.keyword='xyz';
gridDataStore.load();

this will set your parameters' value and reload the store.


The keys were renamed and moved to the Ext.data.Proxy object. Here's a simple example that tells ExtJS to use the default Grails parameter names:

Ext.create('Ext.data.Store', {
    // Other store properties removed for brevity
    proxy: {
        // Other proxy properties removed for brevity
        startParam: "offset",
        limitParam: "max",
        sortParam: "sort",
        directionParam: "order",
        simpleSortMode: true
    }
});

I also set the simpleSortMode so that each of the parameters are sent to the server as discrete request parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜