欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

kendo if 条件判断

Kendo ui grid if else condition

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


4 Answers 正确答案

这是自己亲自做的   #if(1 == 1) {#<div class='customClass'>aaa</div>#} else{#bbbb#}#


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')


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




   

KendoUi控件kendoGrid中template中条件判断的使用

根据dataSource中提供的值渲染出来的页面效果如下:

               

最后一列的操作,根据是否已经处理来显示“回收”的操作按钮。

相关代码如下,主要是template中使用条件判断语句的方式:


               

[javascript] view plain copy                        
  1. var kendoGridPermissionApplys = $("#kendo_grid_permission_applys").kendoGrid(  

  2.     {  

  3.         dataSource:{  

  4.        data:<?php echo $test;?>  

  5.     },  

  6.         sortable: true,  

  7.         scrollable: false,  

  8.         selectable: true,  

  9.         pageable:{  

  10.             messages:{  

  11.                 display: "<?php echo Yii::t('default', 'Showing {0}-{1} from {2} data items'); ?>",  

  12.                 empty: "<?php echo Yii::t('default', 'No items to display'); ?>",  

  13.                 first: "<?php echo Yii::t('default', 'Go to the first page'); ?>",  

  14.                 previous: "<?php echo Yii::t('default', 'Go to the previous page'); ?>",  

  15.                 next: "<?php echo Yii::t('default', 'Go to the next page'); ?>",  

  16.                 last: "<?php echo Yii::t('default', 'Go to the last page'); ?>"  

  17.             }  

  18.         },  

  19.   

  20.         columns:[  

  21.             {  

  22.                  field:"apply_from",  

  23.                  title: "<?php echo Yii::t('default', 'Apply From'); ?>"  

  24.             },  

  25.             {  

  26.                 field:"apply_contents",  

  27.                 title: "<?php echo Yii::t('default', 'Apply Contents'); ?>"  

  28.             },  

  29.             {  

  30.                 field:"apply_status",  

  31.                 title: "<?php echo Yii::t('default', 'Apply Status'); ?>"  

  32.             },  

  33.             {  

  34.                 field:"apply_create_time",  

  35.                 title: "<?php echo Yii::t('default', 'Apply Create Time'); ?>"  

  36.             },  

  37.             {  

  38.                 template:  

  39.                  "<a class='k-button' href='index.php?r=apply/admin/showapply&apply_id=#=apply_id#&apply_from=#=apply_from#' style='min-width:24px'>查看</a><a class='k-button' style='min-width:24px' onclick='IfGoToDistributePermission(#=apply_id# ,#=apply_status_en#)'>分配</a>" +  

  40.                  "# if (apply_status_en == 2) { #" +  

  41.                    "<a class='k-button' onclick='RecyclePermission(#=apply_id#)'>回收</a>" +  

  42.              "# } #",  

  43.                 title:"<?php echo Yii::t('default', 'Operate'); ?>"  

  44.             }  

  45.         ]  

  46.     }).data("kendoGrid");  



           
文章标签: KendoUikendoGridtemplate        

来自  https://blog.csdn.net/houqd2012/article/details/44065685    

普通分类: