<html>
<head>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<link href="https://cdn.datatables.net/2.0.3/css/dataTables.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/2.0.3/js/dataTables.js"></script>
<link href="https://cdn.datatables.net/responsive/3.0.0/css/responsive.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/responsive/3.0.0/js/dataTables.responsive.js"></script>
<link href="https://cdn.datatables.net/rowgroup/1.5.0/css/rowGroup.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.datatables.net/rowgroup/1.5.0/js/dataTables.rowGroup.js"></script>
<meta charset=utf-8 />
<title>DataTables - JS Bin</title>
</head>
<body>
<div class="container">
<table id="example" class="display nowrap cell-border" width="100%">
<thead>
<tr>
<th class="red">0</th>
<th class="red">Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>Age 1</th>
<th>Age 2</th>
<th>Age 3 </th>
<th>Age 4</th>
<th>Age 5 </th>
<th>Age 6</th>
<th class="red">Age 7</th>
<th class="red">Age 8</th>
<th class="red">Age 9</th>
<th class="never">year</th>
</tr>
</thead>
<tfoot>
<tr>
<th>0</th>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
<th>Age 1</th>
<th>Age 2</th>
<th>Age 3 </th>
<th>Age 4</th>
<th>Age 5 </th>
<th>Age 6</th>
<th>Age 7</th>
<th>Age 8</th>
<th>Age 9</th>
<th class="never">year</th>
</tr>
</tfoot>
<tbody>
<tr>
<td></td>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$3,120</td>
<td>61</td>
<td>61</td>
<td>61</td>
<td>61</td>
<td>61</td>
<td>61</td>
<td>61</td>
<td>61</td>
<td>61</td>
<td>2022</td>
</tr>
<tr>
<td></td>
<td>Garrett Winters</td>
<td>Director</td>
<td>Edinburgh</td>
<td>63</td>
<td>2011/07/25</td>
<td>$5,300</td>
<td>63</td>
<td>63</td>
<td>63</td>
<td>63</td>
<td>63</td>
<td>63</td>
<td>63</td>
<td>63</td>
<td>63</td>
<td>2022</td>
</tr>
<tr>
<td></td>
<td>Ashton Cox</td>
<td>Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$4,800</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>2023</td>
</tr>
<tr>
<td></td>
<td>Ashton Simpsons</td>
<td>Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2015/01/12</td>
<td>$4,800</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>66</td>
<td>2023</td>
</tr>
<tr>
<td></td>
<td>Cedric Kelly</td>
<td>Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>$3,600</td>
<td>22</td>
<td>22</td>
<td>22</td>
<td>22</td>
<td>22</td>
<td>22</td>
<td>22</td>
<td>22</td>
<td>22</td>
<td>2024</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
body {
font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
color: #333;
background-color: #fff;
}
.red {background-color: LavenderBlush;}
.right {text-align:right;}
var table = new DataTable('#example', {
columnDefs: [
{ className: 'dtr-control', targets: [0] },
{ orderable: false, targets: [0] },
{ responsivePriority: 1, targets: [0, 1, 13, 14, 15] }
],
//orderFixed: [16, 'desc'], // not working
order: [[16, 'desc']], // order is on col #1 and #6
responsive: {
details: {
type: 'column',
target: 'tr',
renderer: function (api, rowIdx, columns) {
var data = $.map(columns, function (col, i) {
return col.hidden
? '<p class="has-text-grey px-2 py-2"><span class="has-text-weight-semibold smallcaps">'+ col.title + ' : </span>' + col.data + '</p>'
: '';
}).join('');
return data ;
}
}
},
rowGroup: {
dataSrc: 16,
endRender: function (rows, group) {
var resposniveVisiblity = $('#example').DataTable().columns().responsiveHidden().toArray();
var numVisible = resposniveVisiblity.filter(x => x === true).length;
// var totalCols = $('#example').DataTable().columns().toArray().length;
//var numInvisible = 17 - numVisible;
var numInvisible = resposniveVisiblity.filter(x => x === false).length;
// May need to perfom a check to make sure there are at least 4 columns visible otherwise colspan will be a negative number
var valueColspan = numVisible - 3;
return $('<tr/>')
// .append('<td>Visible columns ' + numVisible + ' - Invisibles col ' + numInvisible + '</td>')
.append('<td class="right" colspan="' + valueColspan + '">Visible columns ' + numVisible + ' - Invisibles ' + numInvisible + '</td>')
.append('<td class="red right">7</td>')
.append('<td class="red right">8</td>')
.append('<td class="red right">9</td>');
// .append('<td>never</td>');
}
}
});
table.on('responsive-resize', function () {
table.draw('page');
});
You can jump to the latest bin by adding /latest
to your URL
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + [ | Indents selected lines |
ctrl + ] | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Clone Bin |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |