How to use a second render function alongside a DataTable.render.text() render (anti-XSS security)

How to use a second render function alongside a DataTable.render.text() render (anti-XSS security)

Diego123a73Diego123a73 Posts: 4Questions: 2Answers: 0

Link to test case: https://live.datatables.net/giwojode/1/edit
Description of problem: I want to be able to apply the render type "Text helper" as shown in https://datatables.net/manual/data/renderers#Text-helper
while also having a custom render function that affects all the elements of the table. How can I achieve this? I've tried calling the render function twice for "_all", but that only seems to take the first one that's call. What would be a solution to this?

The test case shows a simple table that has a render that paints specific cells green, but where one of the cells is painted bold because a user inserted a "<b>" that should be read as just text. If I delete the first render, that shows that cell as it should be shown because of the text() render (as seen here https://live.datatables.net/giwojode/2/edit), but then im not able to customize the render because it isn't a function anymore.

How should I solve this?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    Answer ✓

    Yes, there is not a way to assign multiple render functions to a column. You can get an instance of the text renderer function for the display operation using this:

    var escapeHTML = DataTable.render.text().display;
    

    See the Orthogonal data docs for more details about the display and other operations.

    Call the escapeHTML() function with the cell data. Updated example:
    https://live.datatables.net/giwojode/3/edit

    Kevin

Sign In or Register to comment.