Possible reasons for TypeError: Cannot read properties of undefined (reading 'nTable')
Possible reasons for TypeError: Cannot read properties of undefined (reading 'nTable')
I am using datatables 2.0.8 and editor 2.3.2. It is an upgrade from a dataTables environment that has been working well for years.
Because I couldn't make it work, I reverted to a very basic table, to see if I can make it work and still not.
1. If I run only dataTables, everything works the way it is supposed to be.
2. As soon as I introduce the Editor component, I get the error, which is, as mentioned in the title: Cannot read properties of undefined (reading 'nTable')
3. The code is reduced to its minimum expression, so I am running out of ideas to find the error.
4. The comms to the database are OK, because datatables draws all the data, it is only in Editor where the problem comes
5. If I just comment out the line table: '#example' there is no error, but then, of course, there is no editor, because it does not know what table to reference to.
6. devTools takes me to this line, as the location of the failure if (settings.nTable === dtApi.table().node())
Any ideas on where to look at?
This is the html:
<div class="container">
<div class="demo-html">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Object ID</th>
<th>User ID</th>
<th>Specie</th>
<th>State FIP</th>
<th>County FIP</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Object ID</th>
<th>User ID</th>
<th>Specie</th>
<th>State FIP</th>
<th>County FIP</th>
</tr>
</tfoot>
</table>
</div>
</div>
This is the javascript:
$(document).ready(function() {
var editor = new DataTable.Editor({
ajax: '/xyz/controllers/test.php',
table: '#example',
fields: [
{ name: 'OBJECTID' },
{ name: 'USERID' },
{ name: 'SPECIES' },
{ name: 'STATEFIPS' },
{ name: 'COUNTYFIPS' }
]
});
$('#example').DataTable({
ajax: '/xyz/controllers/test.php',
columns: [
{ data: 'OBJECTID' },
{ data: 'USERID' },
{ data: 'SPECIES' },
{ data: 'STATEFIPS' },
{ data: 'COUNTYFIPS' }
],
select: true
});
});
This question has accepted answers - jump to:
Answers
There is nothing obvious in your code. This example with the latest Datatables and Editor versions works.
Does the error. occur on page load or when you are interacting with the page?
Does the error traceback point to any lines in your Javascript code?
It doesn't look like you are using any buttons. Are you using inline editing?
Can you post a link to your page or test case showing the error so we can help debug?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I kept digging in all kinds of threads in this forum and I found the solution, here:
https://datatables.net/forums/discussion/57394/cannot-read-property-ntable-of-undefined.
Please mark this issue solved. Thanks to rompeplatos (nice username for us Spanish speakers) for posting your solution