<html>
<head>
<!-- jQuery 3.6.0 -->
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<!-- Bootstrap4 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<!-- DataTables 1.12.1 -->
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<!-- DataTables Bootstrap4 1.12.1 -->
<script src="https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap4.min.js"></script>
<link href="https://cdn.datatables.net/1.12.1/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />
<!-- SearchPanes -->
<script src="https://cdn.datatables.net/searchpanes/2.0.2/js/dataTables.searchPanes.js"></script>
<!-- nighly does not work
<script src="https://nightly.datatables.net/searchpanes/js/dataTables.searchPanes.js?2022-09-16"></script>
-->
<!-- SearchPanes Bootstrap4 -->
<script src="https://cdn.datatables.net/searchpanes/2.0.2/js/searchPanes.bootstrap4.js"></script>
<!-- nightly does not work
<script src="https://nightly.datatables.net/searchpanes/js/searchPanes.bootstrap4.js?2022-09-16"></script>
-->
<link href="https://nightly.datatables.net/searchpanes/css/searchPanes.bootstrap4.css?2022-09-16" rel="stylesheet" type="text/css" />
<!-- Buttons 2.2.3 -->
<script src="https://cdn.datatables.net/buttons/2.2.3/js/dataTables.buttons.min.js"></script>
<!-- Buttons Bootstrap4 2.2.3 -->
<script src="https://cdn.datatables.net/buttons/2.2.3/js/buttons.bootstrap4.min.js"></script>
<link href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" />
<!-- Select 1.4.0 -->
<script src="https://cdn.datatables.net/select/1.4.0/js/dataTables.select.min.js"></script>
<!-- Select Bootstrap4 1.4.0 -->
<link href="https://cdn.datatables.net/select/1.4.0/css/select.bootstrap4.min.css" rel="stylesheet" type="text/css" />
<title>DataTables - JS Bin</title>
<meta charset=utf-8 />
</head>
<body>
<table id="outer" width="100%">
<thead>
<tr>
<th>+</th>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>Gender</th>
</tr>
</thead>
</table>
</body>
</html>
body {
font: 90%/1.45em "Helvetica Neue", HelveticaNeue, Verdana, Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
color: #333;
background-color: #fff;
}
$(document).ready(function() {
var outerTableElement = $('table#outer');
outerTableElement.DataTable({
dom: 'Bft',
ajax: 'http://datatables.showroom.efficient.it/data/?outer',
buttons: [
{
extend: 'searchPanes',
config: {
layout: 'columns-1',
initCollapsed: true,
cascadePanes: true,
viewTotal: true
}
}
],
columns: [
{
name: 'plus',
searchPanes: {
show: false
},
defaultContent: '<button class="plus">+</button>'
},
{
data: 'first_name',
name: 'first_name',
searchPanes: {
show: true
}
},
{
data: 'last_name',
name: 'last_name',
searchPanes: {
show: true
}
},
{
data: 'email',
name: 'email',
searchPanes: {
show: true
}
},
{
data: 'gender',
name: 'gender',
searchPanes: {
show: true
}
}
],
stateSave: true,
serverSide: true,
stateSaveCallback: function(settings, data) {
console.log('stateSaveCallback() outer');
jQuery.ajax({
type: 'POST',
url: 'http://datatables.showroom.efficient.it/state/save_new.php',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
id: 'outer',
data: data
})
});
},
stateLoadCallback: function(settings, callback) {
jQuery.ajax({
type: 'POST',
url: 'http://datatables.showroom.efficient.it/state/load.php',
dataType: 'json',
data: {
id: 'outer'
},
success: function(response) {
if(response.success) {
callback(response.data);
}
else {
callback(null);
}
}
});
}
});
outerTableElement.on('draw.dt', function() {
outerTableElement.find('button.plus').on('click', function() {
if(!$(this).hasClass('open')) {
$(this).addClass('open');
$(this).parents('tr').after('<tr><td colspan="3"><table class="inner" width="100%"><thead><tr><th>Model</th><th>Year</th><th>Email</th></tr></thead></table></td></tr>');
var innerTableElement = $(this).parents('tr').next('tr').find('table.inner');
innerTableElement.DataTable({
dom: 'Bft',
ajax: 'http://datatables.showroom.efficient.it/data/?inner',
buttons: [
{
extend: 'searchPanes',
config: {
layout: 'columns-1',
initCollapsed: true,
cascadePanes: true,
viewTotal: true
}
}
],
columns: [
{
data: 'model',
searchPanes: {
show: true
}
},
{
data: 'year',
searchPanes: {
show: true
}
},
{
data: 'email',
searchPanes: {
show: true
}
}
],
stateSave: true,
serverSide: true,
stateSaveCallback: function(settings, data) {
console.log('stateSaveCallback() inner');
jQuery.ajax({
type: 'POST',
url: 'http://datatables.showroom.efficient.it/state/save_new.php',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
id: 'inner',
data: data
})
});
},
stateLoadCallback: function(settings, callback) {
jQuery.ajax({
type: 'POST',
url: 'http://datatables.showroom.efficient.it/state/load.php',
dataType: 'json',
data: {
id: 'inner'
},
success: function(response) {
if(response.success) {
callback(response.data);
}
else {
callback(null);
}
}
});
}
});
}
});
});
});
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. |