如何在剑道网格

时间:2016-09-29 02:28:47

标签: javascript kendo-ui kendo-grid kendo-datasource kendo-template

我正在尝试使用动态列和显示[object Object]的数据来实现kendo网格。

如何在我的kendo网格中显示地址[object,Object]数据,我希望示例输出如下表所示: -

Name       |  Phone         |     Address
------------------------------------------------
John Smith | (519) 420-2391 | Address 1: London
           |                | Address 2: 123

 var peoples = [],
   address = [];


 peoples = [{
   id: 1,
   name: "John Smith",
   phone: "(519) 420-2391",
   address: [{
     address1: "london",
     address2: "123"
   }]

 }];

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

   },
   scrollable: true,
   sortable: true,
   resizable: true,
   pageable: true,
   columnMenu: true,

   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>

1 个答案:

答案 0 :(得分:1)

您可以使用columns.template功能来获得所需的结果。 (Reference

根据您的数据结构,您可以使用与此类似的模板:

Address 1: <span>#: address[0].address1 # </span>
<br/>
Address 2: <span>#: address[0].address2 # </span>

我还创建了一个显示示例的Dojo