5

I want to export my datatable to CSV. How to specify utf-8 encoding?

http://jsfiddle.net/ebRXw/3058/

Mamadou Diôf become Mamadou Diôf after the export

I've tryied to add "bom":true but still the problem

3
  • 1
    "Mamadou Diôf","Junior Technical Author","San Francisco","1562","2009/01/12","$86,000" . this what i got in csv Commented Jun 14, 2017 at 14:33
  • 1
    how do you open your file? with excel or another text editor? did you tried to pass the option charset: 'utf-8' to the options of any of your defined buttons? Commented Jun 14, 2017 at 14:39
  • I'm opening the file with Excel 2003. No I haven't tryied yet Commented Jun 14, 2017 at 14:48

1 Answer 1

10

Put bom in csv extend option:

$(document).ready(function() { 
var dataSet = [
[ "Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800" ],
[ "Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750" ],
[ "Mamadou Diôf", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000" ]
];

$('#example').DataTable( {
    dom: 'Bfrtip',
    data: dataSet,
    columns: [
        { title: "Name" },
        { title: "Position" },
        { title: "Office" },
        { title: "Extn." },
        { title: "Start date" },
        { title: "Salary" }
    ],
    buttons: [
        {
           extend: 'csv',
           charset: 'UTF-8',
           fieldSeparator: ';',
           bom: true,
           filename: 'CsvTest',
           title: 'CsvTest'
        }
    ]
});
});
Sign up to request clarification or add additional context in comments.

1 Comment

Is there any way to support Bengali like this 'মো. খায়রুল বাসার' while exporting to PDF in jQuery Datatable? I have added 'charset' but its showing some boxes in the PDF documents. If you could help then it would be great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.