Reputation: 4829
one of my model field is an array and when I attempting to use it to bound grid column in ASP.NET MVC and use of Kendo Grid I get error: "bound columns require a field or property access expression"
for(var i=0; i<10 ; i++)
columns.Bound(p => p.Value[i])
using template also couldn't solve my problem.
Upvotes: 1
Views: 4886
Reputation: 4829
I found my error. Basically the grid columns can be bound only to the object properties. In current case I was trying to bind the column to the values of given property which is invalid configuration. Example below shows how to rendering the given property values in current column using ClientTemplate:
e.g.:
columns.Bound(p => p.Value).ClientTemplate("#=generateTemplate(Value)#");
function generateTemplate(Value) {
var template = "<ul>";
for (var i = 0; i < Value.length; i++) {
template = template + "<li>" + Value[i] + "</li>";
}
return template + "</ul>";
}
Upvotes: 1
Reputation: 3055
You should be able to use a template to do whatever you need to with that columns.
See sample http://jsbin.com/uxefaMI/2/edit
I use a template to sum up each of the values in the array
function numbersTemplate(e) {
var total = 0;
$.each(e.numbers, function(i, n) {
total += parseInt(n, 0);
});
return total;
}
Upvotes: 1