Reputation: 1415
I found out that html special characters such as '&' are not being decoded when we fetch value from the table object using API functions but instead of they are in ASCII or Unicode form. This is my simple initialization for the dataTable.
var otable = $('#vtable').DataTable({
"dom": '<"top"lBf<"clear">>rt<"bottom"ip<"clear">>'
});
See this Fiddle.
What should be best solution to decode html special character before passing it to the data processing?
Upvotes: 1
Views: 5341
Reputation: 58900
Encode HTML entities:
var valEncoded = $('<div>').text(val).html();
Decode HTML entities:
var valDecoded = $('<div>').html(val).text();
See this example for code and demonstration.
See updated jsFiddle for demonstration on how it could be used in your project.
Upvotes: 2
Reputation: 1415
Using this answer of Stackoverflow, the solution for question is the function below to decode the html characters from a row of data.
function decodeHtml(str) {
var map =
{
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'"
};
return str.replace(/&|<|>|"|'/g, function (m) { return map[m];
});
}
Upvotes: 0