Results 1 to 4 of 4

Thread: How to disable JSON-encoding proxy query params?

  1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    16
    Vote Rating
    0
      0  

    Question How to disable JSON-encoding proxy query params?

    Proxy send data as JSON-encoded string param.
    For example:

    [{"property":"order_id","value":5}] (for filter)

    or

    [{"property":"date","direction":"DESC"}] (for sort)

    How to disable it for sending params as raw arrays? Because, i don't want use json_decode() on server-side.

  2. #2
    Ext JS Premium Member stevil's Avatar
    Join Date
    Nov 2007
    Location
    Denver, CO
    Posts
    1,045
    Answers
    15
    Vote Rating
    10
      1  

    Default

    Quote Originally Posted by webleaf View Post
    Proxy send data as JSON-encoded string param.
    For example:

    [{"property":"order_id","value":5}] (for filter)

    or

    [{"property":"date","direction":"DESC"}] (for sort)

    How to disable it for sending params as raw arrays? Because, i don't want use json_decode() on server-side.
    Because I wanted sorting and filtering to work the way they did before 4.0, I did this:

    Code:
    Ext.override(Ext.data.proxy.Server, {
        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,
    
    
                pageParam = me.pageParam,
                startParam = me.startParam,
                limitParam = me.limitParam,
                groupParam = me.groupParam,
                sortParam = me.sortParam,
                filterParam = me.filterParam,
                directionParam = me.directionParam;
    
    
            if (pageParam && isDef(page)) {
                params[pageParam] = page;
            }
    
    
            if (startParam && isDef(start)) {
                params[startParam] = start;
            }
    
    
            if (limitParam && isDef(limit)) {
                params[limitParam] = limit;
            }
    
    
            if (groupParam && groupers && groupers.length > 0) {
    
    
                params[groupParam] = me.encodeSorters(groupers);
            }
    
    
            if (sortParam && sorters && sorters.length > 0) {
                if (simpleSortMode) {
                    params[sortParam] = sorters[0].property;
                    params[directionParam] = sorters[0].direction;
                } else {
                    me.encodeSorters(params, sorters);
                }
    
    
            }
    
    
            if (filterParam && filters && filters.length > 0) {
                // override to support encoding onto the params object itself
                me.encodeFilters(params, filters, 0);
            }
    
    
            // override to allow us to put "static" (non-user-changeable filters)
            // on the request
            if (filterParam && me.staticFilters && me.staticFilters.length > 0) {
                // override to support encoding onto the params object itself
                me.encodeFilters(params, me.staticFilters, filters ? filters.length : 0);
            }
    
    
            return params;
        },
    
    
    
    
        encodeFilters: function (params, filters, startAt) {
            var length = filters.length,
                i = startAt;
    
    
            for (; i < length; i++) {
                params['filter[' + i + '][field]'] = filters[i].property;
                params['filter[' + i + '][data][type]'] = 'string';
                params['filter[' + i + '][data][comparison]'] = 'contains';
                params['filter[' + i + '][data][value]'] = Ext.htmlEncode(filters[i].value);
            }
        },
    
    
        encodeSorters: function (params, sorters) {
            var min = '',
                length = sorters.length,
                i = 0;
    
    
            for (; i < length; i++) {
                min += (i > 0 ? ',' : '') + sorters[i].property + '#' + sorters[i].direction;
            }
    
    
            params["sort"] = min;
        }
    });
    Forgive the formatting of the code - pasted from VS to Notepad and then here, and it won't leave the line breaks alone!

  3. #3
    Sencha User preaction's Avatar
    Join Date
    Sep 2011
    Posts
    22
    Vote Rating
    1
      1  

    Default

    There's an example of this in the docs at http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Ajax

    Basically, you provide your own encodeFilters and encodeSorters functions to do what you want.

  4. #4
    Sencha User alecm's Avatar
    Join Date
    Jul 2009
    Location
    Bratsk, Russia
    Posts
    7
    Vote Rating
    0
      0  

    Default

    This thread is pretty old. But I want to give answer on it anyway.
    There is config option in Ext.data.proxy.Ajax class: sortParam. Set it to undefined or false and it's done.
    Here is example from my code:
    Code:
        proxy: {
            pageParam:  false,
            startParam: false,
            limitParam: false,
            filterParam: false,
            sortParam: false,
            noCache: false,
            type: 'ajax',
            .....
        }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •