justinzane
justinzane

Reputation: 1987

How to change request URI in ExtJS 4.1.0 Proxy or Reader

As it is, ExtJS 4.1 with a Rest proxy and a Json reader asks for a URI like this (urlencoded, though):

http://localhost:8000/api/v1/choice/?filter=[{"property":"question_id","value":2}]

my server wants filter requests to look like:

http://localhost:8000/api/v1/choice/?question_id=2

I've looked at the filterParam config for the proxy, but it doesn't seem relevant. Is there a practical way to achieve the request URI that the server needs?

Upvotes: 3

Views: 1766

Answers (2)

justinzane
justinzane

Reputation: 1987

Following ain't pretty, but it works. Now to fix the damn Store...

/**
         * Customized to send ../?prop=val&prop2=val2 urls.
         */
        buildUrl: function(request) {
            var url = this.url;
            var filters = eval(request.params['filter']);
            if (filters) {
                delete request.params['filter'];
                url += '?'
                for (var i = 0; i < filters.length; i++) {
                    var filterString = filters[i].property + "=" + filters[i].value;
                    if (url.slice(url.length-1) === '?') {
                        url += filterString;
                    } else {
                        url += '&' + filterstring;
                    } 
                }
            };
            return url;
        },

Upvotes: 2

sha
sha

Reputation: 17860

There is no simple (easy) way. You will have to extend existing Proxy class. Take a look at the source code for Ext.data.proxy.Proxy and Ext.data.proxy.Server. Start with looking at functions getParams and buildUrl

Upvotes: 1

Related Questions