This is a migrated thread and some comments may be shown as answers.

How display List<string> in one cell?

1 Answer 296 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 14 Feb 2014, 03:00 PM
I tried to iterate through the list and display all elements in the list into a cell in a column but I've having trouble getting it to work.
Here is what I have so far.

In Grid definition:
columns.Bound(x => x.locationList).Title("Locations Included").ClientTemplate("#= iterate(x.locationList) #");

where x.locationList is a List<string> in the object passed in.

In <script>:
function iterate(object) {
var html = "<ul>";

for (var x = 0; x < object.length; x++) {
html += "<li>";
html += object[x];
html += "</li>";
}

html += "</ul>";
return html;
}

However, this causes all the records to disappear. What is the correct syntax to do this?

1 Answer, 1 is accepted

Sort by
0
Jack
Top achievements
Rank 1
answered on 14 Feb 2014, 05:52 PM
Never mind, solved it. Anyone reading this, I suggest you convert your List<> into a string in the controller first such as "element1, element 2, element3" and then passing it over to the Kendo Grid. 

That way, you avoid the complicated and messy way of building templates and iterating through a JSON serialized version of your List<> which may or may not even work.
Tags
Grid
Asked by
Jack
Top achievements
Rank 1
Answers by
Jack
Top achievements
Rank 1
Share this question
or