How to display array data in column?

6 posts, 0 answers
  1. f
    f avatar
    14 posts
    Member since:
    Jan 2008

    Posted 24 Jul 2015 Link to this post

    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,

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 28 Jul 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. f
    f avatar
    14 posts
    Member since:
    Jan 2008

    Posted 28 Jul 2015 in reply to Nikolay Rusev Link to this post

    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?

  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 30 Jul 2015 Link to this post

    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!
     
  6. f
    f avatar
    14 posts
    Member since:
    Jan 2008

    Posted 30 Jul 2015 in reply to Nikolay Rusev Link to this post

    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.

  7. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 03 Aug 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready