Javascript Kendo ui grid if else 条件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28459463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:49:24  来源:igfitidea点击:

Kendo ui grid if else condition

javascriptif-statementkendo-gridconditional

提问by Aviator

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

我必须检查剑道 UI 网格,我的专栏中是否有“OrderType 20”。如果是,我需要应用包含背景的 css 条件,但它不起作用,有人可以帮助我吗?谢谢

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

回答by Anil Singh

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

它可能会帮助您嵌套 if else 用于剑道 ui 网格行模板。IE

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

回答by ashutosh jambhale

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

回答by Aviator

done on easier way: thank You all

以更简单的方式完成:谢谢大家

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

回答by Andrea

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

您也可以在网格数据绑定事件中处理它。检查这个小提琴:

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

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

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

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

if(dataItem.OrderType == 'OrderType20')

回答by 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> 
            #} #"
}