JavaScript
var table;
var currGroup;
myDataSrc = [['Tiger Nixon', 'System Architect', 'Edinburgh', '5421', '2011/04/25', '$320,800'],
['Garrett Winters', 'Accountant', 'Tokyo', '8422', '2011/07/25', '$170,750'],
['Ashton Cox', 'Junior Technical Author', 'San Francisco', '1562', '2009/01/12', '$86,000'],
['Cedric Kelly', 'Senior Javascript Developer', 'Edinburgh', '6224', '2012/03/29', '$433,060'],
['Airi Satou', 'Accountant', 'Tokyo', '5407', '2008/11/28', '$162,700'],
['Brielle Williamson', 'Integration Specialist', 'New York', '4804', '2012/12/02', '$372,000']];
$(document).ready(function() {
table = $('#example').DataTable( {
data: myDataSrc,
columns: [
{ title: 'Name' },
{ title: 'Position' },
{ title: 'Office',
render: function(data, type, row, meta){
return '<a href="#">' + data +'</a>';
}},
{ title: 'Extn.' },
{ title: 'Start date' },
{ title: 'Salary' },
],
orderFixed: [[2, 'asc']],
rowGroup: {
enable: false,
dataSrc: 2,
startRender: function ( rows, group ) {
if ( table.rowGroup().dataSrc() === 2 ) {
return '<a href="#">' + table.row( rows[0] ).data()[2] +'</a>';
}
return group;
}
}
} );
// Change the fixed ordering when the data source is updated
table.on( 'rowgroup-datasrc', function ( e, dt, val ) {
//console.log(e);
// console.log(dt);
// console.log(val);
table.column(val).visible(false);
currGroup = val;
table.order.fixed( {pre: [[ val, 'asc' ]]} ).draw();
} );
$('a.group-by').on( 'click', function (e) {
e.preventDefault();
table.column(currGroup).visible(true);
column = $(this).data('column')
if(column == "")
{
table.rowGroup().disable().draw();
}
...