如何创建kendo网格detailInit

时间:2016-12-01 08:35:19

标签: javascript object kendo-ui kendo-grid

我尝试使用detailInit函数创建一个kendo网格,但我不知道如何实现它。

如何在我的网格detailsInit函数中显示地址[object,Object]数据,其中允许用户切换以显示详细信息,并且下面有一个想要输出的示例: -

当前输出:

    Name      |  Phone         |     Address
------------------------------------------------
John Smith    | (519) 420-2391 | [object Object]
------------------------------------------------
James Seth    | (123) 212-3332 | [object Object]

想要输出:

   Name       |  Phone         |     
--------------------------------
John Smith    | (519) 420-2391 | 
--------------------------------
 ^  Location  | no             |
   -----------------------------
    london    | 123            |
    aus       | 456            |



var peoples = [],
  address = [];


peoples = [{
  id: 1,
  name: "John Smith",
  phone: "(519) 420-2391",
  address: [{
    Location: "london",
    no: "123"
  }, {
    Location: "aus",
    no: "456"
  }]
}, {
  id: 2,
  name: "James Seth",
  phone: "(123) 212-3332",
  address: [{
    Location: "Paris",
    no: "789"
  }, {
    Location: "ita",
    no: "888"
  }]
}];

$("#grid").kendoGrid({
  dataSource: {
    data: peoples,

  },

  columns: [{
    field: "name",
    title: "Name"
  }, {
    field: "phone",
    title: "Phone number"
  }, {
    field: "address",
    title: "Address"
  }],

});

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>Untitled</title>

  <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.714/styles/kendo.common.min.css">
  <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.714/styles/kendo.rtl.min.css">
  <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.714/styles/kendo.default.min.css">
  <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.714/styles/kendo.mobile.all.min.css">

  <script src="http://code.jquery.com/jquery-1.12.3.min.js"></script>
  <script src="http://kendo.cdn.telerik.com/2016.2.714/js/angular.min.js"></script>
  <script src="http://kendo.cdn.telerik.com/2016.2.714/js/jszip.min.js"></script>
  <script src="http://kendo.cdn.telerik.com/2016.2.714/js/kendo.all.min.js"></script>
</head>

<body>
  <div id="example">
    <div id="grid"></div>
  </div>

</body>

</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

只需在当前行的address属性detailInit事件中创建另一个网格作为其数据:

detailInit: function(e) {
    $('<div></div>')
        .appendTo($(e.detailRow))
        .kendoGrid({
            dataSource: {
                data: e.data.address
            },
            columns: [{
                field: "Location"
            }, {
                field: "no"
            }]
        });
}

Official demo如何做到这一点。