Kendo UI Grid with dynamic columns and random data showing JSON objects as [object Object]

寵の児 提交于 2019-12-14 02:27:05

问题


The data is random and I cant predict the columns. I read data from remote and display it on the grid.

I get json objects as [object Object] in Kendo UI Grid, How can i visualize it or is there any way to show a detail view of a cell in a Kendo grid ?

I think it would solve the issue if I can insert a treeview of JSON Object in those cells.


回答1:


The problem is that your Address is a complex object, so you need to tell kendoGrid how to display it. For example, I have a complex object Connected, as follows: {Connected:{Value:3, Percentage:100}}

If I simply map it to some column, I will get [object Object] displaying in my grid, identical to your experience.

Solution:

Let's say that I need to display my Connected object as follows: '3 (100 %)'. The grid has no way to know that. Therefore I had to create a template in my column declarations:

var gridColumns = [
  { field: "Connected", title: "Connected", template: function(data) {
      return data["Connected"].Value + " (" + data["Connected"].Percentage + " %)"; 
    }
  }
];

And this is what I got:




回答2:


You need to set the template of the column. By default it can only show primitive types such as "Number", "String", "Date" and "Boolean".



来源:https://stackoverflow.com/questions/19567044/kendo-ui-grid-with-dynamic-columns-and-random-data-showing-json-objects-as-obje

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!