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

How to display array data in column?

6 Answers 536 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
f
Top achievements
Rank 1
f asked on 24 Jul 2015, 10:08 PM

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

Sort by
0
Nikolay Rusev
Telerik team
answered on 28 Jul 2015, 01:06 PM

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
f
Top achievements
Rank 1
answered on 28 Jul 2015, 03:47 PM

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?

0
Nikolay Rusev
Telerik team
answered on 30 Jul 2015, 06:35 AM

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
f
Top achievements
Rank 1
answered on 30 Jul 2015, 02:24 PM

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.

0
Nikolay Rusev
Telerik team
answered on 03 Aug 2015, 11:04 AM

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Muhammad
Top achievements
Rank 1
Iron
answered on 22 Dec 2021, 10:43 AM
The implode() function is a built-in function of PHP, and it works the same as the join() function works. It is used to join the elements of an array and convert them into a string. PHP implode() function accepts two parameters as arguments; one is required, and one is optional. For further info I would direct to this site.
Tags
TreeList
Asked by
f
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
f
Top achievements
Rank 1
Muhammad
Top achievements
Rank 1
Iron
Share this question
or