Reputation: 129
I got some data that I'm pulling from JSON API endpoint, one of the data records has object property called requestor. Here is what I mean :
data looks like so -> [{requestor: "First Lastname <[email protected]>", some_other: 'prop'}, {requestor: "Lastname first <[email protected]>", some_other: 'prop'}...{requestor n}]
The problem with this is that when it renders the table column content it renders it like so :
As a result only First Lastname
shows up for the column content on the screen.
Is there a way
I can 'escape' these <
>
or do something so this is treated like a text and not like HTML tag?
Datatables does offer render function callback, where I can return anything, but what do I return for this to be treated like a text?
Update per first edit below:
I can't want to replace <
and >
I need to print this into the table column First Lastname <[email protected]>
Upvotes: 1
Views: 251
Reputation: 106
A simple regex in render worked for me. Here is the code:
$('#dtable').DataTable({
data: [{requestor: "First Lastname <[email protected]>", some_other: 'prop'}, {requestor: "Lastname first <[email protected]>", some_other: 'prop'}],
columns: [
{
data: 'requestor',
render: data => data.replace(/[<]/g, '<').replace(/[>]/g, '>')
},
{data: 'some_other'}
],
})
Upvotes: 1