FixedColumns - Cannot read property 'className' of undefined
FixedColumns - Cannot read property 'className' of undefined
Hi guys,
Datatables is amazing, and has been doing everything I've thought of so far. However, I'm having an issue when I use FixedColumns.
When I use fnDestroy and then reinitialize the table on a button click, sorting breaks on the column that I've fixed. Here's what I have:
$(document).ready(function() {
oTable = $('.datatable').dataTable(
{
"bDestroy": true,
"bAutoWidth": false,
"sScrollX": "100%"
});
new FixedColumns(oTable);
oTable.fnDestroy();
//To test re-init- this is the same code as above.
oTable = $('.datatable').dataTable(
{
"bDestroy": true,
"bAutoWidth": false,
"sScrollX": "100%"
});
new FixedColumns(oTable);
});
After clicking on the fixed column to sort, the traceback I get is as follows:
Uncaught TyperError: Cannot read property 'className' of undefined
_fnSortingClasses
_fnSort
$.fn.dataTable.$.bind.fnInnerSorting
$.fn.dataTable.iColumns
jQuery.event.handle
jQuery.event.add.elemData.handle.eventHandle
Any help is appreciated!
Thanks,
Ted
Datatables is amazing, and has been doing everything I've thought of so far. However, I'm having an issue when I use FixedColumns.
When I use fnDestroy and then reinitialize the table on a button click, sorting breaks on the column that I've fixed. Here's what I have:
$(document).ready(function() {
oTable = $('.datatable').dataTable(
{
"bDestroy": true,
"bAutoWidth": false,
"sScrollX": "100%"
});
new FixedColumns(oTable);
oTable.fnDestroy();
//To test re-init- this is the same code as above.
oTable = $('.datatable').dataTable(
{
"bDestroy": true,
"bAutoWidth": false,
"sScrollX": "100%"
});
new FixedColumns(oTable);
});
After clicking on the fixed column to sort, the traceback I get is as follows:
Uncaught TyperError: Cannot read property 'className' of undefined
_fnSortingClasses
_fnSort
$.fn.dataTable.$.bind.fnInnerSorting
$.fn.dataTable.iColumns
jQuery.event.handle
jQuery.event.add.elemData.handle.eventHandle
Any help is appreciated!
Thanks,
Ted
This discussion has been closed.
Replies
Thanks for the detailed bug report! You are absolutely correct - there is a bug in DataTables which your code is triggering. Basically what is happening is that the sort handler from the first $().dataTable() call isn't being removed on hidden columns (which is a feature used by FixedColumns). You can see this visually by removing your second DataTables initialisation and running Visual Event ( http://sprymedia.co.uk/article/Visual+Event ) - the first column will have an event handler on it, while none of the others do. This also creates a memory leak...
I've just committed a fix (which is simply to change the order of the code in fnDestroy to take account of this!) which you can pick up from the downloads page as the DataTables nightly. I'll be releasing 1.8.1 reasonably soon with this fix as well.
Regards,
Allan
Thanks so much for the fix. I was tearing my hair out over this!
Thanks,
Ted