Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery DataTables CSV export utf-8

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

like image 238
flofreelance Avatar asked Mar 08 '23 20:03

flofreelance


1 Answers

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'
        }
    ]
});
});
like image 81
Zoltán Buzás Avatar answered Mar 17 '23 02:03

Zoltán Buzás