PDA

View Full Version : multiple json readers in datagrid plugin?



wigwam_salesman
13 Sep 2010, 10:03 AM
Is it possible to have multiple arrays of data read in? For example:

reader: new Ext.data.JsonReader({
root: "Data1",
id: "uid"
},['uid','TESTING'] ),
root: "Data2",
id: "uid"
},['uid','ACCOUNTNUMBER'] ),
)

Condor
13 Sep 2010, 11:30 PM
Do you want to merge this data in a single store or would this be for separate stores?

wigwam_salesman
14 Sep 2010, 12:22 AM
I want to merge it into a single store.

Condor
14 Sep 2010, 12:37 AM
And TESTING and ACCOUNTNUMBER should become the same field?

ps. Are you really using Ext 2.x? This is easier to solve in Ext 3.

wigwam_salesman
14 Sep 2010, 12:47 AM
Sorry, I've explained this badly.

When I pass my data into my jsonreader as such:

return json_encode(array('success'=> true, 'Data'=> $data1, 'Data2' => $data2, 'total' => $rowcount));

I then need to access all of the data in those arrays in desktop.js at this point:

reader: new Ext.data.JsonReader({

Would it be easier to combine the data being sent to the reader into one array instead of sending 2?

Condor
14 Sep 2010, 1:31 AM
Which fields do Data and Data2 contain? If the fields in Data and Data2 are not the same (like in your example), how should they be included in the same store?

wigwam_salesman
15 Sep 2010, 4:26 AM
I now have my array that is sent to the json_reader as follows:

Array (
[0] => Array (
[ACCOUNTNUMBER] => example
[color_code] => #example
[COMPANYNAME] => example
[PAGEVIEWSMTD] => example
[PAGEVIEWSYTD] => example
[TARGETMTD] => example
[TARGETYTD] => example
[ACTUALMTD] => example
[ACTUALYTD] => example
[DIFFERENCEMTD] => example
[DIFFERENCEYTD] => example
[PERCENTAGEMTD] => example
[PERCENTAGEYTD] => example
[POINTSMTD] => example
[POINTSYTD] => example
[POINTSUNCLEARED] => example
[POINTSAVAILABLE] => example
[REGIONNAME] => example
[ACCOUNTMANAGERNAME] => example
)
[1] => Array (
[SUMTOTALACCOUNTS] => example
[SUMPAGEVIEWSMTD] => example
[SUMPAGEVIEWSYTD] => example
[SUMTARGETMTD] => example
[SUMTARGETYTD] => example
[SUMACTUALMTD] => example
[SUMACTUALYTD] => example
[SUMDIFFERENCEMTD] => example
[SUMDIFFERENCEYTD] => example
[SUMPERCENTAGEMTD] => example
[SUMPOINTSMTD] => example
[SUMPOINTSYTD] => example
[SUMUNCLEAREDPOINTS] => example
[SUMAVAILABLPOINTS] => example )
)

I am confused why I can do this and get a result:

SUMTOTALACCOUNTS : function(v, record, colName, data, rowIdx) {
return tx_lsyssalesdetails_pi1.customerstore.reader.jsonData.Data[0].ACTUALMTD;
},

but the following produces no result on screen?

SUMTOTALACCOUNTS : function(v, record, colName, data, rowIdx) {
return tx_lsyssalesdetails_pi1.customerstore.reader.jsonData.Data[1].SUMTOTALACCOUNTS;
},

Condor
15 Sep 2010, 4:39 AM
Is this PHP? Can you post what this code actually generates (copy from the Firebug Net tab)?

So Data[1] contains the summary of the previous records? You could merge the 2 data arrays in a root function (so instead of root:'Data[0]' you write a function).

But wouldn't it be better to use a HybridGridSummary for that (needs a small change to read the summary from Data[1] instead of summaryData, but that's easy)?

wigwam_salesman
15 Sep 2010, 4:56 AM
I have resolved the situation by sending the summary data as a separate array, thanks.