thousand separator

thousand separator

eastofthesuneastofthesun Posts: 12Questions: 4Answers: 0
edited May 2014 in DataTables 1.10

hi

I have a column with numbers like:

1
1000
1100

how can I display them with thousand separator (not changing the original format) as:

1
1 000
1 100

Answers

  • allanallan Posts: 63,356Questions: 1Answers: 10,444 Site admin

    Take a look at the Editor examples which use a number rendering formatter that is built into DataTables: { data: "salary", render: $.fn.dataTable.render.number( '\'', '.', 0, '$' ) }.

    Allan

  • eastofthesuneastofthesun Posts: 12Questions: 4Answers: 0

    thanks allan
    look at it but don't really get a grip on it...can you show a complete code how you do it on a column?

    thanks

  • allanallan Posts: 63,356Questions: 1Answers: 10,444 Site admin

    The complete code is there in the example :-). The first parameter is the thousands separator, the second the decimal place, the third the number of decimal places and the last (optionally) a currency symbol.

    Allan

  • eastofthesuneastofthesun Posts: 12Questions: 4Answers: 0
    edited May 2014

    ok =), tried this without success...

    $(document).ready( function () {
        var table = $('#table_id').DataTable({
    "paging":   false
    });
        new $.fn.dataTable.FixedHeader( table,{ "left": true} );
    
    
    fields: [ {
                    label: "Column A:",
                    name: "column_a"
                }, {
                    label: "Column B:",
                    name: "column_b"
                }
    ]
    
    columns: [
                 { data: "column_b", render: $.fn.dataTable.render.number( ' ', '.', 0, '$' ) }
    ]
    
    } );
    
  • allanallan Posts: 63,356Questions: 1Answers: 10,444 Site admin

    Presumably you are getting syntax errors using that? The columns array should be in the DataTables constructor object and fields in the Editor constructor object.

    Allan

  • eastofthesuneastofthesun Posts: 12Questions: 4Answers: 0

    ok, but do you need to use the editor object to get thousand separator like I want, there is no other way?

  • allanallan Posts: 63,356Questions: 1Answers: 10,444 Site admin

    I don't understand? You use the line that I referenced in the DataTables initialisation. That it was in an Editor example is inconsequential - you can ignore that fact. Unless you are using Editor, just look at how DataTables initialised in that example.

    Allan

  • eastofthesuneastofthesun Posts: 12Questions: 4Answers: 0

    Hi again Allan

    http://live.datatables.net/paqebej/1/

    1. How do I get thousand separator on the data (1000000) without changing the original data?

    2. The left column that is fixed is missing the zebra coloring and does not change color on mouseover on the column 2 or higher, how can this be solved?

    3. The columns sorting arrows are getting too close on the header...how can I adress this?

    Thanks in advance for your help!

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    How do I get thousand separator on the data (1000000) without changing the original data?

    Your code shows no attempt to do what Allan has already explained to you twice. Also, why are you initializing your "var table" twice with different table id's?

  • eastofthesuneastofthesun Posts: 12Questions: 4Answers: 0

    Hi Tangerine

    Thanks for you response. Can you please refer in code where its done twice?

  • adefaveriadefaveri Posts: 2Questions: 0Answers: 0

    Hi all,
    I've tried use jQuery.fn.dataTable.render.number( '.', ',', 2, '' ), it works fine for thousand separator but for decimal it doesn't work: I've tried other characters but it show always the dot.
    I use version 1.10.0

    Can you help me?
    thanks

  • allanallan Posts: 63,356Questions: 1Answers: 10,444 Site admin

    @adefaveri - Please link to a test case showing the problem.

    Allan

  • adefaveriadefaveri Posts: 2Questions: 0Answers: 0

    hi allan,
    I can't... it is a not public project.
    I can show this: https://www.dropbox.com/s/s61myz5xonx8dst/2014-06-09_1423.png

  • allanallan Posts: 63,356Questions: 1Answers: 10,444 Site admin

    Thanks for the screenshot! Very certainly a bug in DataTables. I've committed the fix here and it will be in 1.10.1.

    Until then, you can grab the nightly if you want to try out the very latest with this fix.

    Regards,
    Allan

This discussion has been closed.