PDA

View Full Version : [FIXED-607] HybridSummary bug with Field mapping



aedos
19 Feb 2010, 10:50 AM
ExtJs 3.1.

I'm using Ext.ux.grid.HybridSummary to read summary data from json data. Based on the doc, the json data would look like:


{
data: [
{
projectId: 100, project: 'House',
taskId: 112, description: 'Paint',
estimate: 6
},
...
],

summaryData: {
'House': {
description: 14, estimate: 9
}
}
}
However when the store Field has mapping defined, for example:


fields: [
'projectId',
{name:'foo', mapping:'description'},
...
]
The summaryData will not work. Instead HybridSummary will expect something like the following, which looks totally unintuitive. So I think it's a bug.


{
data: [
{
projectId: 100, project: 'House',
taskId: 112, description: 'Paint',
estimate: 6
},
...
],

summaryData: {
'House': {
foo: 14, estimate: 9
}
}
}
Workaround:

I'm currently overriding getSummaryData() method of HybridSummary to work around the bug.
It invokes "this.grid.getStore().reader.readRecords(...)" to parse the json summary data, to handle Field Mapping properly. However, it's a bit overkill (since readRecords() is used to handle a block of multiple records and expects the root property if the store has a "root" configured.) and has a side effect of erasing the old jsonData from the reader.

Any better ideas?

A fix in the out-of-the-box code would be highly appreciated.

evant
21 Feb 2010, 5:31 AM
How about this?



Ext.override(Ext.ux.grid.HybridSummary, {
getSummaryData : function(groupValue){
var reader = this.grid.getStore().reader,
json = reader.jsonData,
fields = reader.recordType.prototype.fields,
v;

if(json && json.summaryData){
v = json.summaryData[groupValue];
if(v){
return reader.extractValues(v, fields.items, fields.length);
}
}
return null;
}
});

aedos
22 Feb 2010, 1:41 PM
Thanks, Evan! This is definitely better than my original version.

I missed extractValues as part of public reader API, because it's exposed as "Properties" rather than "Methods" in the API doc. So, it's safe to assume the method signature even though it's not in the Doc, right?

Any plan to fix it in the ootb product?

evant
22 Feb 2010, 4:57 PM
Yep, it's been fixed in SVN.