Kendo ui grid if else 条件
Kendo ui grid if else condition
我的代码有什么问题?
我必须检查 kendo UI 网格是否在我的专栏中 "OrderType 20"。
如果是,我需要应用我的 css 条件,其中包括背景,但它不起作用,有人可以帮助我吗?谢谢
template: '# if (OrderType == "OrderType 20") {#<div class='customClass'>#:OrderType#</div>#} else {#OrderType#}#'
您可以在网格数据绑定事件中处理它 too.Check 这个 fiddle:
http://jsfiddle.net/Sowjanya51/krszen9a/
您可以修改数据绑定而不是遍历所有单元格集合
if(dataItem.OrderType == 'OrderType20')
我建议您编写一个函数并在模板中调用它,并在其中编写逻辑代码。以下是示例。
$(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";
}
以更简单的方式完成:谢谢大家
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 # #}#"
{
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>
#} #"
}
我的代码有什么问题?
我必须检查 kendo UI 网格是否在我的专栏中 "OrderType 20"。 如果是,我需要应用我的 css 条件,其中包括背景,但它不起作用,有人可以帮助我吗?谢谢
template: '# if (OrderType == "OrderType 20") {#<div class='customClass'>#:OrderType#</div>#} else {#OrderType#}#'
您可以在网格数据绑定事件中处理它 too.Check 这个 fiddle:
http://jsfiddle.net/Sowjanya51/krszen9a/
您可以修改数据绑定而不是遍历所有单元格集合
if(dataItem.OrderType == 'OrderType20')
我建议您编写一个函数并在模板中调用它,并在其中编写逻辑代码。以下是示例。
$(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";
}
以更简单的方式完成:谢谢大家
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 # #}#"
{
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>
#} #"
}