Get row child data as JSON
Get row child data as JSON
Marco Sulla
Posts: 2Questions: 1Answers: 0
Hello all. I can I get the row child data as JSON? I tried with row.child.data, but it gets me a DataTables.Api object, and it does not have the toArray() method.
This discussion has been closed.
Answers
Thats an interesting question. Since this is a dynamically created display which you can format however you like there aren't any API's to get the data. However I suspect the data is available to you as a Javascript variable that you used to generate the display.
Kevin
This is true, but it's not so simple.
In my case, I need the data of the clicked row. Since there's no way to get the data with datatables, I had to attach them to the DOM element using Jquery data().
But since I need to wait the subtable is added and there's no child.shown event, I had to use a MutationObserver on the table.
Really overcomplicated for an apparently simple operation.
Hi Marco,
row().child()
returns a jQuery object for the child rows - so you can parse that, either manually or with jQuery, to get the internal data, something like:Cheers,
Colin
Is your child an HTML table or a Datatable?
You should be able to get the data using your favorite table methods if its an HTML table or with something like the Select extension if using Datatables for the child.
If you need help maybe you can post an example of what you are doing:
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin