Two datatables on the page

Two datatables on the page

vuceticavucetica Posts: 15Questions: 0Answers: 0
edited September 2009 in General
When I have two datatables on the page, and do filtering (search) on one of them, datatables can not distinguish between those two datatables and does search on both of them. What I'm doing wrong? Thanks!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi vucetica,

    How are you doing your filter? Using fnFilter() or the default input box? Here is an example of using multiple tables: http://datatables.net/examples/basic_init/multiple_tables.html . You can also use "$.fn.dataTableExt.iApiIndex" if you are using the API to tell DataTables which object it should use if you have created multiple tables with the initialiser: http://datatables.net/development/

    Regards,
    Allan
  • vuceticavucetica Posts: 15Questions: 0Answers: 0
    Hi Allan,
    thanks for quick reply. We are using default input box. Here is the example how we create two datatables:
    [code]
    $(document).ready(function() {
    oTable = $('#table1').dataTable({
    "bFilter": true,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "some_url.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    aoData.push( { "name": "something" } );
    $.getJSON( sSource, aoData, function (json) {
    fnCallback(json)
    } );
    }
    }).ajaxComplete(function(){
    // Something1
    });

    oTable2 = $('#table2').dataTable({
    "bFilter": true,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "some_url2.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    aoData.push( { "name": "something2" } );
    $.getJSON( sSource, aoData, function (json) {
    fnCallback(json)
    } );
    }
    }).ajaxComplete(function(){
    // Something2
    })
    });
    [/code]

    In the code examples we saw that you are using one .dataTable call to initialize all the datatables on the page. But in that way we are not able do give different initialization options to our datatables. Any suggestion? Thanks!

    Aca
  • dujchedujche Posts: 3Questions: 0Answers: 0
    Hi! I'm also interested in this issue. Is there any solution for this?

    Regardz,
    Dusan
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Interesting - I've just tried the following initialiser on my demo page and it appears to work as expected:

    [code]
    $('.dataTable:eq(0)').dataTable();
    $('.dataTable:eq(1)').dataTable();
    $('.dataTable:eq(2)').dataTable();
    [/code]
    This is similar to what you've got, although no initialisation information, and not using server-side processing - although those functions should be wrapped up so tight that the scope isn't going to jump to something unexpected.

    Do you have an example you could link to which shows the problem you are having? That would be most useful for tracing this one down!

    Regards,
    Allan
  • vuceticavucetica Posts: 15Questions: 0Answers: 0
    Sorry, but when creating some tests we have failed to reproduce the error (which still exists in our production code). We will have to take a look at our code before coming back to you with the non working example. Thanks.

    Aca
  • vuceticavucetica Posts: 15Questions: 0Answers: 0
    We have found the problem. It was not caused by the datatables, but the plugin called fnSetFilteringDelay. Here is the solution to the problem: http://datatables.net/forums/comments.php?DiscussionID=392&page=1#Item_0
    Thanks, Allan.

    Aca
  • dujchedujche Posts: 3Questions: 0Answers: 0
    I'm using fnSetFilteringDelay, and this solved the issue. Thanks everyone!

    Regards,
    Dusan
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi vucetica,

    Thanks for the update. Good to hear that there is already a solution for the issue :-)

    Allan
This discussion has been closed.