PDA

View Full Version : Count number inside template



msuresh
29 Oct 2010, 1:44 AM
Hi,
I am using template and need to display blocks in alternative color (like stripeRows in grid). How can we achieve using template.

Is it possible to get a count value inside the template so that we can manipulate using JQuery eq function.



var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<div id="{docId}" style="color: black;">',
'<div style="color:red"><b>Node: {docId} @ {dateTime}</b></div>',
'<div style="font-size:12px !important">{textResult}</div>','<br/>',
'</div>',
'</tpl>'
);


Regards,
SURESH KUMAR M R

StuartAshworth
29 Oct 2010, 2:13 AM
Check the docs...



Execute arbitrary inline code with special built-in template variables Anything between {[ ... ]} is considered code to be executed in the scope of the template. There are some special variables available in that code:


values: The values in the current scope. If you are using scope changing sub-templates, you can change what values is.
parent: The scope (values) of the ancestor template.
xindex: If you are in a looping template, the index of the loop you are in (1-based).
xcount: If you are in a looping template, the total length of the array you are looping.
fm: An alias for Ext.util.Format.

This example demonstrates basic row striping using an inline code block and the xindex variable: var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Company: {[values.company.toUpperCase() + ", " + values.title]}</p>',
'<p>Kids: ',
'<tpl for="kids">',
'<div class="{[xindex % 2 === 0 ? "even" : "odd"]}">',
'{name}',
'</div>',
'</tpl></p>'
);
tpl.overwrite(panel.body, data);

msuresh
29 Oct 2010, 3:21 AM
Hi Stoot,
Thanks a lot, now I am able to solve my problem with ease.

Regards,
SURESH KUMAR M R