fnClearTable() its trhowing: Unable to get property 'length' of undefined or null reference
fnClearTable() its trhowing: Unable to get property 'length' of undefined or null reference
I have created a custom table to a CRM Dynamics environment.
It is being populated using an object (I'm creating the object using a fetch query to the CRM).
The table is being populated correctly the first time but Im trying to add a reload button using:
var table = $('#results').dataTable();
resultsObj = datatest(); /* creates the object. It is the same method that its being called the first time the table is created.*/
table.fnClearTable();
table.fnAddData(resultsObj);
But the table.fnClearTable is throwing:
Unable to get property 'length' of undefined or null reference
File: jquery.js, Line: 2, Column: 2817
Im using jquery 1.11.3 and jquery DataTables 1.10.7
Any idea of what can be happening?
This question has accepted answers - jump to:
Answers
On a quick glance I see that you are using .dataTable() and not .DataTable(); One is used to get a jquery object and the other a datatables instance. You might try just capitalizing it and see if that changes the error for you?
Also you are using functions found in the legacy version of datatables not sure if there is backwards compatibility support for all functions or not.
I tried with DataTable but same result.
It is the first time I use datatables :o I didnt knew that the functions im using were from the legacy version! :o!
Can you link to the page showing the issue please? That will set us debug the issue.
Your code looks fine (although as mrd05d points out it is legacy API calls you are using -
clear()
is the 1.10+ preferred style).Allan
It is inside an iframe in a CRM Dynamics environment, it is not public. I dont know if there is a way I can show it.
var table = $('#example').dataTable();
table.clear();
didnt work BUT when I tried with
function reloadData() {
var table = $('#example').DataTable();
datatest();
table.clear();
//table.fnClearTable();
//table.fnAddData(resultsObj);
}
It doesnt clear completly the table but I dont receive any error in the console.
I receive:
[object Object]{ajax: Object {...}, context: Array[1], length: 0, selector: Object {...}}
so It is actually recognizing the command.
I can see the table there BUT the dataset is empty. My table have details row as in
https://datatables.net/examples/server_side/row_details.html
and after I use table.clear() I cannot see the details because I dont have the data anymore... I realize this is weird to understand without a screenshoot but I dont see the option to add one here.
Well I used:
var table = $('#example').DataTable();
datatest(); /* this fills the global object resultsObj*/
table.clear();
table.rows.add(resultsObj.data).draw();
and it is working now! Thanks, I expect to learn a lot of datatables from now on.