(function( $ ) {
'use strict';
var datatableInit = function() {
var $table = $('#datatable-details');
// format function for row details
var fnFormatDetails = function( datatable, tr ) {
var data = datatable.fnGetData( tr );
return [
'
',
'',
'Rendering engine: ',
'' + data[1]+ ' ' + data[4] + ' ',
' ',
'',
'Link to source: ',
'Could provide a link here ',
' ',
'',
'Extra info: ',
'And any further details here (images etc) ',
' ',
''
].join('');
};
// insert the expand/collapse column
var th = document.createElement( 'th' );
var td = document.createElement( 'td' );
td.innerHTML = ' ';
td.className = "text-center";
$table
.find( 'thead tr' ).each(function() {
this.insertBefore( th, this.childNodes[0] );
});
$table
.find( 'tbody tr' ).each(function() {
this.insertBefore( td.cloneNode( true ), this.childNodes[0] );
});
// initialize
var datatable = $table.dataTable({
aoColumnDefs: [{
bSortable: false,
aTargets: [ 0 ]
}],
aaSorting: [
[1, 'asc']
]
});
// add a listener
$table.on('click', 'i[data-toggle]', function() {
var $this = $(this),
tr = $(this).closest( 'tr' ).get(0);
if ( datatable.fnIsOpen(tr) ) {
$this.removeClass( 'fa-minus-square-o' ).addClass( 'fa-plus-square-o' );
datatable.fnClose( tr );
} else {
$this.removeClass( 'fa-plus-square-o' ).addClass( 'fa-minus-square-o' );
datatable.fnOpen( tr, fnFormatDetails( datatable, tr), 'details' );
}
});
};
$(function() {
datatableInit();
});
}).apply( this, [ jQuery ]);