Reputation: 135
I'm trying to implement kendo grid with dynamic columns and the data showing [object Object].
How to show the address[object,Object] data in my kendo grid and i would like the sample output to be like the table below:-
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>
Upvotes: 0
Views: 1424
Reputation: 1884
You can utilize the columns.template
functionality to achieve the desired result. (Reference)
Depending on your data-structure you could use a template similar to this:
Address 1: <span>#: address[0].address1 # </span>
<br/>
Address 2: <span>#: address[0].address2 # </span>
I've also create a Dojo showing an example.
Upvotes: 1