PDA

View Full Version : Function in "groupTextTpl"



Tinki
23 Jun 2009, 12:37 AM
Is it possible to insert a function into groupTextTpl? I want it look like this:



function countTotal(records){
var totalSum = 0;
for (i=0;i<records.length;i++){
totalSum += records[i].get('docAmount');
}
return totalSum;
}
............
groupTextTpl: '{gvalue}, bla-bla-bla: {[countTotal(values.rs)]}'
............


Just need an asumming value in the header of the row.

Condor
23 Jun 2009, 2:04 AM
With a bit of XTemplate magic:


groupTextTpl: new Ext.XTemplate(
'{gvalue}, bla-bla-bla: {[this.countTotal(values.rs)]}',
{
countTotal: function(records){
var totalSum = 0;
for (i=0;i<records.length;i++){
totalSum += records[i].get('docAmount');
}
return totalSum;
}
}
)

Tinki
23 Jun 2009, 3:50 AM
Something gone wrong:((
I belive, there should be my grouping rows (take a look at the attach). When I exploring the DOM, it shows that grouping rows are empty.

Condor
23 Jun 2009, 4:45 AM
groupTextTpl needs to be a string; a template is not allowed.

You'll have to specify the startGroup config option instead:

startGroup : new Ext.XTemplate(
'<div id="{groupId}" class="x-grid-group {cls}">',
'<div id="{groupId}-hd" class="x-grid-group-hd" style="{style}"><div class="x-grid-group-title">',
'{gvalue}, bla-bla-bla: {[this.countTotal(values.rs)]}',
'</div></div>',
'<div id="{groupId}-bd" class="x-grid-group-body">',
{
countTotal: function(records){
var totalSum = 0;
for (i=0;i<records.length;i++){
totalSum += records[i].get('docAmount');
}
return totalSum;
}
}
)

Tinki
23 Jun 2009, 5:01 AM
It works! :D