<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<meta charset=utf-8 />
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<title>DataTables - JS Bin</title>
</head>
<body>
<div class="panel panel-default">
<div class="panel-heading"><h3>Overview</h3></div>
<div class="panel-body">
<table id="mytable" class="table table-condensed table-hover" width=100%">
</table>
</div>
</div>
<div class="modal fade" id="editModal" role="dialog">
<div class="modal-dialog">
<div id="content-data"></div>
</div>
</div>
</body>
</html>
td.details-control {
background: url('https://www.datatables.net/examples/resources/details_open.png') no-repeat center center;
cursor: pointer;
}
td.details-control1 {
background: url('https://www.datatables.net/examples/resources/details_open.png') no-repeat center center;
cursor: pointer;
}
const parentData = [
{column1: 's01', column2: '200 250', column3: 'A / B / C'},
{column1: 's02', column2: '100 200', column3: 'A / D'},
{column1: 's03', column2: '100 300', column3: 'E / F'}
];
const childData = {
s01: [
{column1: 'p1', column2: '5', column3: 'yes', column4: '100 200', column5: 's02', column6: '1', tagged: '0'},
{column1: 'p2', column2: '4', column3: 'yes', column4: '150 250', column5: 's06', column6: '3', tagged: '0'},
{column1: 'p3', column2: '1', column3: 'yes', column4: '150 250', column5: 's07', column6: '71', tagged: '1'},
{column1: 'p4', column2: '2', column3: 'yes', column4: '100', column5: 's03', column6: '35', tagged: '1'}
],
s02: [
{column1: 'p1', column2: '1', column3: 'yes', column4: '150 200', column5: 's02', column6: '21', tagged: '1'},
{column1: 'p2', column2: '3', column3: 'no', column4: '200 250', column5: 's03', column6: '32', tagged: '1'}
],
s03: [
{column1: 'p1', column2: '3', column3: 'yes', column4: '100', column5: 's03', column6: '31', tagged: '1'},
{column1: 'p2', column2: '2', column3: 'yes', column4: '150 300', column5: 's06', column6: '62', tagged: '1'},
{column1: 'p3', column2: '1', column3: 'no', column4: '150', column5: 's01', column6: '13', tagged: '1'}
]
};
const dataTable = $('#mytable').DataTable({
"paging": false,
"lengthChange": false,
"info": false,
data: parentData,
columns: [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{title: 'Col 1', data: 'column1'},
{title: 'Col 2', data: 'column2'},
{title: 'Col 3', data: 'column3'}
],
"order": [[1, 'asc']]
});
$('#mytable').on('click', 'td.details-control', function(){
const parentRow = dataTable.row($(this).closest('tr'));
parentRow.child.isShown() ?
parentRow.child.remove() :
parentRow.child('<table id="details'+parentRow.data().column1+'" class="table table-condensed table-hover"></table>').show();
$(this).closest('tr').toggleClass('shown');
if(!parentRow.child.isShown()) return;
const detailsData = childData[parentRow.data().column1];
$('#details'+parentRow.data().column1).DataTable({
sDom: 't',
data: detailsData,
columns: [
{title: 'Child 1', data: 'column1'},
{title: 'Child 2', data: 'column2'},
{title: 'Child 3', data: 'column3'},
{title: 'Child 4', data: 'column4'},
{title: 'Child 5', data: 'column5'},
{title: 'Child 6', data: 'column6'},
{title: 'Tagged', data: 'tagged', "render": function (data, type, row) {
return (data === '1') ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>';}
},
{title: 'Action', "render": function (data, type, row) {
return '<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#editModal" data-id="1"><i class="glyphicon glyphicon-pencil"> </i>Edit</button>';}
}
]
});
});
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. |