Datatables footer error: Uncaught TypeError: Cannot set property 'nTf' of undefined
datatable, datatables, jquery, php, php-5.4
Solution
In case others are experiencing this issue, I found that this occurs if you do the following:
- Use server-side processing
- Specify a tfoot in your HTML
- Define a columns array in your DataTables Javascript setup that does not include one column definition for every cell in your tfoot
The solution is to make sure the columns definition in your Javascript matches the actual number of cells in your HTML. This issue is still relevant with the new DataTables API.
Problem
I am facing problem related to datatables. I have a large number of records (45,000 +). So I am using datatables with "Server Side " coding. The issue is this, its showing the following error in the below code is: ERROR: Uncaught TypeError: Cannot set property 'nTf' of undefined ``` // allows cells to be used for multiple columns using colspan if ( tfoot !== null ) { var cells = oSettings.aoFooter[0]; for ( i=0, ien=cells.length ; i<ien ; i++ ) { column = columns[i]; column.nTf = cells[i].cell; if ( column.sClass ) { $(column.nTf).addClass( column.sClass ); } ``` JavaScript code I am using for this is: ``` $(document).ready(function() { $('#authorsdatatab').dataTable( { "bPaginate": true, "processing": true, "serverSide": true, "sAjaxSource": "../assets/common/authorsServerSide.php", }); }); ``` The data I am using for showing column in server side scripting is: ``` $aColumns = array( 'a_ID', 'a_name', 'a_birth', 'a_death' ); /* Indexed column (used for fast and accurate table cardinality) */ $sIndexColumn = "a_ID"; /* DB table to use */ $sTable = "authors"; ```