Datatables not decoding htmlentities while trying to get the data

Datatables not decoding htmlentities while trying to get the data

chitturirakhichitturirakhi Posts: 2Questions: 1Answers: 0
edited March 2022 in DataTables

When I try to read the data from datatables using rows().data() api, its not decoding html entities.

For example if I sent this data to datatables

Tiger & Nixon
Garrett > Winters

When I try to read it - its giving me data like below

[["Garrett > Winters"], ["Tiger & Nixon"]]

Please see the below link
http://live.datatables.net/siqizuwa/1/edit

Kindly suggest whats the best way i can get all the values in the table.

Thanks.

Answers

  • rf1234rf1234 Posts: 2,522Questions: 79Answers: 368

    I don't have the problem with values read from the database. But I came across it when exporting to Excel. I resolved it this way:
    http://live.datatables.net/fikizipu/1/edit

  • chitturirakhichitturirakhi Posts: 2Questions: 1Answers: 0

    @rf1234 considering my datatable contains big texts in the column which can have commas, converting array to string and replacing will make it difficult to identify them back and I have many grids with different structures and some with renders. So any other better alternative?

  • rf1234rf1234 Posts: 2,522Questions: 79Answers: 368

    @rf1234 considering my datatable contains big texts in the column which can have commas, converting array to string and replacing will make it difficult

    Of course you shouldn't do it that way. I only did it to make the point in the test case. You can simply loop through the array and convert each array entry
    http://live.datatables.net/fikizipu/2/edit

    I don't have an alternative, but maybe someone else has.

  • allanallan Posts: 57,686Questions: 1Answers: 9,195 Site admin

    When I try to read the data from datatables using rows().data() api, its not decoding html entities.

    Correct - it just passed back the original data. And since your table is reading the data from the HTML the browser is automatically correctly the invalid HTML (un-escaped entity).

    Best option: Use Ajax or Javascript sourced data and this wouldn't be a problem.

    Otherwise, if your HTML has entities in it, you would need to un-encode them when reading from the data method.

    Allan

Sign In or Register to comment.