How do I make the number "1000" showed as "1,000"?

How do I make the number "1000" showed as "1,000"?

guoguoguoguoguoguo Posts: 3Questions: 2Answers: 0

I searched thru the forum and found posts about number format. It seems it's by default showed as 1,000 rather than 1000. But it's not. The HTML is very simple:

<td>3201800</td>

Do I have to use external JavaScript functions to pre-modify it?

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    edited September 2015

    This example shows how to use the number rendering function.

    { data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$') }

    https://editor.datatables.net/examples/simple/simple.html

    -fixed some odd copy/paste artifacts

  • guoguoguoguoguoguo Posts: 3Questions: 2Answers: 0

    @ThomD

    Thanks, but the solution requires a fixed count of the column. In my tables they are not fixed. Some table has 5 columns and some has 7. Is there kind of something any 'global settings'?

  • allanallan Posts: 61,934Questions: 1Answers: 10,155 Site admin

    You can still use that approach, but use columnDefs to target one or more columns either by column index or by class name. You do need to tell DataTables which columns you want to format though - it won't just apply a global formatter to all numbers.

    Allan

This discussion has been closed.