Ext.XTemplate how to do if else condition

323 views Asked by At

I am using extjs ver. 3.4.1

I am having problem in xtype='treegrid' with this column:

{   
    dataIndex: 'SpReset',
    tpl: new Ext.XTemplate('{values.data.SpReset}')
}

I want to add renderer or something and put condition here, like:

if(values.data.SpReset === 1){
return 'Yes';
}else{return '';}

Problem is that treegrid does not support renderer. Is it possible to do this somehow?

1

There are 1 answers

1
shae On

In order to use a custom template you must use the "templateheader" component. For Example:

{
 xtype: 'templatecolumn',
            dataIndex: 'duration',
            tpl: Ext.create('Ext.XTemplate', '{duration:this.format}', {
                format: function(v) {
                    if (v < 1) {
                        return "yes";
                    }else {
                        return "No";
                    }
                }
            })
 }

https://docs.sencha.com/extjs/4.1.3/extjs-build/examples/tree/treegrid.html

Refer this example so that you would get a clear view.

Note: Try to Upgrade your ExtJs version since this component is not available in the version that you are using(extjs ver. 3.4.1)