Datatable does not export values as they visible on data-table list

Datatable does not export values as they visible on data-table list

anujeetanujeet Posts: 39Questions: 15Answers: 0

Hi Team,

I have created a js fiddle and below is url:

https://jsfiddle.net/Akashs/bjvf8q3a/21/

On above page we have a column "Fees" and under this column we are showing values like(''10,00, 100,00, 20,00") in Dutch format. When we export the values in to excel file then values are not exporting as they visible on the list. For example 10,00 is exporting as 1,000. Do you have any solution for this?.

Looking forward your early reply.

Thanks

Replies

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Have you defined your decimal point as a comma?
    https://datatables.net/examples/basic_init/comma-decimal.html

  • HPBHPB Posts: 73Questions: 2Answers: 18
    edited May 2017

    Buttons has a private list of possible number separators called _excelSpecials. It reads the comma as a thousand seperator.
    Until this is exposed, what you could do is change your code like this so comma's are replaced with dots and those are treated as expected:

    $(document).ready(function() {
        $('#jq-datatables').DataTable( {
            dom: 'Bfrtip',
            buttons: [
                'csv', 
                {
                    extend: 'excel',
                  exportOptions: {
                    format: {
                        body: function ( data, row, column, node ) {
                            // Replace , with . in column 3
                            return column === 3 ?
                                data.replace(',', '.' ) :
                                data;
                        }
                    }
                  }
                }
            ]
        } );
    } );
    
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Yes, I'm afraid that Buttons does not currently support commas as the decimal place. That is something that I hope to address in a future update.

    Until then, @HPB's workaround is spot on!

    Regards,
    Allan

This discussion has been closed.