PDA

View Full Version : [3.0] List View XTemplate row number



JamesC
8 Sep 2009, 5:34 AM
How do i get the row number in the tpl: config for a list view column? I tried {[xindex]} & parent.xindex but neither worked. Any ideas?

Condor
8 Sep 2009, 6:08 AM
You can't access the parent, because it uses a subtemplate.

Instead, you could modify the ListView tpl, e.g.

new Ext.ListView({
tpl: new Ext.XTemplate(
'<tpl for="rows">',
'<tpl exec="values.row = xindex;"></tpl>',
'<dl>',
'<tpl for="parent.columns">',
'<dt style="width:{width}%;text-align:{align};"><em unselectable="on">',
'{[values.tpl.apply(parent)]}',
'</em></dt>',
'</tpl>',
'<div class="x-clear"></div>',
'</dl>',
'</tpl>'
),
columns: [{
header: '#',
dataIndex: 'row'
},{
header: 'Text',
dataIndex: 'field1'
}],
store: ['One', 'Two', 'Three'],
width: 200,
height: 200,
renderTo: Ext.getBody()
});

JamesC
8 Sep 2009, 1:10 PM
Worked perfect - cheers Condor! Those XTemplates really are powerful, but take a bit to get ya head around! Thanks again!

pym
14 Jan 2011, 2:54 PM
How would something similar work if the listview was an extension - it seems like adding a row counter to list view would
be useful... but the method above applied causes the viewlist to show only headers - so I must be missing some part of
using it in an extend.
ListViewWithRows = Ext.extend(Ext.list.ListView, {