PDA

View Full Version : ComboBox Value In templatecolumn



azinyama
24 May 2013, 11:39 AM
Good day all!!! I have a grid with three columns: 'Title', 'Contact_FName', 'Contact_Surname'.

I found the templatecolumn xtype and decided to combine the three columns and just have one column titled 'Contact' instead of three columns titled 'Title', 'First Name' and 'Surname'.

It works fine for columns 'Contact_FName', 'Contact_Surname' because they are just straight forward text.



{
xtype : 'templatecolumn',
tpl :'{Contact_SName}, {Contact_FName}',
text : 'Contact (Surname, First Name(s))',
flex : 1,
sortable : false,
hideable : false
},


My question is now can I use take the Title value and use it in the templatecolumn if I was displaying it in a grid combobox.
ComboBox Column


{
text : 'Title',
width : 100,
sortable : false,
hideable : false,
dataIndex : 'Title_RowID',
renderer : function (value, metaData, record, rowIndex, colIndex, store, view)
{
var catRecord = Ext.getStore('Title').findRecord('Title_RowID', value);

return catRecord ? catRecord.get('Title_Descr') : '';
}
},


Store looks like this:
Title_RowID ..........Title_Descr
1 ............................. MR
2 ............................. MRS
3 ............................. MISS
...
...
...
...

I want to have something like this.

tpl :'{Contact_SName}, {Contact_FName} {Title_Descr}',

skirtle
25 May 2013, 5:02 PM
Perhaps try a member function on your XTemplate? See the XTemplate docs for more details on member functions.

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.XTemplate

Failing that, maybe you could use a {% ... %} block?

Or just a normal column with a renderer. I think this is how I'd do it.

azinyama
26 May 2013, 11:52 AM
Thanks for the assist. Worked it out using XTemplate. Code below:



{
xtype : 'templatecolumn',
// tpl :'{Contact_SName}, {Contact_FName}',
tpl: new Ext.XTemplate('{Contact_SName}, {Contact_FName} <tpl for=".">{[this.getTitle(values.Title_RowID)]}</tpl>.',
{
disableFormats : true,
getTitle : function (value)
{
console.log(value);
var catRecord = Ext.getStore('Title').findRecord('Title_RowID', value);

return catRecord ? catRecord.get('Title_Descr') : '';
}
}),
text : 'Contact (Surname, First Name(s))',
flex : 1,
sortable : false,
hideable : false
},