parent/child with additional data
parent/child with additional data
montoyam
Posts: 568Questions: 136Answers: 5
in DataTables
I have a parent/child setup implemented as shown here: https://datatables.net/blog/2019-01-11
However, when the child is shown, I would like to add data in addition to the table. I tried this:
function createChild(row) {
var rowData = row.data();
var rowID = rowData.RequestID;
// This is the table we'll convert into a DataTable
var table = $('<table class="display" />');
// Display it the child row
//row.child(table).show();
row.child('<h3>' + rowData.RequestDescription + '</h3>' + table).show();
it shows this in the created tr:
Request Description shows here
[object Object]
I guess it turned table to a string. is there a way I can add the RequestDescription after the table is drawn perhaps?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
table
is a jQuery object, so you are adding (concatenating) a string to an object. The output you are seeing is what I would expect. Are you trying to put a table inside the child row? If so, append the row(s) / cell(s) to it, like you would with other DOM manipulation, then userow.child(table).show();
.You might also be interested in this blog post which I think largely does what you are looking for - with an Ajax call (which you might or might not want).
Allan
but from what I am seeing, table can only be the table, no extra items such as
<
h1> and such, because of table.DataTables() function, right?
Try this:
Kevin
no, when I tried that I got an error:
Like I mentioned above, this must be because I use table variable later to initialize the Datatable (line 51 above): RequestNotesTable = table.DataTable({
I have found a work-around for now where I am adding a caption to the table:
But there is some other things I would like to add besides the table.
Yep, I see. Just use some jQuery methods to place the elements where you want. You can inspect the HTML to see the structure built by
row().child().show()
. Something like this might do what you want:Here it is in an example:
http://live.datatables.net/gohefoki/433/edit
Kevin
yes, that worked perfectly!
thanks