Thousands separator

Thousands separator

BJW86BJW86 Posts: 30Questions: 11Answers: 0

Is it possible to get thousands separator working for rendered data? Like I have set for the second column?

http://live.datatables.net/botuguzu/1/edit

Thanks,
Bruce

Answers

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    Yes it is possible! Your example demonstrates it!

    But what is your question? ...

  • BJW86BJW86 Posts: 30Questions: 11Answers: 0

    I have used the render function in the first column but not in the second, so the thousand separator is only working for the second column, I am trying to get it to work for both!

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    In the first column you will need to run the number renderer for each number, for example:

    DataTable.render.number( ',', '.', 2, '$' ).display(data.mktCap)
    

    Chain .display()to provide the number to the renderer.

    Also note that you can't have two render functions defined for a column. The number renderer is not running for column 0 since you have columns.render defined. See the columnDefs conflict resolution docs for details. Also note that the number renderer only works with numbers not with cells that have extra data like column 0.

    Updated example:
    http://live.datatables.net/botuguzu/3/edit

    Kevin

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Kevin is bob on - you are putting the numbers into your own inner table, so you need to renderer them with the helper function. But want I wanted to check was if it is intentional to use an inner table like that, rather than just having three columns in the host table?

    Allan

  • BJW86BJW86 Posts: 30Questions: 11Answers: 0

    Hi Kevin that's brilliant thank you! Thanks for explaining, makes sense now.

    Kevin I need display some values from the same array vertically so this was the only way I could figure out of doing it, is there another easier way?

    Thanks,
    Bruce

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    You can join() the array with an HTML line break br using columns.render, for example:

    render: function (data, type, row) {
      return data.join('<br>');
    }
    

    Kevin

Sign In or Register to comment.