Kendo UI数据网格:如何根据状态标志整数值

时间:2017-08-02 06:52:30

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

在我的datasource中,status的值为01。基于此,在datagrid中,我想将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" },
            ]
          });


        });

1 个答案:

答案 0 :(得分:2)

将模板用于条件列值

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

Working fiddle