PDA

View Full Version : How 'v' in GroupSummary plugin populate



Madhu11
1 Jul 2011, 7:33 AM
I am trying to modify GroupSummary plugin to suit my need. Code for GroupSummary plugin is available in the link below,

http://trac.symfony-project.org/browser/plugins/sfExtjsThemePlugin/web/extjs/examples/grid/GroupSummary.js?rev=5499

The plugin has a function to sum up values in a group

'sum' : function(v, record, field){
return v + (record.data[field]||0);
}I want to sum based on value in another column. So I have written the function below which is adopted from the 'sum'


'sumcredit' : function(v, record, field){
if (record.data.transtype == 'C') {
return v + (record.data[field]||0);
}
}
I have give summaryType: 'sumcredit' in the column where I want to display the total. But I get some value which is not correct. But when I give summaryType: 'sum' I am getting proper total.

So I placed alert (like below) to check how the value of 'v' changes.


'sum' : function(v, record, field){
alert(v);
return v + (record.data[field]||0);
}For 'sum' - I was getting 'v' value as zero the first time. Then, I was getting get the cumulative sum.

For example, if the my values in my column are 100, 150, 50 and 200 the alert message box showed 0, 100, 250, 300... as expected

But when I used alert in 'sumcredit', I was getting random zeros in between each row's value


'sumcredit' : function(v, record, field){
alert(v);
if (record.data.transtype == 'C') {
return v + (record.data[field]||0);
}
}Could someone help me understand how the value for 'v' is populated.

skirtle
5 Jul 2011, 10:34 AM
I'm not familiar with this plugin but it seems to be using the function as an accumulator. Your function won't return a value if transtype isn't 'C', resetting the accumulated value back to 0.

What about something like this?


'sumcredit' : function(v, record, field) {
return v + ((record.data.transtype === 'C' && record.data[field]) || 0);
}