1

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 :

enter image description here

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]>

1 Answer 1

1

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, '&lt;').replace(/[>]/g, '&gt;')
      },
      {data: 'some_other'}
    ],
})
Sign up to request clarification or add additional context in comments.

2 Comments

hi @Rahul Pal I want to render First Lastname <[email protected]> I don't want to replace the <>, how can I do that?
@Echotest You can also use render: $.fn.dataTable.render.text()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.