【问题标题】:Kendo ui grid if else condition剑道 ui 网格 if else 条件
【发布时间】:2015-04-12 03:01:09
【问题描述】:

我的代码有什么问题?

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

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

【问题讨论】:

    标签: javascript if-statement kendo-grid conditional


    【解决方案1】:

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

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

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

    if(dataItem.OrderType == 'OrderType20')
    

    【讨论】:

      【解决方案2】:

      我建议您编写一个函数并在模板中调用它并在其中编写逻辑代码。以下是示例。

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

      【讨论】:

        【解决方案3】:

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

        template: "#if(OrderType == 'OrderType 20') {#&lt;div class='customClass'&gt;#:OrderType#&lt;/div&gt;#} else{##:OrderType##}#"

        【讨论】:

          【解决方案4】:

          对于 kendo ui 网格行模板的嵌套 if else 可能会有所帮助。即

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

          【讨论】:

            【解决方案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> 
                        #} #"
            }
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-09-24
              • 2015-11-11
              相关资源
              最近更新 更多