3
I’m creating a table using the Datatables, but would like to keep a minimum height even when you have at least one record.
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
</tbody>
</table>
and the JS
var nTrs = $('#example tbody tr');
if (typeof document.getElementsByTagName('td')[0] != 'undefined'){
var iColspan = nTrs[0].getElementsByTagName('td').length;
}
var oTable = $('#example').dataTable({
"columnDefs": [
{ "visible": false, "targets": 2 },
],
"order": [[ 2, 'asc' ],[ 0, 'asc' ]],
"orderFixed": [ 2, 'asc' ],
"lengthChange": false,
"scrollY": "200px",
"scrollCollapse": true,
"paging": false,
"info": false,
"drawCallback": function ( settings ) {
var api = this.api();
var rows = api.rows( {page:'current'} ).nodes();
var last = null;
api.column(2, {page:'current'} ).data().each( function ( group, i ) {
if ( last !== group ) {
$(rows).eq( i ).before(
'<tr class="group"><td colspan="'+ (iColspan-1) +'" class="info">' + group + '</td></tr>'
);
last = group;
}
});
}
});
the example can be seen here https://jsfiddle.net/53q66vrt/
I guess you could try Style="height='???? px';"
– Brunão
@Simple brunão like this, but I did not test in several browsers to see if the result will be as expected, I left in css like this:
#example{height: 250px}
– Marcelo Diniz
@Marcelodiniz please put as answer the solution you found
– Joao Paulo