【问题标题】:Kendo UI data grid: How to change column display value based on status flag integer valueKendo UI 数据网格:如何根据状态标志整数值更改列显示值
【发布时间】:2018-01-09 05:54:03
【问题描述】:

在我的datasource 中,status 的值为01。基于此,在数据网格中,我想将 Status 的值显示为 "Active for Status=1" and "Inactive for Status=0"。如何相应地修改列值。

这是我的数据网格的DEMO

代码:

$(document).ready(function() {

          var myData = [{
            id: 1,
            name: "Grant",
            location: "A",
            color: "green",
            status: 1,
          }, {
            id: 2,
            name: "Vaughan",
            location: "B",
            color: "red",
            status: 0,
          }, {
            id: 3,
            name: "David",
            location: "A",
            color: "orange",
            status: 1,
          }];

          $("#grid").kendoGrid({
            dataSource: {
              data: myData,
              schema: {
                model: {
                  fields: {
                    id: { type: "number" },
                    name: { type: "string" },
                    location: { type: "string" },
                    color: { type: "string" }
                  }
                }
              }
            },
            columns: [
              { field: "id", title: "ID", width: "130px" },
              { field: "name", title: "Name", width: "130px" },
              { field: "location", title: "Location", width: "130px" },
              { field: "color", title: "Color", width: "130px" },
              { field: "status", title: "Status", width: "130px" },
            ]
          });


        });

【问题讨论】:

    标签: jquery kendo-ui datagrid kendo-grid kendo-datasource


    【解决方案1】:

    为条件列值使用模板

    { field: "status", title: "Status", width: "130px", template: "#if(status==1) #  Active # }else{#  Inactive  #}#"}
    

    Working fiddle

    【讨论】:

    • 非常感谢朋友
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多