2 table views - Synchronized tables

2 table views - Synchronized tables

robertshawnrobertshawn Posts: 5Questions: 2Answers: 0

Is it possible to have 2 tables that are controlled by 1 filter set?

I've used FilterMultipleTables from yadcf to do it in this example.

Is there another way to have synchronized tables? Or 2 views of the same table?

example: https://live.datatables.net/yugiwahi/1/edit

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    edited September 2023

    It is possible. This example shows one way to do this:
    https://live.datatables.net/jujuqixe/1/edit

    First it sets default config options for all tables. Your solution might not need this just made the example easier. It uses dom to show only the info element for the second table.

    The key to this example is to use only the inputs for the first table to drive the second. You can try controlling both tables with inputs from both but it makes the using the Datatables events more complicated as you can easily get into an infinite loop.

    The example uses the search, order, page, and length to update the second Datatable. It uses the page.info() to get the paging info, order() to get the current order and search() to get the current search term.

    When changing the page length or page number it uses draw() with the page parameter to stay on the same page and not recalculate the sorting and searching.

    You can also you something like these column search examples:
    https://datatables.net/examples/api/multi_filter.html
    https://datatables.net/examples/api/multi_filter_select.html

    And use column().search() with the inputs search term on table 2. This is simulated with the Tiger search button.

    Kevin

  • robertshawnrobertshawn Posts: 5Questions: 2Answers: 0

    Thank you Kevin. I think this first example is just what I'm looking for. Is it possible to create, or is there an existing table.on function for Search Panes?

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

    Unfortunately no - sorry. Not at this time at least. SearchPanes doesn't expose an API to get or set its current state. Without that, there would be no way to have a single instance of SearchPanes control two tables. Sorry.

    Allan

Sign In or Register to comment.