user2720297
user2720297

Reputation: 141

Kendo Grid Client Template with Condition

 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">
}#  

Upvotes: 14

Views: 43524

Answers (6)

dynamiclynk
dynamiclynk

Reputation: 2331

This worked for me but note do not use href='#' it will break the template compiler.

 c.Bound(p => p.ItemNumber)
  .Width(64)
  .ClientTemplate("# if (ItemCommentActive) { #" +
                      "<a href='void(0);' title='#=Comments#' onclick='return false;'>#=ItemNumber#</a>" +
                       "# } else { #" +
                       "<div>#=ItemNumber#</div>" +
                       "# } #");

Upvotes: 0

GoviNd Gopi
GoviNd Gopi

Reputation: 1

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...

Upvotes: -1

Bhavsar Jay
Bhavsar Jay

Reputation: 163

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);

Upvotes: 7

Ohlin
Ohlin

Reputation: 4178

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.

Upvotes: 34

callisto
callisto

Reputation: 5083

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");

Upvotes: 5

Jaimin
Jaimin

Reputation: 8020

Try this,

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

Upvotes: 8

Related Questions