View Full Version : A way to obtain the actual URL that a store uses for its load operation?

4 Oct 2011, 8:11 PM
Hi all,

Which would be the best way to obtain the actual URL that a store uses on its load method? the thing is that the URL is being appended with lots of parameters for filters, sorters, etc while the grid is being used, and I have lots of actions for export to pdf, xls, rss, etc.

Basically, I want to press a button and, on the handler, get a reference to the store of the grid and, somehow, obtain the URL the store would use to load the grid at that moment, with all the actual filters, sort information, etc. With that URL I'm happy, but I don't know how to obtain it. I went through the source code, specifically to the AbstractStore.load method, which seems to create an Ext.data.Operation object, and then it passes it to the Proxy.read method. I guess it builds the final URL there, but I can't figure it out how to obtain it with a simple store reference.

Any help will be greatly appreciated.

Thanks in advance!

5 Oct 2011, 6:04 AM
Fetching the URL is handled by the buildUrl (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.proxy.Server-method-buildUrl) method of the store's proxy, but since that method requires an Ext.data.Request built by the proxy, here's what I think I'd do:

// assuming var store is your store

var operation = Ext.create('Ext.data.Operation', {
action : 'read',
filters: store.filters.items,
sorters: store.getSorters()

var url = store.getProxy().buildRequest(operation).url;

(Disclaimer: This is just top-of-my-head; I haven't actually tested to see if it works.) This is all assuming your proxy is a subclass of Ext.data.proxy.Server (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.proxy.Server), of course.

5 Oct 2011, 7:07 AM
First of all, thanks a lot for replying!

I did try your example, and the URL is generated, but the problem is that it doesn't contain the parameters I need. Not even the sorters are appended to the URL. It just generates the read URL configured in the api of the proxy (it's the rest proxy).

What could be wrong?

Thanks again for your help!

5 Oct 2011, 7:13 AM
Oh, that's right - the request parameters aren't combined with the URL until the request is processed. So I guess it should actually be something like this:

var request = store.getProxy().buildRequest(operation);
var url = request.url + '?' + Ext.Object.toQueryString(request.params);

Does that work for you?

5 Oct 2011, 7:19 AM
Yes, it worked like a charm! thanks a lot for your help!

BTW: Maybe there should be a method to simplify this process? it's a common need the use case of exporting exactly the same view of the grid to other formats, and using the same URL but adding a parameter (or, in my case, changing the format from json to whatever format I need to export) seems to be a common way to do it.

Again, thanks a lot!