table.ajax.reload() vs $('#TableID').DataTable().ajax.reload();
table.ajax.reload() vs $('#TableID').DataTable().ajax.reload();
I have a series of tables that need to be reloaded on a click.
The code is very simple:
releaseGeneralInfoTable.ajax.reload();
releasePhysicalInfoTable.ajax.reload();
requestFormProgramTable.ajax.reload();
requestFormResearchTable.ajax.reload();
parasitoidRequestTable.ajax.reload();
all the tables go to the same database, have very similar js and PHP scripts.
But one of them would not reload.
I tried multiple tricks and double-checked everything to no avail. The ajax part of the js script is identical, and it works in the first load. It just won't go with table.ajax.reload();
Then I replaced "table" with $('#TableID').DataTable()
Bam! it works.
What is the rational on this?
Answers
You will want to read about Accessing the API.
Do you get errors in the browser's console?
As long as the variable
table
contains an instance of the Datatables API, ievar table = $('#TableID').DataTable();
, and is accessible within the scope you are trying to use it there is no difference betweentable.ajax.reload();
and$('#TableID').DataTable().ajax.reload();
.Kevin
The console shows no errors.
Yes. there is a var table = $('#TableID').DataTable()
But one works and the other does not.
Very puzzling.
Without seeing your code it would be hard to say. Can you post a link to your page or a test case showing the issue?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Make sure you have
var table = $('#TableID').DataTable()
notvar table = $('#TableID').dataTable()
. Notice the case of theD
inDataTable()
. Make sure the jQuery selector,$('#TableID')
, is correct. Make sure you haven't reassignedtable
to something else. Make sure thetable.ajax.reload();
statement is executed.Kevin
kthorgren, thanks for taking the time to discuss this.
It is too complicated (and behind a firewall) to share or post a copy.
However, the table is created with
(function($){
$(document).ready(function() {
} );
}(jQuery));
There are five tables constructed very similarly.
They all are reloaded with
tablename.ajax.reload();.
only one needs
$('#TableID').DataTable().ajax.reload();.
That's definitely not expected, but without seeing the issue, it's hard to progress. This example here is using ajax, could you modify that, please, to mimic what your code is doing so that we can see.
Colin