Force all columns to be interpreted as text instead of HTML
Force all columns to be interpreted as text instead of HTML
Hello,
We're happily using DataTables.net in our project. However we recently encountered the following issue: when a column's value contains text surrounded by angle brackets, such as <deleted>
, it appears that it gets interpreted as an HTML element which gets inserted as is into the DOM instead of being escaped.
Here's an example:
$('#logs').dataTable({
"autoWidth": false,
"ordering": false,
"ajax": "@Url.Action("Logs", "User", new { id = Model.Id })",
"columns":
[
{
"data": "initiator"
},
{
"data": "message",
}
]
});
If the initiator
column contains <deleted>
, then a <deleted>
element will get inserted into the DOM.
In general we would prefer that, by default, all columns get interpreted as plain text rather than HTML.
What's the proper way to achieve this? I couldn't find anything in the documentation.
Cheers,
Franz
This question has an accepted answers - jump to answer
Answers
Use the text renderer.
Allan
Works perfectly, thank you!