can hidden row toggle column be something OTHER than column 0?

can hidden row toggle column be something OTHER than column 0?

devitdevit Posts: 2Questions: 0Answers: 0
edited February 2013 in General
The example here: http://www.datatables.net/release-datatables/examples/api/row_details.html, gives a great example of how to add a toggle column that, when the toggle image is clicked on a particular row, a hidden row below that is then shown with additional data. GREAT FEATURE. The example shows the column created as becoming column 0.

I have 8 columns in my table and I want the toggle image to be in column 5. Was thinking it would be as simple as revising the "childNodes[0] in the code below to childNodes[4], but that seems to cause problems. Is it able to be done in the current version of DataTables? If so, can an example be provided like that on the page referenced above?

..................
$('#classlist thead tr').each( function () {
this.insertBefore( nCloneTh, this.childNodes[0] );
} );

$('#classlist tbody tr').each( function () {
this.insertBefore( nCloneTd.cloneNode( true ), this.childNodes[0] );
} );
..................

Thanks.

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    It should be as simple as sicking the image tag into the 5th column, yes.

    If you are using Ajax loaded data, it is actually easier to use sDefaultContent rather than manipulating the DOM that way - but if you've got a DOM sourced table, that might be the best way of doing it.

    Allan
  • devitdevit Posts: 2Questions: 0Answers: 0
    Thanks Allan. Looks like I was not completely understanding childNodes. Was thinking childNodes[0] equated to column 0 and thus childnodes[5] would equate to column 6. So the question I have now is, why use childNodes in the example as opposed to getElementsByTagName('th')[5]?

    And a VERY minor FYI, the example on this page: http://www.datatables.net/extras/fixedheader/options for "offsetTop" has "table" where it should be "oTable". Threw me off for a second. By the way, is there any conflict where fixedheader will not work when hidden rows are also being used?
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Thanks for spotting the example typo. Now fixed.

    > So the question I have now is, why use childNodes in the example as opposed to getElementsByTagName('th')[5]?

    Because it is heck of a lot faster to use childNodes if you just want the first and you know the structure. However, that doesn't account for text nodes, which is likely what you are hitting, so yes, using jQuery of getElementsByTag name might be better long term.

    Allan
This discussion has been closed.