How can i decode special characters in datatable?
How can i decode special characters in datatable?

Hello,
i have a datable that works well, but i have a proble with special characters like è,à or ù.
When i try to display one of this i see a very strange char.
Someone can help me?
This is my code
$('#clientTableId').DataTable( {
"order": [[ 0, "asc" ]],
ajax : {
url :url,
type: 'POST',
dataSrc:function ( json ) {
return json;
},
},
"language": {
"lengthMenu": lengthMenuT,
// "zeroRecords": zeroRecordsT,
"info": infoT,
"infoEmpty": infoEmptyT,
"infoFiltered": infoFilteredT,
"search": searchT,
"paginate": {
"previous": previousT,
"next": nextT
}
},
columns: [
{ "data": "Cognome",
render: function (data,type,row) {
return " <div onclick='goToClientPage("+row.id.clients.patientId+")' style='width: 100%; height: 80px'><label style='text-decoration: underline' class='cliente-"+row.id.clients.active+"'>"+row.id.clients.surname+"</label></div>"
}},
{ "data": "Nome",
render: function (data,type,row) {
return " <div onclick='goToClientPage("+row.id.clients.patientId+")' style='width: 100%; height: 80px'><label style='text-decoration: underline'>"+row.id.clients.name+"</label></div>"
}
},
....
and this is the resuts
jhon mari�������������
i have already verified that in my java code the returned string has the correct chars è, ò, à.
Thanks to everyone for helping me
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Let's assume you get your data from an SQL database. Then you would need to set the character set of the database to UTF-8 like in here. I remember using the db handler for the first time and it didn't have "charset" specified in "$dsn" because in US English it isn't needed. I had the same problems with special characters.
Hi, thanks for your reply. Unfortunately this is not the solution, my database is encoding in UTF8 and as i said when i retriving data from my batabase on my java code the characters are well formed. they change when arrive via Json to my table
Can you post an example of the JSON string by copying it from the browser's network inspector? This will show us what Datatables is receiving.
Kevin
Hi Kevin,
This is what i send from java controller via ajax:
and this is what i see in browser inspection,
I don't know where the transformation occurs
I think you are actually sending the broken values because they are like that in the browser's network inspector - and that is what data tables is receiving.
The problem is: The visual representation of what you are sending and that you look at doesn't show you what you are actually sending. I had the same problem - and it was really mind boggling.
For some interface I had to send an awfully looking header to the client. It looked fine in my debugger using PHP. But when I opened the result with Excel as a csv file all the special characters were broken like in your example.
The solution was: convert it all to "Windows-1252" which is the format Excel likes. My default is UTF-8 but that wasn't good enough in this case. All you can do is experiment a little I guess ...