DataTables - Child rows
HTML
<link rel="stylesheet" href="https://cdn.datatables.net/r/dt/dt-1.10.9/datatables.min.css">
<script src="https://cdn.datatables.net/r/dt/dt-1.10.9/datatables.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.scrollto/2.1.2/jquery.scrollTo.min.js"></script>
<table id="example" class="display" cellspacing="0" width="100%">
</table>
CSS
td.details-control {
background: url('https://raw.githubusercontent.com/DataTables/DataTables/1.10.7/examples/resources/details_open.png') no-repeat center center;
cursor: pointer;
}
tr.shown td.details-control {
background: url('https://raw.githubusercontent.com/DataTables/DataTables/1.10.7/examples/resources/details_close.png') no-repeat center center;
}
JavaScript
/* Formatting function for row details - modify as you need */
function dataFormat(d) {
var result = '';
var hasChildren = false;
for (i = 0; i < d.length; i++) {
result +=
'<tr>' +
'<td></td>' +
'<td>' + d[i].col0 + '</td>' +
'<td></td>' +
'<td>' + d[i].col2 + '</td>' +
'<td>' + d[i].col3 + '</td>' +
'<td>' + d[i].col4 + '</td>' +
'<td>' + d[i].col5 + '</td>' +
'</tr>';
hasChildren = true;
}
if (!hasChildren)
result += '<ul>There are no items in this view.</ul>';
return $(result);
}
function ProcessTableVehicleDetailV2(id, tableData) {
if (!$.fn.dataTable.isDataTable('#' + id)) {
$('#' + id).DataTable({
data: tableData,
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excelHtml5', 'pdfHtml5', 'print'
],
columns: [
{
"class": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ data: "col0" },
{ title: "Title1", data: "col1" },
{ title: "Title2", data: "col2" },
{ title: "Title3", data: "col3" },
{ title: "Title4", data: "col4" },
{ title: "Title5", data: "col5" },
{ title: "Hide1", data: "col6", "visible": false, "searchable": false },
{ title: "Hide2", data: "col7", "visible": false, "searchable": false }
],
ordering: false,
"scrollY": "400px",
"paging": false,
"searching": false,
"info": false,
'responsive': true,
"language": {
"emptyTable": "No Data"
},
"createdRow": function (row, data, index) {
if (data.Col0 === " " && data.Col1 === " " && data.Col2 === " ")
$('td', row).eq(0).removeClass('details-control');
},
"render": function (data, type, full, meta) {
return full["Col0"] + "" + full["Col1"] + "" + full["Col2"];
},
"initComplete": function () {
$('.dataTables_scrollBody thead tr').addClass('hidden');
$('.dataTables_scrollBody thead th').addClass('hidden');
$('.dataTables_scrollBody tfoot...