var oTable;
/* Formating function for row details */
function fnFormatDetails ( nTr )
{
var iIndex = oTable.fnGetPosition( nTr );
var aData = oTable.fnSettings().aoData[iIndex]._aData;
var sOut = '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">';
sOut += '<tr><td>Rendering engine:</td><td>'+aData[1]+' '+aData[4]+'</td></tr>';
sOut += '<tr><td>Link to source:</td><td>Could provide a link here</td></tr>';
sOut += '<tr><td>Extra info:</td><td>And any further details here (images etc)</td></tr>';
sOut += '</table>';
return sOut;
}
$(document).ready(function() {
/*
* Initialse DataTables, with no sorting on the 'details' column
*/
oTable = $('#aircraft').dataTable( {
"bPaginate": false,
"iDisplayLength": 500,
"bLengthChange": false,
"bProcessing": true,
"bFilter": true,
"bInfo": true,
"bAutoWidth": false,
"sDom": 'rtip',
"aoColumns": [
{ "sWidth": '30px' },
{ "sWidth": '40px' },
{ "sWidth": '30px' },
{ "sType": 'block-custom', "sWidth": '30px' },
{ "sWidth": '30px' },
{ "sWidth": '120px' },
{ "sWidth": '60px' },
{ "sWidth": '60px' },
{ "sWidth": '60px' },
null
] } );
$(oTable.fnGetNodes()).each( function () {
oTable.fnOpen( this, fnFormatDetails(this) );
} );
});
/* If the nTr isn't on the page at the moment - then we don't insert at the moment */
var nTrs = $('tbody tr', oSettings.nTable);
if ( $.inArray(nTr, nTrs) != -1 )
{
$(nNewRow).insertAfter(nTr);
}
Which I will include in the next release of DataTables. With this - your current code should work as is.
oTable = $('#example').dataTable( {
"fnDrawCallback": function () {
/* Open rows for all pages - after initialisation */
if ( typeof oTable != 'undefined' ) {
$('#example tbody tr:not(.details)').each( function () {
oTable.fnOpen( this, fnFormatDetails(this), 'details' );
} )
}
}
});
/* Open rows for the first page */
$('#example tbody tr').each( function () {
oTable.fnOpen( this, fnFormatDetails(this), 'details' );
} )
var nTrs = document.getElementsByTagName('tr');
for ( var i=0, iLen=nTrs.length ; i<iLen ; i+=2 )
{
if ( nTrs[i].className.match(/odd/) ) {
$(nTrs[i+1]).removeClass("odd even").addClass('odd');
} else {
$(nTrs[i+1]).removeClass("odd even").addClass('even');
}
}
Allan It looks like you're new here. If you want to get involved, click one of these buttons!
Get useful and friendly help straight from the source.