How do i append a row to nRow, using fnRowCallback?

How do i append a row to nRow, using fnRowCallback?

EvanCarrollEvanCarroll Posts: 7Questions: 1Answers: 0
edited July 2010 in General
I'm trying to write an example of a table, that just appends a blank row with stuff. The currently example of this is broken. I'm looking to figure out what I have to do here, to get $tr to append to nRow. This is a very simple question because I've removed the more complex and useful portions.

[code]
$(document).ready( function () {
oTable = $("table").dataTable({
bJQueryUI: true
, bPaginate: false
, bAutoWidth: false
, fnRowCallback: function( nRow, aData, iDisplayIndex ) {
var $tr = $('').append(
$('', { colspan: $(nRow).children('td').length, text:'HALLO WIN' } )
)

// Something here to append $tr to nRow

return nRow
}
})
} )
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What you are looking for here isn't possibly quite like that - not a limitation of DataTables, just simply how the DOM works. What you are looking for is insertAfter (or insertBefore), so as to have the $tr variable a sibling of nRow, rather than a child of nRow (which is what append does).

    So the question is how to achieve the same effect... You can use fnOpen which will do something similar, or you could simply parse over the table in the DOM after DataTables has drawn and insert the rows there.

    Allan
  • EvanCarrollEvanCarroll Posts: 7Questions: 1Answers: 0
    Allan, I'm not seeing an insertAfter
    https://developer.mozilla.org/en/insertbefore

    That append was just verbial. I was hoping you would fill in the blank with whatever worked. This question is a follow up on this: http://datatables.net/forums/comments.php?DiscussionID=57&page=1#Item_14 I'm just trying to find a static way to do this that works with multiple pages.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    insertAfter isn't in the standard DOM (it really should be - don't know why they didn't add it). jQuery and just about every other JS library make it available: http://api.jquery.com/insertAfter/

    There is no way to use fnRowCallback to do exactly what you are looking for here - only one node can be added to the DOM. As I mentioned, using fnDrawCallback could be used to do as you need - or possibly even fnRowCallback to store references to all of the nodes you want to add something after, and then fnDrawCallback to do the insert.

    Allan
This discussion has been closed.