Ext-JS 4.2 : conditional if else in combobox getInnerTpl

Hi experts
I am using Ext-Js 4.2 in my project.

I have a combobox but in its getInnerTpl i want to use  if - else conditional statement

{
		xtype : 'combo',
		queryMode: 'local',
		fieldLabel : 'Name',
		width: '250',
		store : 'BusinessNames',
listConfig :{
getInnerTpl : function(){
return '<div data-qtip="{status}">' +
	'<div class="blackcss">{status}</div>' +
}
},

Open in new window

The above code works.


What i want to do is
{
		xtype : 'combo',
		queryMode: 'local',
		fieldLabel : 'Name',
		width: '250',
		store : 'BusinessNames',
listConfig :{
getInnerTpl : function(){
return '<div data-qtip="{status}">' +
if(status == 'ACTIVE'){
'<div class="blackcss">{status}</div>' +
}else if(status == 'INACTIVE'){
'<div class="REDcss">{status}</div>' +
}else{
'<div class="GREENcss">{status}</div>' +
}
	
}
},

Open in new window

any idea how i can do that?

thanks
royjaydAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy PooleCommented:
{
		xtype : 'combo',
		queryMode: 'local',
		fieldLabel : 'Name',
		width: '250',
		store : 'BusinessNames',
listConfig :{
getInnerTpl : function(){
var o='';
if(status == 'ACTIVE'){
o='<div class="blackcss">{status}</div>';
}else if(status == 'INACTIVE'){
o='<div class="REDcss">{status}</div>';
}else{
o='<div class="GREENcss">{status}</div>';
}

return '<div data-qtip="{status}">' + o+'</div>';
	
}
},

Open in new window

0
leakim971PluritechnicianCommented:
You should use CSS :
{
	xtype : 'combo',
	queryMode: 'local',
	fieldLabel : 'Name',
	width: '250',
	store : 'BusinessNames',
	listConfig :{
		getInnerTpl : function() {
			var template = "";
			template += '<div data-qtip="{status}">';
			template += '<div class="blackcss">{status}</div>';
			template += '<div class="REDcss">{status}</div>';
			template += '<div class="GREENcss">{status}</div>';
			template += '</div>';
			return template;
		}
	}
},

Open in new window


and depending which one you want to display in your code somewhere in your code, when you can handle the change of the status

var els = Ext.DomQuery.select('.blackcss,.GREENcss,.REDcss');
for(var i=0;i<els.length;i++) {
     els[i].addClass("hideClass");
}
if(status == 'ACTIVE') {
    Ext.query(".blackcss")[0].removeClass("hideClass");
}
else if(status == 'INACTIVE') {
    Ext.query(".REDcss")[0].removeClass("hideClass");
}
else {
    Ext.query(".GREENcss")[0].removeClass("hideClass");
}

Open in new window


CSS :
hideClass {
    display:none !important;
}

Open in new window

0
royjaydAuthor Commented:
hi randy
Thanks for the reponse.
when i try your above sugession i get
Uncaught ReferenceError: status is not defined  on line >>if(status == 'ACTIVE'){

To get the value of status we do {status} but when i try something like
if({status} == 'ACTIVE'){  

i get an error.

any clue?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

royjaydAuthor Commented:
Thanks leakim971,
but i am getting an error >> status is not defined.
0
leakim971PluritechnicianCommented:
yes, where do you set it?
you should place the code in the same scope/section
0
royjaydAuthor Commented:
status is defined in Model which is accessed from the store  : 'BusinessNames'

My Store
Ext.define('common.BusinessNames', {
    extend: 'Ext.data.Store',
    model: 'common.BusinessNameModel',//Store uses model
    autoLoad : true,		
    proxy: {
        type: 'ajax',
        url: 'businessNameList.controller', 
		method:'GET',
		reader: {
            type : 'json',
			root : 'data',
			totalProperty : 'total',
			successProperty: 'success'
			
        }
    }
});

Open in new window


My Model

Ext.define('common.BusinessNameModel', {
    extend: 'Ext.data.Model',
    fields: ['firstName','lastName','status',        
        {
            name    : 'fullName', 
            convert : function (v, rec) {
               return rec.get('firstName') + ' ' + rec.get('lastName');
            }
        }]
});

Open in new window



and in my view i am doing
{
            xtype : 'combo',
            queryMode: 'local',
            fieldLabel : 'Name',
            width: '250',
            store : 'common.BusinessNames',
listConfig :{
getInnerTpl : function(){
var o='';
if(status == 'ACTIVE'){
o='<div class="blackcss">{status}</div>';
}else if(status == 'INACTIVE'){
o='<div class="REDcss">{status}</div>';
}else{
o='<div class="GREENcss">{status}</div>';
}

return '<div data-qtip="{status}">' + o+'</div>';
      
}
},
0
leakim971PluritechnicianCommented:
your view seems to be the wrong place to set the status
Now I see you're only adding different class but it's globally the same content to show with different style

What about something like :

{
	xtype : 'combo',
	queryMode: 'local',
	fieldLabel : 'Name',
	width: '250',
	store : 'BusinessNames',
	listConfig :{
		getInnerTpl : function() {
			var template = "";
			template += '<div data-qtip="{status}">';
			template += '<div class="{status}css">{status}</div>';
			template += '</div>';
			return template;
		}
	}
},

Open in new window


so instead having blackcss, REDcss and GREENcss you have : ACTIVEcss,INACTIVEcss and css
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
royjaydAuthor Commented:
thanks , that was pretty good solution.
Just curious why you feel view is wrong place to set the status. where should the status be set?
thanks
0
leakim971PluritechnicianCommented:
view is view, you should not put any logic here
0
royjaydAuthor Commented:
Ok so I should move that if else logic to the store , correct?
0
leakim971PluritechnicianCommented:
it's just a suggestion...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.