Kendo ui grid if else condition

北慕城南 提交于 2019-11-27 16:34:33

问题


What is wrong with my code?

I have to check in kendo UI grid is there "OrderType 20" in my column. If it is, I need to apply my css condition which includes background, but it does not work, can someone help me? thanks

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

回答1:


It might help you for nested if else for kendo ui grid row template. i.e.

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



回答2:


done on easier way: thank You all

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



回答3:


I would recommend you to write a function and call that in template and code the logic in that. following is the example.

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



回答4:


You can handle it in grid databound event too.Check this fiddle:

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

You can modify the databound instead of looping through all the cell collection

if(dataItem.OrderType == 'OrderType20')



回答5:


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


来源:https://stackoverflow.com/questions/28459463/kendo-ui-grid-if-else-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!