Events binding on multiple DataTable

Events binding on multiple DataTable

Rob616Rob616 Posts: 3Questions: 1Answers: 0

Hi, I am trying to bind my events on the same class DataTable

Interface;

I am looping through the users and create a table for each
<?php foreach($all_users as $user): ?>
<table class="table table-hover tasks-table">

So in the end, I have 4 DataTable with the class "task-table" initialized with;

The issue is, only the first table get binded to my event (which is normal), How can I proceed to make it work?

$('.tasks-table').DataTable() also doesn't work, it creates a new DataTable

Thanks for the help!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @Rob616 ,

    I tried it here, a very simplified version of your code, and the event is bound to both tables. Could you modify my example, or create a similar example with your config, that demonstrates the problem, please.

    Cheers,

    Colin

  • Rob616Rob616 Posts: 3Questions: 1Answers: 0

    @colin

    Unfortunatly, I am unable to reproduce the error, my full code; live.datatables.net/liduyeku/1/edit

    On my side, I am getting the error on this line;
    var rowData = table.row( diff[i].node ).data();

    Uncaught TypeError: Cannot read property '_aData' of undefined
    at s.<anonymous> (jquery.datatable.min.js:185)
    at s.data (jquery.datatable.min.js:171)
    at HTMLTableElement.<anonymous> (global_2.js:179)
    at HTMLTableElement.dispatch (jquery-2.2.3.min.js:3)
    at HTMLTableElement.r.handle (jquery-2.2.3.min.js:3)
    at Object.trigger (jquery-2.2.3.min.js:4)
    at n.fn.init.triggerHandler (jquery-2.2.3.min.js:4)
    at s.<anonymous> (jquery.datatable.min.js:545)
    at s.iterator (jquery.datatable.min.js:168)
    at k._emitEvent (jquery.datatable.min.js:545)

    I am not sure why, the error only occurs when i try switching index of the 2nd table.

    Table1:
    x1 : ok
    x2 : ok

    Table2
    x1: ok
    x2; ok
    x3 : error

    Is it because the var Table only store index of first table?

    I appreciate alot thanks for the help

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @Rob616 ,

    Those errors can occur when the number of columns are different - so it would be worth checking your data to make sure the column count of all the rows/headers/footer are all correct.

    It's a shame you can't reproduce it, could you link to your page?

    Cheers,

    Colin

  • Rob616Rob616 Posts: 3Questions: 1Answers: 0

    Colin,

    I managed to fix it by adding;

    $(document).ready( function () {

    });

    The error is how I load my data, and the table were initialized mid loading. This is why we are unable to reproduce it here, the data is always the same.

    Thank you very much, stating back from 0 with your code did it

This discussion has been closed.