I have a problem where I am trying to access a data table object of a particular HTML element.
I have looked at the docs for JQuery Data Table and am using this example: https://datatables.net/reference/option/retrieve
This however, does not work. Here is my code in my global file main.js:
function initTable () {
return $(".dynamic-table").DataTable({
"aaSorting": [],
"scrollY": 530,
"scrollCollapse": true,
"lengthMenu": [
[100, 400, 1000, 5000, -1],
[100, 400, 1000, 5000, "All"]
],
"retrieve": true
});
}
$(document).ready(function() {
initTable();
});
Now inside of my other file I attempt to retrieve the object:
$(document).ready(function() {
var table = initTable();
});
This does not retrieve the object but instead it initializes the object again and causes the table to render twice.
I have also tried:
$(document).ready(function() {
var table = $(".dynamic-wide-table").DataTable();
});
because I have read some threads saying that a blank initialization will just retrieve the object.
Neither of these solutions work. If anybody knows what I am doing wrong I would greatly appreciate it! Thanks.

DataTable. What is the difference?dataTablenotDataTableordatatable. Look at the example, it is case sensitive.