One of my TreeList field is an array. For example:
var localData = [
{ id: 1, name: "A Team", description: "", players: ["a","b"], parentId: null },
{ id: 2, name: "Team Lead", description: "", players: ["c"], parentId: 1 }
];
The "players" field is an array. I configure the column like:
columns: [
{ field: "name", title: "Team", width: "350px" },
{ field: "description", title: "Description", width: "350px" },
{
title: "Players",
template: '{{ dataItem.players }}'
}]
However, the "Players" column shows like
["a","b"]
I expect it as
a, b
How do I fix it?
Thanks,
6 Answers, 1 is accepted
Hello,
You need to take care of formatting the content of the template otherwise it will be stringified.
For example you could simple implement the following template:
template: '{{ dataItem.players.join(", ") }}'
Regards,
Nikolay Rusev
Telerik
Thank you! it helps. But, I need to remove all spaces after the "join", so I did like:
template: '{{ dataItem.players.join(", ").replace(/ /g, "") }}'
It does not work. Can you give me a clue?
Hello,
This expression `dataItem.players.join(", ").replace(/ /g, "")` is a plain JavaScript. You can implement the logic you require as in any other place using JavaScript.
Regards,
Nikolay Rusev
Telerik
It works only when I use
template: '{{ dataItem.players.join(", ").replace(" ", "") }}'
I need to replace ALL space, so I used "/ /g" in my code:
template: '{{ dataItem.players.join(", ").replace(/ /g, "") }}'
It shows up the text exactly same as the above code with a popup error message:
"d is not a function"
By the way, I am using the TreeList with AngularJS.
Hello,
I'm not sure what is the issue with replacing space characters in a string. This doesn't seems to be related to our widgets.
`
It shows up the text exactly same as the above code with a popup error message:
"d is not a function"
` - Can you demonstrate this error in a runnable example?
Regards,
Nikolay Rusev
Telerik