How to reference the current dataTable Object

How to reference the current dataTable Object

xzvtzxzvtz Posts: 3Questions: 1Answers: 0

I am trying to implement a table that identifies the first value in a row similar to this.

https://datatables.net/examples/advanced_init/events_live.html

This is my Javascript code

$(document).ready(function() { var table = $('#tablepress-2').DataTable(); $('#tablepress-2 tbody').on('click', 'tr', function () { var data = table.row( this ).data(); } ); } );

However i get the following error "DataTables warning: table id=tablepress-2 - Cannot reinitialise DataTable. "

I figured tablepress already initiated the dataTable hence i only need to reference the same object again.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,364Questions: 26Answers: 4,956

    I built a test case for you with your code snippet and it works as expected:
    http://live.datatables.net/hosajizi/1/edit

    var table = $('#tablepress-2').DataTable(); is giving an API instance so shouldn't be the problem. I'm not familiar with tablepress but you will need to review the full page to see where else the Datatable is initialized or provide a link to a page showing the issue for someone here to look at.

    Also this technote talks about the error:
    https://datatables.net/manual/tech-notes/3

    Kevin

  • xzvtzxzvtz Posts: 3Questions: 1Answers: 0

    the error disappeared when i added **bRetrieve": true ** however the Column Filter Widget stopped displaying as well.

  • kthorngrenkthorngren Posts: 21,364Questions: 26Answers: 4,956

    Is it possible that the code you posted is executed before tablepress initializes the Datatable?

    Kevin

  • xzvtzxzvtz Posts: 3Questions: 1Answers: 0

    It is, because it's currently in the header but I already tried transferring it to the footer and the problem still persists

  • kthorngrenkthorngren Posts: 21,364Questions: 26Answers: 4,956
    edited October 2017 Answer ✓

    Maybe this thread will help:
    https://datatables.net/forums/discussion/comment/102228/#Comment_102228

    Without seeing your code its hard to troubleshoot.

    Kevin

This discussion has been closed.