Error on multi table with .fnGetData .fnGetPosition

Error on multi table with .fnGetData .fnGetPosition

onservonserv Posts: 3Questions: 0Answers: 0
edited December 2011 in Bug reports
Hi,
Thans for this very nice js framework.

I have this problem :
I have 2 tables on a web page ( http://site.loup-garou.fr/templates/lg/inscription.php ).
I initialize with that :
[code] $('table').dataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bSort": false,
"bInfo": false,
"bAutoWidth": false
});

oTable = $('table').dataTable();[/code]

but I have an error on the second table If for example I try a simple .fnGetData or .fnGetPosition.

Must I instance the different table seperatly ?

Thanks for your help

Replies

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    No you don't need to, but if you don't you need to use $.fn.dataTableExt.iApiIndex to tell DataTables which table you want to use: http://datatables.net/development/ . API methods currently only operate on one table at a time.

    Allan
  • onservonserv Posts: 3Questions: 0Answers: 0
    edited December 2011
    In fact i need to have the same function for all my table.
    So it is possible to have the same Table twice et use .fnGetData ?
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Absolutely. For example applying fnFilter to two tables:

    [code]
    var oTables = $('#example').dataTable();

    // Filter table 1
    oTables.fnFilter( 'hello' );

    // Filter table 2
    $.fn.dataTableExt.iApiIndex = 1;
    oTables.fnFilter( 'hello' );

    // Reset iApiIndex
    $.fn.dataTableExt.iApiIndex = 0;
    [/code]

    In future (v1.10) I might make this a lot easier using an option for the API. It is also possible to wrap this up into an API method such as: http://datatables.net/plug-ins/api#fnFilterAll

    Allan
  • onservonserv Posts: 3Questions: 0Answers: 0
    edited December 2011
    Hi,
    I do something like that but I think it's an agly way....
    [code]
    try {
    var aPos = oTable.fnGetPosition( this );
    var sejour = oTable.fnGetData(this.parentNode,0); //on précise 0 pour ne recupérer la valeur que de la 1ere colonne
    }
    catch(err) {
    $.fn.dataTableExt.iApiIndex = 1;
    var aPos = oTable.fnGetPosition( this );
    var sejour = oTable.fnGetData(this.parentNode,0); //on précise 0 pour ne recupérer la valeur que de la 1ere colonne
    }
    [/code]

    And it's working for 2 tables only. I have to count the number of $('table') and loop ;-/
    Any specific method for Counting ?
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    edited December 2011
    $('table').length would do it. Or oTable.length.

    As I mentioned, take a look at fnFilterAll - that might help you understand what is going on in the background.

    Allan
This discussion has been closed.