PDA

View Full Version : Json Data Store Questions



dcipher
10 Nov 2009, 1:23 PM
Hi

I am attempting my first extJS applications so this is basically a learning project. I have attached a file containing a short example where I want to load a listview from a json data store. The listview is rendered by without showing any rows. It does correctly call the url and data is returned. So I have the following questions:

1) How should the params object be configured that is passed to the store load() method?
2) Are the name/value a pairs in the params object just turned into query string parameters
3) Do I required a callback function to load the listview or is that done automatically? If it is not done automatically how should it be done?

Thanks
Simon

piyushjain7
10 Nov 2009, 1:48 PM
Your code looks ok. I think the only problem is in the width you specified for the columns, 0.2 and 0.3 doesn't make sense. Rather try 100, 200.

dcipher
10 Nov 2009, 6:50 PM
The column widths are correct because they are supposed to be expressed as a percentage of the total width so .2 represents 20% and the .8 represents 80%. I could have left one column undefined and it would automatically be assigned the remainder.

So something else is missing in my code.

Simon

nicobarten
11 Nov 2009, 3:00 AM
guess you need also 'totalProperty' in your jsonStore like this:



var upmenu_json = new Ext.data.JsonStore({
url: 'http://localhost/cisaa/loadmenu.dcjs?',
root: 'rows',
totalProperty: 'total',
fields: ['id','no','item', 'desc']
});
Then you can use the following Json:

{"total":"2","rows":[{"id":"1","no":"15","item":"item1","desc":"description1"},{"id":"2","no":"16","item":"item2","desc":"description2"}]}

In 'total' you set how many rows you give to the store.

dcipher
11 Nov 2009, 8:26 AM
The totalProperty makes no difference. So something else is wrong.

Simon

carol.ext
11 Nov 2009, 8:39 AM
Is the json coming from a different domain? If not, why are you not using a relative url? If so, you'll need to use ScriptTagProxy (http://www.extjs.com/deploy/dev/docs/?class=Ext.data.ScriptTagProxy). Read the doc carefully!

Added note: next time just post your code in code tags, you will get more people looking at it; the Help Guide (http://www.extjs.com/learn/Ext_Forum_Help) describes how to do it.

dcipher
11 Nov 2009, 9:11 AM
I am not using relative url for the data if that is what you are referring to.

I am using relative URL for the javascript files because my application will be used by a number of clients on different servers so the url might be different but the application structure will always be the same.

For test purposes I was using FireFox to open the Index.htm file from the file system instead of using a http request.

I will setup a test website and see if there is any difference.

Thanks for the tip about code tags.

Simon

carol.ext
11 Nov 2009, 9:24 AM
I am not using relative url for the data if that is what you are referring to.
...
For test purposes I was using FireFox to open the Index.htm file from the file system instead of using a http request.


Yes, that would be a problem.

dcipher
11 Nov 2009, 10:51 AM
I changed my setup so that I actually load the page using a http request in the browser and everything works perfectly. So the problem was due to cross domain urls.

Thanks for pointing me in the right direction regarding the cross domain urls.

Simon