Use multiple DataTables 1.9

Use multiple DataTables 1.9

Adrian2007Adrian2007 Posts: 19Questions: 7Answers: 0

Hello,
I would like to know how to select a DataTables in a page with 2 or more DataTables.

For example:

$('#tableList1').on( 'click', 'tbody tr', function () { //click on every row - this works //do_something
});


$('#tableList1').on( 'click', 'thead tr th:not("#someid")', function () { //click on every cell of the header except the one with id=someid - doesn't work //do something });```

And then the same things for tableList2, tableList3, etc.

Thanx,
A

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Not exactly clear what you are looking for. Here is a single event handler for multiple tables.
    http://live.datatables.net/dozepotu/1/edit

    $(document).ready( function () {
      
      
        $("table").on("click", "tbody tr" , function(){
         alert( $(this).closest("table").attr("id"));
        // do something
    
      });
      var table1 = $('#example1').DataTable();
      var table2 = $('#example2').DataTable();
      var table3 = $('#example3').DataTable();
    
    } );
    
  • Adrian2007Adrian2007 Posts: 19Questions: 7Answers: 0

    Thank you for your rapid answer.
    I actually need to select a DataTables (based on its ID) in order to make some operations (for example click on the columns header or rows) on one DataTables or on another one.
    In my example I wanted to show that clicks on the body of every DataTables (identified by its ID) work but on the header not.

This discussion has been closed.