Is there a way to make the content of cells DOM elements?

Is there a way to make the content of cells DOM elements?

WabilooWabiloo Posts: 13Questions: 4Answers: 0

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

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    Answer ✓

    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

  • WabilooWabiloo Posts: 13Questions: 4Answers: 0
    edited July 2022

    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?

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    Answer ✓

    You may need to use responsive.details.renderer like this example to apply the JSON formatting library.

    Kevin

  • WabilooWabiloo Posts: 13Questions: 4Answers: 0

    Yep, exactly what I was planning on doing. Thanks for your help!

Sign In or Register to comment.