Kendo UI网格if else条件

14

我的代码有什么问题?

我需要检查kendo UI网格中是否存在“OrderType 20”在我的列中。如果是,我需要应用包括背景的css条件,但它不起作用,可以有人帮帮我吗?谢谢。

template: '# if (OrderType == "OrderType 20") {#<div class='customClass'>#:OrderType#</div>#} else {#OrderType#}#'
5个回答

33

对于Kendo UI网格行模板的嵌套if else可能会有所帮助。例如:


template: "#if(ErrorDesc==null){# #: DeviceLabel # #}else If(ErrorDesc==""){# #: DeviceLabel # #}else{# #: DeviceText # #}#"

8

更简单的方法完成:感谢大家

template: "#if(OrderType == 'OrderType 20') {#<div class='customClass'>#:OrderType#</div>#} else{##:OrderType##}#"


6

我建议您编写一个函数,并在模板中调用它,将逻辑代码编写在函数中。以下是示例。

$(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";
}

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

1
您也可以在网格数据绑定事件中处理它。请查看此示例:

Check this fiddle:

http://jsfiddle.net/Sowjanya51/krszen9a/

您可以修改数据绑定,而不是循环遍历所有单元格集合。

if(dataItem.OrderType == 'OrderType20')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接