Identifying a table in multiple tables example

Identifying a table in multiple tables example

vigdalvigdal Posts: 7Questions: 0Answers: 0
edited April 2009 in General
I have a page with two table using the DataTables class.
I have to identify in javascript some of the rows from the second Table.
I initialize the tables with this javascript :
oTable = jQuery('.dataTable').dataTable( );
If i display the oTable.length, i got "2" which is the number of tables in the document; and if i display the oTable.fnGetNodes().length, i obtain the number of visible rows in the "first" table.
So my question is:
How can i see the number of visible rows in the second table?

Thank you for your responses.

Replies

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    Hi vigdal,

    That's a good one! I hadn't actually considered the possibility of doing this before. The problem is that the API functions use "_fnSettingsFromNode( this[0] );" to get the settings object for a particular table. As you can see the array index is hard coded as '0' which is why you are always getting information about the first table.

    Here is my proposed fix (I'd be interested in your comments), I can provide a variable in $.fn.dataTableExt which will allow you to select which array index should be used, with zero as default. So you could do something like:

    $.fn.dataTableExt.iApiIndex = 2;
    oTable.fnGetNodes()...

    Other options include passing in the index that you want (not too attractive as it might break current applications), or moving the elements of the jQuery array (urgh).

    Thanks,
    Allan
  • vigdalvigdal Posts: 7Questions: 0Answers: 0
    Hi Allan,
    Your proposed fix is a nice one for me.
    And i understand the problem which can be caused by the index on the current applications.
    I try your solution on my way and i will say you if i succeed or not (i am not an expert in JQuery), but i like to peel code .
    And thank you again for your interest.
  • vigdalvigdal Posts: 7Questions: 0Answers: 0
    Hi again,

    I just finish to try your solution, and it works fine.
    I add the variable "$.fn.dataTableExt.iApiIndex" as you say, and in my javascript for example i did that:

    oTable.dataTableExt.iApiIndex=1;
    alert(oTable.fnSettings().aiDisplay.length);
    for(i=0;i
  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    Ideal - good to know that works. I'll put that change into the next release of DataTables using the iApiIndex variable :-)

    Allan
This discussion has been closed.