How to split record across multiple rows
How to split record across multiple rows
doug_hale_jr
Posts: 22Questions: 0Answers: 0
Hi all. I have records that contain a "notes" field. I want all of the fields except the notes field to appear on one row and I want the notes to show up on a second row. The notes field does not require a header. I have looked at the examples but could not figure out how to achieve my goal from them.
Thank you for any help that can be provided.
Doug
Thank you for any help that can be provided.
Doug
This discussion has been closed.
Replies
Do you mean something like this: http://datatables.net/examples/api/row_details.html ? If not, could you elaborate a little please?
Thanks!
Allan
Does this sound right?
Ah okay - so basically you just want the details row from my example to be "open" all the time? You could just to that then - when the initialisation of the table is complete, just call fnOpen() for all of the tr nodes in the table (the open rows are retained over paging/filtering etc - unless you are using server-side processing...). This way you wouldn't need to worry about the rows being "attached" to a parent etc.
Does that sound like it work work for you?
Regards,
Allan
[code]
var oTable;
/* Formating function for row details */
function fnFormatDetails ( nTr )
{
var iIndex = oTable.fnGetPosition( nTr );
var aData = oTable.fnSettings().aoData[iIndex]._aData;
var sOut = '';
sOut += 'Rendering engine:'+aData[1]+' '+aData[4]+'';
sOut += 'Link to source:Could provide a link here';
sOut += 'Extra info:And any further details here (images etc)';
sOut += '';
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) );
} );
});
[/code]
I've just experimented with this a little bit, and it's actually a little more complicated than I had thought... DataTables (at the moment) requires that a row be 'visible' (i.e. on the page) before it can be opened - which is, I suspect, where you are running into issues.
So two ways around this. The first is to edit the fnOpen function to wrap the 'insertAfter' line like so:
[code]
/* 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);
}
[/code]
Which I will include in the next release of DataTables. With this - your current code should work as is.
That is probably the better option - but another one is to use fnDrawCallback to open any rows which aren't already open on display:
[code]
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' );
} )
[/code]
Regards,
Allan
Row 1 - Highlighted
Row 1 detail - no highlight
Row 2 - No highlight
Row 2 detail - no highlight
pattern repeats
Row 1 - Highlighted
Row 1 detail - Highlighted
Row 2 - No highlight
Row 2 detail - No highlight
Row 3 begins repeat highlighting as Row 1
Thanks
Do you mean "highlighted" as in tr:hover? If so, you'll need to bare in mind that the detail row is actually a separate tr element, and as such it's highlighting will be separate from the "parent" (it's not really a parent in the DOM). To overcome this, you'll need to an an event handler to the tr elements. Something like - if it's a regular table row, add a class to the "child" row to highlight it. If it's a "child" row, add a class to the "parent" row to highlight it.
Regards,
Allan
Current:
Row 1 = blue
Row 1 detail = Grey
Row 2 = white
Row 2 detail = Grey
Goal:
Row 1 = blue
Row 1 detail = blue
Row 2 = white
Row 2 detail = white
Thanks
Doug
Allan
Thanks
Doug
[code]
var nTrs = document.getElementsByTagName('tr');
for ( var i=0, iLen=nTrs.length ; i