简体   繁体   中英

how can i implement a IF statement in command inside Kendo-grid?

I try to implement a IF condition in a template of kendo-grid, but the template is located inside of command. The condition send me an error. what is wrong and what can i do?

Here my code:

command:{
          text: "Tarea",
          field: "Comentario",
          click: function (e) {
                  console.log("Hello")
          },
         template:'#if(Comentario != 0){# <a href="\\#" class="k-button k-button-icontext k-grid-Tarea"><span class="fa fa-2x fa fa-pencil-square-o text-default"></span></a> # } else {# <a href="\\#" class="k-button k-button-icontext k-grid-Tarea"><span class="fa fa-2x fa fa-pencil text-default"></span></a> #} #',
          },

The command object does not have a template property. You can use the column template instead:

$("#grid").kendoGrid({
  columns: [
    "name", 
    "Comentario",
    {
       field: "Comentario",
       title: "Tarea",
       template: '#if(Comentario != 0){# <a href="\\#" class="k-button k-button-icontext k-grid-Tarea"><span class="fa fa-2x fa fa-pencil-square-o text-default"></span></a> # } else {# <a href="\\#" class="k-button k-button-icontext k-grid-Tarea"><span class="fa fa-2x fa fa-pencil text-default"></span></a> #} #'
    }],
  dataSource: [ { Comentario: "0", name: "Name1" }, { Comentario: "1", name: "Name1" } ]
});

Then you can use a click handler and the grid's dataItem method to handle the clicks on your custom font awesome buttons:

$("#grid").on("click", ".k-grid-Tarea", function(e) {
    var grid = $("#grid").data("kendoGrid");
    var dataItem = grid.dataItem($(this).closest("tr"));
    alert(dataItem.name); // displays name column       
});

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM