tags:

views:

144

answers:

2

Hi all

Is it possible to change the structure of the URL that is created by ExtJS when the baseParams are sent to the server via the dataUrl?

For example, as it stands setting the baseParams as follows:

baseParams: {
    category: 2
},
dataUrl:'testclass.php'

would create the following request string:

testclass.php?category=2

What I want to do is retrieve the data in a restful way like this:

testclass/category/2

Is this URL structure possible with ExtJS? Thanks.

+1  A: 

You could of course, write your own TreeLoader, that would be the only way IIRC.

Lloyd
I thought as much, thanks.
Alan Grant
+1  A: 

I recognize that this is not an ideal solution, and that this question is a bit old, but this code has worked fairly well for me in this venue:

Ext.override(Ext.tree.TreeLoader, {
    requestData : function(node, callback, scope) {
        var originalDataUrl = this.dataUrl;
        this.dataUrl += "/" + this.getParams(node).node;
        if(this.fireEvent("beforeload", this, node, callback) !== false){
            if(this.directFn){
                var args = this.getParams(node);
                args.push(this.processDirectResponse.createDelegate(this, [{callback: callback, node: node, scope: scope}], true));
                this.directFn.apply(window, args);
            }else{
                this.transId = Ext.Ajax.request({
                    method:this.requestMethod,
                    url: this.dataUrl||this.url,
                    success: this.handleResponse,
                    failure: this.handleFailure,
                    scope: this,
                    argument: {callback: callback, node: node, scope: scope}
                    //params: this.getParams(node)
                });
            }
        }else{
            // if the load is cancelled, make sure we notify
            // the node that we are done
            this.runCallback(callback, scope || node, []);
        }
        this.dataUrl = originalDataUrl;
    }
});

Really, the only big downside is the complete lack of params when you go down this road. In my case, I only needed the node ID ever. But this should at least give you a good starting point if you want to override your load method! :)

Chris Rueber
Cheers for this, I haven't yet got around to adding this feature and this will deffo come in handy for it. Ta.
Alan Grant