PDA

View Full Version : Getting data for several JsonStores with one request



pest
20 Jan 2011, 4:41 AM
Hi there!

I have a locigal question. I tried and searched now for several days and it doesn't work. Perhaps someone in the forum can help me out.

I want to load some data for a histogram chart from a database. The execution time of the query can be pretty high. That's why I want to get all data from my model and not only the bars.

What kind of information do I collect?

1: The histogram itself. Some like
{"Dauer":0,"Anzahl":1},{"Dauer":2,"Anzahl":1},{"Dauer":18,"Anzahl":3} ...
2. Data to specify the histogram
StartDate,
EndDate,
MinDauer,
MaxDauer
Stepwidth
I had the idea to embed the different results into one resultset, like


{"total":4, //totalProperty of general request
"result": //root of general
{"histogramm":[ //root of histogram
{"Dauer":0,"Anzahl":1},
{"Dauer":2,"Anzahl":1},
{"Dauer":18,"Anzahl":3}],
"totalbars":3, //totalProperty of histogram
"formdata": //root of form data
{"StartDate":-1,
"EndDate":-1,
"MinDauer":1.97,
"MaxDauer":20.20,
"Stepwidth":2.53
},
"totalform":5 //totalProperty of form data
}
}
I tried to load all data by one JsonStore and to distribute the collected data to specialiced JsonStores.



var histogrammstore = new Ext.data.JsonStore({
root: 'histogramm',
totalProperty: 'totalbars',
fields: ['Dauer', 'Anzahl']
});

var formstore = new Ext.data.JsonStore({
root: 'formdata',
totalProperty: 'totalform',
fields: ['StartDate','EndDate','MinDauer','MaxDauer','Stepwidth']
});

var generalstore = new Ext.data.JsonStore({
root: 'result',
totalProperty: 'total',
url: '<?php echo url_for('modul/HistogrammSQL?id='.$modul->getId()) ?>',
autoLoad: true,
fields: ['histogramm', 'totalbars', 'formdata', 'totalform'],
listeners: {
load: function ()
{
var data = generalstore.reader.jsonData;
histogrammstore.loadData(data); //********* ERROR ***********
formstore.loadData(data);
}

}
});

... (other code)
Everything works fine until the execution reached the line marked with "ERROR".

Firebug delivers the message:

root is undefinedvar root = this.getRoot(o), c ...th, totalRecords = c, success = true;

I have tried a lot of other combinations of these datasets without success. Can anyone of you tell me if this kind of behaviour is realizable?

I'm using ExtJS 3.3.1.

Thanks in advance!

Peter

20 Jan 2011, 4:59 AM
I think that generalstore.reader.jsonData; points to generalstore's root. That's most likely why you're getting the exception. A simple breakpoint would do the trick here.

pest
20 Jan 2011, 5:07 AM
Hi jgarcia!

Thanks for your reply.



I think that generalstore.reader.jsonData; points to generalstore's root.


That's exactly my thought. Generalstore's root is "result" and so these are my 4 datasets for histogram and form.
I already tried to read the raw data at that point, but I wasn't able to find a method to access the data.

Peter

pest
21 Jan 2011, 12:44 AM
Isn't there anybody to help me?

21 Jan 2011, 5:17 AM
if you're going to go through that trouble, why not just use an ajax request, which loads all the stores with the inbound payload?

pest
21 Jan 2011, 5:27 AM
If I understand you right you mean that an ajax request should activate all stores to load the data.

The problem here is that each request has it's own database connection. So I would have to do the query another time.

Meanwhile I realized it via session handling, but it's not so nice...