开发者

How do I stop ext-js from adding limit=25 to my JSON query?

开发者 https://www.devze.com 2023-02-15 09:47 出处:网络
The following code is working. The problem is the request is being sent with &_dc=1299207914646&limit=25 appended to every request sent to the server. Nothing I can do changes the limit=25. Id

The following code is working. The problem is the request is being sent with &_dc=1299207914646&limit=25 appended to every request sent to the server. Nothing I can do changes the limit=25. Ideally I want no additional parameters sent to the server. I would make do however with being able to set the limit to 10000 or something. I AM able to add other parameters but nothing I do removes the limit=25. I would also like to get rid of the &_dc parameter although I don't know why it has been added it is not causing a problem.

Any ideas?

note: some weird problem with code formatting below?

Thanks

    Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.panel.*'
]);
Ext.onReady(function(){
    Ext.regModel('Image_', { // window.Image is protected in ie6 !!!
        fields: ['id', 'key', 'value']
    });    

var store = new Ext.data.JsonStore({
        model: 'Image_',
        proxy: {
            type: 'ajax',
var store = new Ext.data.JsonStore({
        model: 'Image_',
        proxy: {
            type: 'ajax',
            autoload: 'false',
            url: '/couchdb/test/_design/blah/_view/by_surname2?startkey=%22r%22&endkey=%22r\u9999%22',
            reader: {
                type: 'json',
               root: 'rows'
                    }
        }
    });
    store.load();




    var listView = new Ext.grid.GridPanel({
        width:425,
        height:250,
        collapsible:true,
        title:'Simple ListView <i>(0 items selected)</i>',
        renderTo: Ext.getBody(),

        store: store,
        multiSelect: true,
        viewConfig: {
            emptyText: 'No images to display'
        },


        headers: [{
            text: 'File',
            flex: 50,
            dataIndex: 'value'
        },{
            text: 'Last Modified',
            flex: 开发者_JAVA技巧35, 
            dataIndex: 'key'
        },{
            text: 'Size',
            dataIndex: 'id',
            flex: 15,
            cls: 'listview-filesize'
        }]
    });

    // little bit of feedback
    listView.on('selectionchange', function(view, nodes){
        var l = nodes.length;
        var s = l != 1 ? 's' : '';
        listView.setTitle('Simple ListView <i>('+l+' item'+s+' selected)</i>');
    });
});


In your Proxy, set

limitParam: undefined,
pageParam: undefined,
startParam: undefined,
noCache: false,


You can modify your store limit when you load the store.

store.load({params:{limit:50}});

In this case, I am asking to set the limit to 50. _dc=1299207914646 is unique cache-buster param added to GET requests. If you don't want to have them in the url, you can disable them by setting disableCaching parameter to false.

But I would recommend you to set the method of you store to POST and pass the parameters using POST rather than GET method. That way you can have clean URLs and also hide the data being sent.


You can override getParams method of the Ext.data.proxy.Server.

For example, in my project I added custom boolean parameter embeddedParams and if I dont want to add ExtJS parameters to a request I set it to false in a store proxy:

/**
 * Added embeddedParams option
 */
Ext.define('Ext.lib.overrides.ServerProxy', {
    override: 'Ext.data.proxy.Server',

    /**
     * Add or not pagination, grouping, sorting and filtering parameters to the request. Defaults to true.
     */
    embeddedParams: true,

    /**
     * @private
     * Copy any sorters, filters etc into the params so they can be sent over the wire
     */
    getParams: function (operation) {
        var me = this,
            params = {},
            isDef = Ext.isDefined,
            groupers = operation.groupers,
            sorters = operation.sorters,
            filters = operation.filters,
            page = operation.page,
            start = operation.start,
            limit = operation.limit,
            simpleSortMode = me.simpleSortMode,
            simpleGroupMode = me.simpleGroupMode,
            pageParam = me.pageParam,
            startParam = me.startParam,
            limitParam = me.limitParam,
            groupParam = me.groupParam,
            groupDirectionParam = me.groupDirectionParam,
            sortParam = me.sortParam,
            filterParam = me.filterParam,
            directionParam = me.directionParam,
            hasGroups, index;

        if (me.embeddedParams && pageParam && isDef(page)) {
            params[pageParam] = page;
        }

        if (me.embeddedParams && startParam && isDef(start)) {
            params[startParam] = start;
        }

        if (me.embeddedParams && limitParam && isDef(limit)) {
            params[limitParam] = limit;
        }

        hasGroups = me.embeddedParams && groupParam && groupers && groupers.length > 0;
        if (hasGroups) {
            // Grouper is a subclass of sorter, so we can just use the sorter method
            if (simpleGroupMode) {
                params[groupParam] = groupers[0].property;
                params[groupDirectionParam] = groupers[0].direction || 'ASC';
            } else {
                params[groupParam] = me.encodeSorters(groupers);
            }
        }

        if (me.embeddedParams && sortParam && sorters && sorters.length > 0) {
            if (simpleSortMode) {
                index = 0;
                // Group will be included in sorters, so grab the next one
                if (sorters.length > 1 && hasGroups) {
                    index = 1;
                }
                params[sortParam] = sorters[index].property;
                params[directionParam] = sorters[index].direction;
            } else {
                params[sortParam] = me.encodeSorters(sorters);
            }

        }

        if (me.embeddedParams && filterParam && filters && filters.length > 0) {
            params[filterParam] = me.encodeFilters(filters);
        }

        return params;
    }
});

Usage:

store: Ext.create('Ext.data.Store', {
    ...
    proxy: {
        ...
        type: 'ajax', // or 'direct', 'jsonp' / 'scripttag'
        embeddedParams: false
    }
})


add the limit property to your store...

  limit:50,

and might not hurt to try pagesize....

  pagesize:50

and see if either of these help.

Edit : also try

 pageParam:undefined,

in your proxy.

found that last piece from...

http://www.sencha.com/forum/showthread.php?118445-CLOSED-1.0.1-Ext.data.JsonStore-quot-limit-quot-param-issue


You can modify the limit param using

store.proxy.limitParam=null;


To remove the _dc parameter on extjs 4 you can set:

noCache: false

or just uncheck the box if you're using architect 2.


Specifically for Json, to get rid of _dc parameter, in your proxy object, set the config option given by Tharahan:

proxy: {
    type: 'ajax',
    api: {
           read: 'app/data/something.json',
           update: 'app/data/something.json'
       },
    reader: {
        type: 'json',
        ...
    },
    writer: {
        type: 'json',
        ...
    },
    noCache: false
}

EDIT: (sorry, I did not look at the post date, but lost so much time with it) Please note that the global Ext.Loader.setConfig({disableCaching: false}); does not affect subclasses of Ext.data.proxy.Server which need this specific option (at least in development with sencha touch 2.2.0).

0

精彩评论

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