How to get column to show as child row?
How to get column to show as child row?
PhilJones
Posts: 10Questions: 2Answers: 0
<table class="table table-bordered" id="table">
<thead>
<tr>
<th>Order No</th>
<th>Purchase Order No</th>
<th>Creation Date</th>
<th>Delivery Date</th>
<th>Total Items</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
$(document).ready(function() {
$('#table').dataTable( {
"ajax": {
"url": "/server_scripts/orders.php",
"type": "POST"
},
"columnDefs": [
{
"targets": [ 0 ],
"render": function ( data, type, full ) {
return '<a href="/order.php?id='+ full[0] +'" target="_blank"">' + data + '</a>';
}
}
],
"order": [[ 0, "desc" ]],
"serverSide": true
} );
} );
What is the simplest method to get the Total Items column as a child row instead?
I read the example at https://datatables.net/examples/api/row_details.html but I can't get the table to load at all using similar code.
I don't define columns in the DataTables code, only in the HTML.
This discussion has been closed.
Answers
Bump.
Bump.
Bump.
Well, if you are looking for the easiest way to do this you can use the Responsive extension and "push" the row off the grid, causing that row to be a child record. An example of this is: https://datatables.net/extensions/responsive/examples/column-control/auto.html. It is not really a child row, however, but it displays like one. You can see this in action when using Responsive and narrowing the browser window width.
This is the easiest way I can think to do this and hopefully relevant to what you are looking for.
Good luck,
John
Hi Phil,
Perhaps you can show us the code you tried for the child row please. If should basically be the same as the example you linked to. Have the data you want to display in a column that you make hidden (with
columns.visible
) and then use that information (which you get fromrow().data()
) when you render the child row.Allan
@allan Sorry, tried following https://datatables.net/examples/api/row_details.html but got confused, as that code defines columns and such and mine doesn't, so I couldn't match up how I use it in my scenario. I'll try again today and post here.
@allan OK, here is the code:
At the moment I get no child row or anything.
I don't have names like in the child row example, the server side data is returned just values, example:
Note: I should have said, I want all child rows to be constantly viewable, hence I don't have a column for the icon to open and close.
@allan do you know what I'm doing wrong?
This:
d.[8]
looks like it would cause a Javascript syntax error. Are there no errors shown in your browser's console? I think it should simply bed[8]
for your above data structure.Allan
@allan Sorry not getting anywhere here using the child row example page. Whenever I try use that code it just completely breaks everything and I can't work out what it is.
Here is current code:
I want Column9 to be the child row, as you can see I've successfully hide that column from appearing but I don't know how to get it to show as an extra row?!
Even when I try and run this
as a test, I don't get any child rows or any errors.
Can you give a link to the page show I can debug it please.
Allan