Is there a way to make the content of cells DOM elements?
Is there a way to make the content of cells DOM elements?
I use datatables to show payloads returned from a complex API. Those payloads are in JSON.
Currently, I'm showing the JSON in the cells as plain HTML (with syntax highlighting/colouring and indenting), but I would like to make it possible for the user to collapse / expand the (sometimes quite long) JSON payloads, with the help of something like http://caldwell.github.io/renderjson/.
However, if I try to provide an object (such as the HTML node returned by that renderjson function), the datatable will only show "[object Object]". If I convert it to plain HTML, obviously all the interactive functions attached to the node are lost, and the expand/collapse buttons don't work...
Is such a thing possible? (I had a look in the forum, but don't quite know what search terms to search for...)
This question has accepted answers - jump to:
Answers
Take a look at this thread. Its asking a similar question but uses a different library. You should be able to do something similar withe renderjson. If you need help please provide a test case with an example of your data and renderjson so we can offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thanks @kthorngren, that's very helpful and partly works.
Now my issue is that I also use the Responsive extension, and this
createdCell
event only get triggered when the cell is rendered as a column. It does not work when the child rows are being displayed...I guess I'm also going to have to perform a similar treatment when showing child rows, or can you think of a generic way of going about it?
You may need to use
responsive.details.renderer
like this example to apply the JSON formatting library.Kevin
Yep, exactly what I was planning on doing. Thanks for your help!