Horizontal alignment when having multiple childs
Horizontal alignment when having multiple childs
raduborcan
Posts: 20Questions: 3Answers: 0
Hello
I've managed to finish the master-detail functionality, but I've noticed the lack of alignment control, meaning, each time I expand a detail set the header is moving to the right; more, the "scrollX" it appears to function opposite as described: if it is true, the header and the rows are static, although they are misaligned.
Please find below the code along with 2 files of data.
$(document).ready(function() {
var table = $('#example').DataTable( {
ajax: "alin@TS Locks_Master.txt"
/*
function (data, callback, settings) {
$.ajax({
url: "objects.txt",
}).then ( function(json) {
var data = JSON.parse(json);
callback(data);
});
}
*/,
pageLength: 10,
scrollX: "true",
columns: [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ data: 0 },
{ data: 1 },
{ data: 2 },
{ data: 3 },
{ data: 4 }
],
initComplete: function () {
init = false;
},
createdRow: function ( row, data, index ) {
if (data[5] === '') {
var td = $(row).find("td:first");
td.removeClass( 'details-control' );
}
}
} );
// Add event listener for opening and closing first level childdetails
$('#example tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = table.row( tr );
var rowData = row.data();
var index = rowData[5];
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child(
'<table id = "child_details'+index+'" style="padding-left:50px;">'+
'<thead>'+
'<tr>'+
'<th>#</th>'+
'<th>CltId</th>'+
'<th>DocCode</th>'+
'<th>DocNo</th>'+
'<th>DocDate</th>'+
'<th>Value</th>'+
'</tr>'+
'</thead>'+
'<tbody></tbody>'+
'</table>').show();
$('#child_details'+index).DataTable({
ajax: function (data, callback, settings) {
$.ajax({
url: "alin@TS Locks_Detail.txt"
}).then ( function(json) {
var data = JSON.parse(json);
data = data.data;
var display = [];
for (d = 0; d < data.length; d++) {
if (data[d][5] == rowData[5]) {
display.push(data[d]);
}
}
callback({data: display});
});
},
//fixedHeader:{header: "true"},
scrollX: 800,
scrollCollapse: true,
td: 'scope= "col"',
columns: [
{
"className": 'details-control1',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ data: 0 },
{ data: 1 },
{ data: 2 },
{ data: 3 },
{ data: 4 }
],
columnDefs: [{ targets: [1] , visible: false}],
destroy: true,
scrollY: '200px',
});
tr.addClass('shown');
}
})
} );
This discussion has been closed.
Answers
Hi @raduborcan ,
Thanks for those files, we're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
I've managed to put the JS code, CSS code and HTML code in http://live.datatables.net/sinotazi/1/edit, but I didn't find a way to upload the 2 files required for the test case, neither the place (I suppose is http://live.datatables.net/sinotazi/ajax)
Could you provide some more info please.
Thank you
Radu B.
Hi @raduborcan ,
I think I've simulated it, you'll need to paste the attached file here into the JS section of your example above.
Cheers,
Colin
Colin asked me to take a little look. Its because the inner table isn't taking 100% and scrolling is enabled. When you get that set of conditions the table header and body can look really odd.
Three options:
width: 100%
to your inner table.div
inside the child and put the table inside that - with it set to 100% width (and the div smaller if you want it smaller).Allan
I've updated the JS section on http://live.datatables.net/sinotazi/3/edit
I've tested with all 3 possibilities, none appears to work (or I didn't understand what to do), the 2nd worsen the appearance.
Thank you
Radu B.
This is it with option 1: http://live.datatables.net/sinotazi/4/edit .
Allan
Would you mind make a sample with the 3rd option,
Thank you
Had something similar. The solution I used was (basically):
CSS:
I've inserted the snippets, but it doesn't seem to work.
Please take a look at http://live.datatables.net/hujafixa/1/edit
BTW in the JS section is missing a DIV closure.
Thank you for your answer
Option 3: http://live.datatables.net/sinotazi/7/edit