<html>
<head>
<link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<link href="https://cdn.datatables.net/rowgroup/1.2.0/css/rowGroup.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<script src="https://cdn.datatables.net/rowgroup/1.2.0/js/dataTables.rowGroup.js"></script>
<meta charset=utf-8 />
<title>DataTables - JS Bin</title>
</head>
<body>
<a class="dnr-group-by-office" data-column="Office">Group by Office</a>
<a class="dnr-group-by-date" data-column="Dateonly">Group by Date</a>
<a class="dnr-disable-group">Disable Grouping</a>
<div class="container">
<table id="example" class="display nowrap" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Office</th>
<th>Datetime</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Office</th>
<th>Datetime</th>
</tr>
</tfoot>
</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;
}
.dnr-disable-group {
color:red;
padding: 0.5em;
}
.dnr-group-by-office {
color:darkgreen;
padding: 0.5em;
}
.dnr-group-by-date {
color:blue;
padding: 0.5em;
}
a:hover {
cursor:pointer;
}
var currGroup;
var table;
$(document).ready( function () {
var TableData = [
{Name: 'Tiger Nixon', Office: 'Edinburgh', Timestamp: 1672255040037.893, Dateonly: "2022-12-28", Timeonly:"19:17:20"},
{Name: 'Garrett Winters', Office: 'Edinburgh', Timestamp: 1672255040403.037, Dateonly: "2022-12-28", Timeonly:"19:17:20"},
{Name: 'Ashton Cox', Office: 'New York', Timestamp: 1662254052834.487, Dateonly: "2022-09-04", Timeonly:"01:14:12"},
{Name: 'Cedric Kelly', Office: 'San Francisco', Timestamp: 1652254052834.487, Dateonly: "2022-05-11", Timeonly:"07:27:32"},
];
table = $('#example').DataTable( {
data: TableData,
columns: [
{ data: 'Name', name: 'Name'},
{ data: 'Office', name: 'Office'},
// { data: 'Timestamp', name: 'Timestamp'},
{
data: 'Timestamp', name: 'Timestamp',
render: function ( data, type, row, meta ) {
return convertTimestamp(data);
}
},
{ data: 'Dateonly', name: 'Dateonly', visible: false },
{ data: 'Timeonly', name: 'Timeonly', visible: false },
// {
// data:null,name: 'DateOnly',
// visible: false,
// render: function( data, type, row, meta ) {
// return convertToDateOnly(row);
// }
// }
],
orderFixed:[[1, 'asc']],
rowGroup: {dataSrc: "Office"}
});
table.on('rowgroup-datasrc', function(e, dt, val) {
var colIndex = table.column( val + ':name' ).index();
table.order.fixed( {pre: [[colIndex, 'asc']]} ).draw();
});
$('a.dnr-group-by-office').on('click', function(e) {
e.preventDefault();
table.rowGroup().enable().draw();
table.rowGroup().dataSrc( $(this).data('column'));
});
$('a.dnr-disable-group').on('click', function(e) {
e.preventDefault();
table.rowGroup().disable().draw();
});
$('a.dnr-group-by-date').on('click', function(e) {
e.preventDefault();
table.rowGroup().enable().draw();
table.rowGroup().dataSrc( $(this).data('column'));
//var dates = table.column(2).data();
//console.log(dates)
//table.rowGroup().dataSrc( dates);
});
} );
function convertTimestamp(long) {
var dt = new Date(long).toISOString();
return dt.slice(0,10) + " " + dt.slice(-13, -5);
}
// function convertToDateOnly(str) {
// //var dt = new Date(long).toISOString();
// //return dt.slice(0,10);
// console.log("str:",str);
// return str.substring(0,11);
// }
This bin was created anonymously and its free preview time has expired. Get a free unrestricted account
Dismiss xShortcut | 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. |