PDA

View Full Version : Ext.data.DirectStore making me crazy



danellison
28 Jan 2010, 2:43 PM
Hi folks. I have been working a bit with Ext.Direct of late. I love the easy access to PHP methods on the backend. Initially I always used a JsonStore with an Ext.Direct call to load the data via a callback handler as shown in the code block below:



var store = new Ext.data.JsonStore({
fields: [ 'projects_projectid'],
data: []
});

function fillMyData(resp, e) {
var json = Ext.util.JSON.decode(resp);
if(json.success) {
store.loadData(json.data);
} else {
alert(json.error);
}
}

ICCI.ICCI.getMyProjects(fillMyData, this);



This method works fine but soon you are writing the same handler code over and over.... So I decided to dive into the DirectStore to see if I could get around the callback overhead. After hours of attempting to successfully load data into an Ext.data.DirectStore, reading every post I could find and tracing into ext-all-debug I have turned to the forum for an answer. My Ext.Direct store declaration is as follows:



var store = new Ext.data.DirectStore({
autoLoad: true,
api: {
read: ICCI.ICCI.getMyProjects
},
paramsAsHash: false,
fields: ['projects_projectid'],
root: 'data',
idProperty: 'projects_projectid',
totalProperty: 'total',
successProperty: 'success',
messageProperty: 'error',
listeners: {
'exception': function(proxy, type, action, options, res, arg) {
alert("exception: "+arg);
},
'load': function(proxy, type, action, options, res, arg) {
alert("load: "+arg);
}
}
});


With a DirectStore I get an exception event in ext-all.js: root is undefined. Clearly, root is defined in my store declaration. I cannot find a solution. Anybody see anything wrong with my store definition? Anybody shed any light on the problem?

I found an override that didn't help. Ideas? inquiring mind is worn out trying but I still need to know.

Many thanks,
Dan

cerad
28 Jan 2010, 6:22 PM
Which override did you try? This one?
http://www.extjs.com/forum/showthread.php?t=84398

I understand your frustration. It will probably get worse when you try tackling updating the stores. It's a real shame that such a fine concept was so poorly implemented and rushed out the door without testing.

But the end does justify the journey.

ishobr
28 Jan 2010, 7:30 PM
Reply from your server side backend must be like this:




$ret = array('success' => true, 'total': your_data_total_count, 'data' => array_of_your_data);
return $ret;



You can use Firefox+Firebug as tool to help you solving your problem.

danellison
29 Jan 2010, 6:37 AM
Which override did you try? This one?
http://www.extjs.com/forum/showthread.php?t=84398

I understand your frustration. It will probably get worse when you try tackling updating the stores. It's a real shame that such a fine concept was so poorly implemented and rushed out the door without testing.

But the end does justify the journey.

Yes, that is the one I tried without success. Updating the store is different than using any other Ext store? Won't be an issue if I can't get the store loaded to begin with.

Dan

danellison
29 Jan 2010, 6:39 AM
Reply from your server side backend must be like this:




$ret = array('success' => true, 'total': your_data_total_count, 'data' => array_of_your_data);
return $ret;



You can use Firefox+Firebug as tool to help you solving your problem.

Yes, I am using FF+FB - couldn't survivie without them. Are you saying that my backend should not return JSON but a true array? Let me try that.

YES! That was all that did it. Puzzling. I certainly didn't catch a clue that the router would process a native php array. Thank you very much.

Dan

cerad
29 Jan 2010, 1:05 PM
Yes, that is the one I tried without success. Updating the store is different than using any other Ext store? Won't be an issue if I can't get the store loaded to begin with.

Dan
Updating the store itself is fine but any failure message in the response is ignored so your store can end up getting out of sync with your database. Another bug report shows a fix for it.