[英]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.我尝试在kendo-grid的模板中实现IF条件,但模板位于命令内部。 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:然后你可以使用点击处理程序和网格的 dataItem 方法来处理对自定义字体真棒按钮的点击:
$("#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
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.