How to create a 3 level child-rows in DataTable?
How to create a 3 level child-rows in DataTable?
Hello,
I am trying to create a multiple level dynamic child based on data from the database. How I will create a three level child.
Thanks In Advance.
This is the code I am using
// Text File which brings the data:
{
"data": [
{
"Name": "NY Times",
"Kind": "Site",
"Start_Date": "01/01/2016",
"End_Date": "03/31/2016",
"Cost_Type": "",
"Unit_Type": "",
"Units": "",
"Cost_Rate": "",
"Ext_Cost": "",
"Discount_Amount": ""
},
{
"Name": "Young Moms",
"Kind": "Site",
"Start_Date": "01/01/2016",
"End_Date": "03/31/2016",
"Cost_Type": "",
"Unit_Type": "",
"Units": "",
"Cost_Rate": "",
"Ext_Cost": "",
"Discount_Amount": ""
}
]
}
// script
function format ( d ) {
// d
is the original data object for the row
return '
' + ' | Package_1 | ' + 'Package | ' + '01/01/2016 | ' + '03/31/2016 | ' + 'CPA | ' + 'Impressions | ' + '1 | ' + '3,500.0000 | ' + '7,000.00 | ' + '500.00 | ' + '
';
}
var jsonData =
$(document).ready(function () {
var table = $('#mediaplan-placement').DataTable({
"ajax": "scripts/objects.txt",
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data": "Name" },
{ "data": "Kind" },
{ "data": "Start_Date" },
{ "data": "End_Date" },
{ "data": "Cost_Type" },
{ "data": "Unit_Type" },
{ "data": "Units" },
{ "data": "Cost_Rate" },
{ "data": "Ext_Cost" },
{ "data": "Discount_Amount" }
],
"bAutoWidth": false,
"aaSorting": [],
"searchable": false
});
var tablenext;
// Add event listener for opening and closing details
$('#mediaplan-placement tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child(format(row.data())).show();
tr.addClass('shown');
}
});
});
Now I want to use the same function format() for the 3rd level as well.
This is the helping Url but It is only helpful for 2 level rows.
https://datatables.net/forums/discussion/30823/dear-all-how-can-we-use-nested-data-tables-up-to-3-levels#Comment_83141
Answers
This appears to be a duplicate of this thread where I've posted a reply. Please don't post duplicates.
Allan