0
votes

I use Kendo grid MVC and In The First Column I Use This Code:

 columns.Template(s => s.IsActive).Title("").ClientTemplate(
                     " <input type='checkbox' \\#= IsActive ? checked='checked' : '' \\#   /input>"
                 ).Width(50);

and it works correctly, but when i wanted to use this code in span it's not working i wanted to show text insted of boolean my wrong code is :

 columns.Template(s => s.IsActive).Title(T("My Title").ToString()).ClientTemplate(
                    " <span> \\#= IsActive?" + T("Required") + " : " + T("Optional") + " \\#</span>"
                    ).Width(150);

so what's wrong with second one?

1

1 Answers

2
votes

From looking at it the code is not being picked up because it it a mix of html and javascript. In the client templating then this should would in Kendo:

#if(data.IsActive === true){#<span>Required</span>#}else{#<span>Optional</span>#}#

I find this messy so I personally like to pull this out of the template and use a function as it means I can edit it easier and don't get frustrated. so something like this:

.ClientTemplate("#=TextFormatter(data.IsActive)#")

Then in the javascript would be

function TextFormatter(value)
{
    var returnString = ''; 
    if(value === true) 
    {
       returnString = '<span>Required</span>';
    }
    else 
    {
      returnString = '<span>Optional</span>'; 
    }

    return returnString; 
}

For further reading check this link out: How do I have conditional logic in a column client template