Problem with multiple DataTables on same page

Problem with multiple DataTables on same page

1chc1chc Posts: 3Questions: 0Answers: 0
edited February 2014 in General
Hey there,

following these examples:
http://datatables.net/release-datatables/examples/basic_init/multiple_tables.html
http://datatables.net/release-datatables/examples/api/multi_filter.html

I've build two tables with single column filtering. My problem now is, that the column filter and the TableTools only work for the first table on each page whenever multiple tables appear.

Here's a JSFiddle with example code:

http://jsfiddle.net/vrkS3/

Sorting, etc works for both tables, but filtering and the "save as"-button only work for the first table. I've found several threads dealing with this topic but all were rather old with no satisfying solution, so maybe there came up a solution in the meantime? Concering the column filtering, is my only option using the column-filter plugin?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Could you try DataTables 1.10 ( http://datatables.net/download - the nightly version)? I think it might be fixed with that.

    Allan
  • 1chc1chc Posts: 3Questions: 0Answers: 0
    Okay, i tried the nightly build and the "save as"-button seems to be working now :)
    Looking forward to the release version.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Excellent to hear :-)

    Allan
  • 1chc1chc Posts: 3Questions: 0Answers: 0
    Hm, after some testing I can't get the individual column filtering to work, even when using the column filter plugin.

    Is there a way to get the individual column filter for multiple tables to work? Currently in every setup only the first table will be able the filter the columns. The jfiddle from above (http://jsfiddle.net/vrkS3/) still shows this issue and is using DataTables1.10.

    Thanks in advance :)
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    You are using the old 1.9- style API, so you won't be getting any benefits of the new 1.10 API, but still it would require special consideration. Basically:

    > oTable.fnFilter

    will limit itself to just a single table based on the $.fn.dataTable.iApiIndex ( http://datatables.net/development/ ). You would need to modify that for each table based on which table is being used. Or split the initialisation into multiple table variables.

    With 1.10 it is similar, either use the `table()` API method to reduce the API instance to just the table you want, or split it into multiple parts.

    Allan
  • Barn0wlBarn0wl Posts: 1Questions: 0Answers: 0

    I am having the same issue, how exactly should we split it into multiple parts? Do we call it in two separate function when initializing in a script tag on the page?

  • mehdikmehdik Posts: 7Questions: 0Answers: 0

    I'm also having the same issue, trying to run four datatables in one page (with million+ rows) and use only column text input search boxes for the first table to search through all the tables, each column separately. Any idea or sample?

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

    If you must use a legacy version of DataTables take a look at this plug-in. But I would suggest using the built in search() method in 1.10 to filter multiple tables.

    Allan

  • mehdikmehdik Posts: 7Questions: 0Answers: 0

    Thanks for your reply Allan, I'm using the latest version of datatable, do you have any sample for that search() method in multiple tables to filter columns?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    var allTables = $('table.dataTable').DataTable();
    
    allTables.column( 0 ).search( 'mySearchTerm' ).draw();
    

    Allan

This discussion has been closed.