jQuery Datatables responsive example
HTML
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="//cdn.datatables.net/1.10.1/css/jquery.dataTables.css">
<script src="//cdn.datatables.net/1.10.1/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="//cdn.datatables.net/responsive/1.0.0/css/dataTables.responsive.css">
<script src="//cdn.datatables.net/responsive/1.0.0/js/dataTables.responsive.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.css">
<table id="example" class="compact hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>Start date</th>
<th>Salary</th>
<th>Inner Table</th>
</tr>
</thead>
<tbody>
<tr>
<td>2011/04/25</td>
<td>$320,800</td>
<td>
<table width="100%" class="table table-sm">
<thead>
<tr>
<th>Name</th>
<th>Buttons</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>
<input type="button" value="btn1">
<input type="button" value="btn2">
<input type="button" value="btn3">
</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>
<input type="button" value="btn1">
<input type="button" value="btn2">
...
CSS
/* if this CSS is commented out, the table will not have the style-breaking issue,
but won't display correct number of spaces*/
table.dataTable td {
white-space:pre;
}
JavaScript
$(document).ready(function() {
$('#example').DataTable( {
columnDefs: [
{ className: 'align-top', targets: '_all' }
],
} );
} );