View Full Version : Multiple URLs in one Ext.data.Store

4 Oct 2011, 8:30 PM
This might be a noobish question but I haven't seen a solution in my searching:

Is it possible to have multiple URLs in one Ext.data.store so that the different CRUD actions can operate on their corresponding URL? I have build a restful applications that uses the URI and HTTP Request to decide what action to take. For example a GET request to http://www.example.com/path/to/customer.json will return a json object of all customers, while a GET to http://www.example.com/path/to/customer/24.json will return a json object of customer 24. A POST request to http://www.example.com/path/to/customer will add a new customer and a PUT command to http://www.example.com/path/to/customer/24 will update customer 24.

Here is an example of my store to get the list

store : new Ext.data.Store( {
model : 'app.models.Customers',
getGroupString : function(record) {
return record.get('lastName')[0];
autoLoad : true,
proxy : {
type : 'ajax',
url : '/path/to/customers.json',
reader : {
type : 'json',
root : 'attendeesSet'
I need to be able to perform all CRUD operations on a customer but setting different URLs for each operation. That way I can send the proper request to the proper URI in my restful system and get the desired results.

Any suggestions?

4 Oct 2011, 11:55 PM
Hi, you can set the url in this way:

yourStore.proxy.url = "yourServiceUrl";

5 Oct 2011, 4:45 AM
That's not quite what I need. I'm lookin to have multiple URLs associated one store so that the correct the correct one is used when needed. Or are you saying I should change the store URL on the fly when I need to? Is that possible?

5 Oct 2011, 4:59 AM
Or are you saying I should change the store URL on the fly when I need to? Is that possible?

That is, the above code is intended to be used on the fly.

5 Oct 2011, 6:52 AM
I needed the same when i used list who call different JsonFile for each Item for create a new List
different Jsonfile was call with extraParams.
I explain:

in my controller:

showDirectoryCategoryList: function(options) {
var data = options.data;
WPApp.views.DirectoryPanel.setActiveItem(WPApp.views.DirectoryCategoryListPanel, {type: 'slide'});

I set an ID, each Item of my list have an ID.
After in my Store:

WPApp.stores.DirectoryCategoryListStore = new Ext.data.Store({
model: "WPApp.models.DirectoryCategoryListModel",
storeId: 'DirectoryCategoryListStore',
proxy: {
type: 'ajax',
url: "/getCategoryList.php",
reader: {
type: 'json'
setId: function (id) {
this.itemId = id;
autoLoad: true

With that, it's the same like if i send the URL:

url: "/getCategoryList.php?id=1"
if i tap on Item 1
And you can make a good treatment with $_GET in php for each item, call the good request or JSON File.

It's only a way, i think, there is better, i just do like that and it's working.

Hope this help you

9 Mar 2012, 7:05 AM
That is, the above code is intended to be used on the fly.

This appears to be the only way to do this, which means in an MVC application the controller is responsible for changing the URL on the proxy. IMO this is bad design as the controller should not have to know the implementation of the store, or even that an ajax proxy is being used (it may be a memory store, local storage, etc.) It seems to me that a better store class is needed with the ability to have multiple URLs as I see this as a very standard approach. One other possibility is to add methods on the store that at least hide the implementation of changing the URL, so perhaps the controller could call store.setUpdateMode() or something like that. Still not sure I like that either though.