我的代码有什么问题?
我需要检查kendo UI网格中是否存在“OrderType 20”在我的列中。如果是,我需要应用包括背景的css条件,但它不起作用,可以有人帮帮我吗?谢谢。
template: '# if (OrderType == "OrderType 20") {#<div class='customClass'>#:OrderType#</div>#} else {#OrderType#}#'
我的代码有什么问题?
我需要检查kendo UI网格中是否存在“OrderType 20”在我的列中。如果是,我需要应用包括背景的css条件,但它不起作用,可以有人帮帮我吗?谢谢。
template: '# if (OrderType == "OrderType 20") {#<div class='customClass'>#:OrderType#</div>#} else {#OrderType#}#'
对于Kendo UI网格行模板的嵌套if else可能会有所帮助。例如:
template: "#if(ErrorDesc==null){# #: DeviceLabel # #}else If(ErrorDesc==""){# #: DeviceLabel # #}else{# #: DeviceText # #}#"
更简单的方法完成:感谢大家
template: "#if(OrderType == 'OrderType 20') {#<div class='customClass'>#:OrderType#</div>#} else{##:OrderType##}#"
我建议您编写一个函数,并在模板中调用它,将逻辑代码编写在函数中。以下是示例。
$(gridId).kendoGrid({
dataSource: {
data: datasource
},
scrollable: true,
sortable: true,
resizable: true,
columns: [
{ field: "MetricName", title: "Metric", width: "130px" },
{ field: "OnTrack", title: "On Track", template:'#:changeTemplate(OnTrack)#', width: "130px", attributes: { style: "text-align: center !important;" } },
{ field: "CurrentAmount", title: "Current", template: '$ #:parseFloat(CurrentAmount).toFixed(2)#', width: "130px" },
{ field: "RequiredAmount", title: "Required", template: '$ #:parseFloat(RequiredAmount).toFixed(2)#', width: "130px" }
]
});
function changeTemplate(value)
{
Conditions depending on Your Business Logic
if ()
return "HTML Here";
else
return "HTML Here";
}
{
field: "status",
title: "Status",
width: "80px",
template: "# if (status == '1' ) { # <center><span
style='color:green;'>Active</span></center> #
}
else if (status == '0'){ #
<center><span style='color:red;'>Deactive</span></center>
#} #"
}
Check this fiddle:
http://jsfiddle.net/Sowjanya51/krszen9a/
您可以修改数据绑定,而不是循环遍历所有单元格集合。
if(dataItem.OrderType == 'OrderType20')