Kendo ui grid if else condition

天涯浪子 提交于 2019-11-29 02:23:15

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

done on easier way: thank You all

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

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

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')
bilal chaudhari
{
  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> 
            #} #"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!