Problem with fnGetDisplayNodes or fnDrawCallback

Problem with fnGetDisplayNodes or fnDrawCallback

cdrwf150cdrwf150 Posts: 6Questions: 0Answers: 0
edited February 2011 in Plug-ins
I think there might be bug in fnDrawCallback or fnGetDisplayNodes when there are multiple tables on a page with the same definition.

I have a loop where I define n number of tables. The table definition are all the same except for the id.
[code]
var currTable = $("#table_"+id).dataTable(
...
"fnDrawCallback": function() {
if ( typeof this != 'undefined' ) { // make sure table is ready
updateMainBox(this);
}
...
});
[/code]

After each table update, I want to get the top row and print it in a box outside of the table. I use the fnDrawCallback function for this (as shown above)....the code to update this box looks like this:
[code]
function updateMainBox(currTable) {
if (currTable.fnGetDisplayNodes().length>0){
...
}
}
[/code]

This works if there's one table on a page. However, when there are more than one tables on a page the firing from the second table's fnDrawCallback throws the error "Uncaught TypeError: Cannot read property 'aiDisplay' of null" on this line of code in the fnGetDisplayNodes plugin :
[code]
if (oSettings.aiDisplay.length !== 0 ){
[/code]

Also, what's interesting is that I can call updateMainBox(currTable) from outside the fnDrawCallback on any of the tables and it works without a problem.

Any idea what could be causing this or how to work around it? Thanks!

Replies

  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    What selector are you using when you have multiple tables on the page? I presume it's something which matches the multiple tables? If so - then you need to watch when using the API functions because they always apply to the first table in the jQuery object array, unless told otherwise. iApiIndex is the parameter which controls which element of the jQuery array the API method works on: http://datatables.net/development/ .

    Hmm - having said that, I see you are passing currTable into your update function - so actually it looks like you might initialise them separately? Can you post a link to an example showing this issue?

    Allan
This discussion has been closed.