.DataTable doesn't return the tabel reference

.DataTable doesn't return the tabel reference

lucasexatolucasexato Posts: 3Questions: 2Answers: 0

Hi, I'm facing a problem while using datatables with local data. If I load the table data from an ajax link, everything runs fine. However, if I use local data (by providing the table rows using <tr>...</tr>), the .DataTable call returns undefined (but the table works as expected). Here is a real case:

Here, tbRemote is correctly set.

var tbRemote = $("#tbRemote").DataTable({
"responsive": true,
"searching": true,
"ordering": true,
"lengthChange": true,
"autoWidth": false,
"initComplete": tbRemoteComplete,
"processing": true,
"serverSide": true,
"ajax": {
"url": "/tool/accounts-feed/",
"type": "POST",
},
"columnDefs": [ { "targets": [0], "visible": false}, ],
"paging": true,
"buttons": [ "copy", "csv", "excel", "pdf", "print", "colvis" ]
});

However, here tbLocal is undefined, as always happens with local data.

var tbLocal = $("#tbLocal").DataTable({
"responsive": true,
"searching": true,
"ordering": true,
"lengthChange": true,
"autoWidth": false,
"initComplete": tbLocalComplete,
"columnDefs": [ { "targets": 0, "render": fulldate } ],
"paging": true,
"buttons": [ "copy", "csv", "excel", "pdf", "print", "colvis" ]
});

How can I get the reference to my datatable in this case?

Answers

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    Sounds like a Javascript scoping problem. Without seeing your code and where the problem occurs its hard to say. The data source doesn’t matter.

    Please post a link to your page or a test case replicating the issue so we can help debug.

    Kevin

Sign In or Register to comment.