10
votes
 columns.Bound(p => p.Active).ClientTemplate("\\#if('#=Active#'=='Y') {\\<input type='button' value='OK' />\\}\\#").Width(150).Title("Status");

but condition is taken as string??

#if('Y'=='Y')`enter code here` {
<input type="button" value="OK">
}#  
5

5 Answers

32
votes

There are three ways to use the hash syntax in a Kendo template:

  1. Render literal values: #= #
  2. Render HTML-enocded values: #: #
  3. Execute arbitrary JavaScript code: # if(...){# ... #}#

So in your code you would have to write

columns.Bound(p => p.Active).ClientTemplate(
     "#if(Active=='Y') {#
        <input type="button" value="OK">
      #}#").Width(150).Title("Status");

Notice in the sample how the # signs separate inside code from outside code. When you're inside code you don't have to use # again to access a variable and that's why Active can be without # before.

7
votes

Try this,

 columns.Bound(p => p.Active).ClientTemplate(
                "# if (IsServiceExist) { #" +
                    "<input type='button' value='OK' />"+
                "# }#").Width(150).Title("Status");
5
votes

I hope you get the solution....

columns.Bound(p => p.IsActive)
    .ClientTemplate(
        "\\# if (IsActive != false) { \\#" +
            "\\<input type=\"checkbox\" id=\"checkBox\" class=\"parentCheckBox\" window-call=\"template\" checked/>\\" +
        "\\# } else { \\#" + 
            "\\<input type=\"checkbox\" id=\"checkBox\" class=\"parentCheckBox\" window-call=\"template\" />\\" + 
        "#\\ } \\#")
    .Width(10);
4
votes

To have data values rendered in your Kendo template you could use the following as a guide:

columns.Template(@<text></text>)
    .ClientTemplate("#if (Field3 == true) {#"
    + "<a onclick='jsFoo(#=Id#)' href='\\#'></a> "
    + "#} #").Width(70).Title("ColA");
-1
votes
columns.Bound(searchModel => searchModel.Value).ClientTemplate(
    "#if(Name=='DevboardTask'){# " + 
        "<a href='\\#UpdateStatusWindow' onclick=\"javascript:openflexpmtask('#=Value#');\">#=Value#</a> " +
    "#} else {# " +
        "<a\">#=Value#</a> " +
    "#}#");

This might help you. This is just an example...