View Full Version : Question on Howto handle Datastores

7 Aug 2010, 2:42 PM

I got the following function:

function returnDstore(url,colums,id,root,init){
var store = new Ext.data.Store(
url: url,
reader: new Ext.data.JsonReader(
root: root,
id: id
if(init == true){store.load();}return store;

This makes it easier for me to create a new data Store, as all my data stores are identic.

Here's the function I'm workin on:

function submitChange(id){
var cfg = [
{name: 'status'}
var store = returnDstore('<?=$this->link('Workbench','rpc',array('mode'=>'customer','section'=>'updateStatus','id'=>''))?>' + id,cfg,'tid','rows',true);
Wenn alert fires, the store isn't yet loaded.
I tried following:

store.on = { 'load': function(){alert(store.getCount);}};
I don't really get an error message, but the event is never fired.
I need this, because the script handels an update inside a grid.
It should update an icon if another icons is clicked (an row operation)
The part, where this function is called works quite well,
only the update Part isn't workin.
I also tried to insert an delay, but that didn't really help.
I'm not really brand new to javascript.
A lot of stuff is identic to php.
Some stuff is new.
But I don't get the clue that is behind the data stores.
It would be really great, if someone could help me.

8 Aug 2010, 10:10 PM
1. To avoid confusion you should call the fields 'fields' and not 'colums' (a record has fields - a grid has columns).
2. Loading is asynchronous. You have to wait for the server to send back the response before you can examine the record count.
3. You do this by using the load callback or the load event handler, but the syntax is:

store.on('load', function(){alert(store.getCount());});
4. I would recommend to also add an 'exception' handler to see if your server is returning the data correctly.