Display Array items in a cell

Display Array items in a cell

cskcsk Posts: 4Questions: 1Answers: 0
edited April 2014 in DataTables 1.9
I have a response which has array in it. Right now it shows as a string, but i would like to have it as a list item in a cell.
Eg: data = {test1, test2, test3}
Right now it displays as --> test1, test2, test3
I would need it as --> test1
test2
test3

Can someone please let me know on how to achieve this?

Replies

  • allanallan Posts: 54,881Questions: 1Answers: 8,601 Site admin
    You could use the mRender option with array syntax - for example:

    [code]
    mData: 'myArray',
    mRender: '[
    ]'
    [/code]

    Hard to be more specific without being able to see an example, but that's the basic idea.

    Allan
  • cskcsk Posts: 4Questions: 1Answers: 0
    Its not really working as expected.

    I have one column data which returns an array.
    The solution you have provided is working if has more than one item, but when there is only one item, its splitting that.

    Eg: mData = {test1, test2, test3}
    Returns: test1
    test2
    test2

    but if
    mData = {test1}
    Returns: t
    e
    s
    t
    1
  • allanallan Posts: 54,881Questions: 1Answers: 8,601 Site admin
    That's odd. Can you copy and paste a sample of the data that isn't working into here please so I can take a look?

    Thanks,
    Allan
  • cskcsk Posts: 4Questions: 1Answers: 0
    I apologize, after carefully looking at the return data, if it has single item, its returns as a string, otherwise its returns as an array.

    Your solution works great !!

    By the way, this is the first time i am using datatables, and its really great and the more important is the documentation.

    I appreciate the work. So easy to use.
  • allanallan Posts: 54,881Questions: 1Answers: 8,601 Site admin
    Great to hear you got it working and thanks for your kind words!

    Allan
This discussion has been closed.