fnDestroy issue with JQuery 1.5 and IE7
fnDestroy issue with JQuery 1.5 and IE7
I have recently upgraded to JQuery 1.5.
The following works fine with JQuery 1.4.2.
In JQuery 1.5 I get a javascript null object error in IE7 but it works fine in Firefox and Chrome.
$("#item").dataTable(.......); /// initialise the datatable
$("#item").dataTable().fnDestroy();
// this line works in JQuery 1.4.2 but throws a javascript null object exception in JQuery 1.5
$("#item").dataTable(.......); /// reinitialise the datatable
The following works fine with JQuery 1.4.2.
In JQuery 1.5 I get a javascript null object error in IE7 but it works fine in Firefox and Chrome.
$("#item").dataTable(.......); /// initialise the datatable
$("#item").dataTable().fnDestroy();
// this line works in JQuery 1.4.2 but throws a javascript null object exception in JQuery 1.5
$("#item").dataTable(.......); /// reinitialise the datatable
This discussion has been closed.
Replies
Allan
I'm a dev working with johnc on the same project. This issue is really killing us as it is fine in the older version of jQuery.
To expand on the summary John made above we are initialising datatables on two tables, both with server side data. The first table is initialised on page load and the second is initialised in a modal dialog with the jQuery plugin Colorbox.
When the application is first opened a function is called that initialises datatables on a table with ID of 'quotations' like so:
[code]
function reInitialiseQuoteTable() {
$('#quotations').dataTable({
"fnInitComplete": function() {
// custom scroll bars
$('#icis_dashboard')
.find('.w_price_assess .dataTables_scrollBody')
.jScrollPane();
},
"bAutoWidth": false,
"bPaginate": false,
"sScrollY": "242px",
"bLengthChange": false,
"bInfo": false,
"bFilter": false,
"aaSorting": [[2, 'asc']],
"aoColumns": [
{ "sSortDataType": "dom-checkbox", "sWidth": "3%" },
{ "bSortable": true, "sWidth": "8%" },
{ "bSortable": true, "sWidth": "10%" },
{ "bSortable": true, "sWidth": "15%" },
{ "bSortable": true, "sWidth": "8%" },
{ "bSortable": true, "sWidth": "9%" },
{ "bSortable": true, "sWidth": "6%" },
{ "bSortable": false, "sWidth": "2%" },
{ "bSortable": false, "sWidth": "7%" },
{ "bSortable": false, "sWidth": "13%" },
{ "bSortable": false, "sWidth": "2%" },
{ "bSortable": false, "sWidth": "7%" },
{ "bSortable": false, "sWidth": "10%" }
]
});
}
[/code]
Then when a user initiates the dialog, the dialog opens the previious quotations table is destroyed and then datatables is initialised on the new table with ID 'quote_prefs':
[code]
// Quote preferences dialog
function initialiseQuoteFavouritesSelectionTable() {
$("#quote_prefs").dataTable({
//"bRetrieve": true,
//"bDestroy": true,
"aaSorting": [[1, 'asc']], //disable default sorting order
"bLengthChange": false, //remove drop-down for length change
"bPaginate": true, //pagination
"sPaginationType": "full_numbers",
"bProcessing": false, //disables processing indicator
"iDisplayLength": 15, //set display length
"bSortClasses": true, //turn off sorting classes
"bAutoWidth": false, //smart column width calculation
"bFilter": true, //turn off filtering
"sDom": 'l<"wrap"t>ip', //re-order datatable elements: length, wrap div > table, information, pagination
"aoColumnDefs": [
{ "sName": "Selected", "aTargets": [0], "sWidth": "4%", "bSortable": false },
{ "sName": "Commodity", "aTargets": [1], "sWidth": "18%" },
{ "sName": "GradeDisplay", "aTargets": [2], "sWidth": "20%", "bSortable": false },
{ "sName": "TermName", "aTargets": [3], "sWidth": "10%" },
{ "sName": "LocationName", "aTargets": [4], "sWidth": "12%" },
{ "sName": "UnitDisplay", "aTargets": [5], "sWidth": "8%" },
{ "sName": "Properties", "aTargets": [6], "sWidth": "10%", "bSortable": false },
{ "sName": "StartDate", "aTargets": [7], "sWidth": "7.5%" },
{ "sName": "LatestDate", "aTargets": [8], "sWidth": "7.5%" },
{ "sName": "Notes", "aTargets": [9], "sWidth": "3%", "bSortable": false }
],
"sAjaxSource": DashboardApplicationRoot + "Quote/FavouriteQuoteSelection",
"bServerSide": true,
"fnServerData": function(sSource, aoData, fnCallback) {
addDataForServerSideProcessing(aoData);
getPaginatedQuotes(sSource, aoData, fnCallback);
}
});
}
[/code]
[code]
$.ajax({// retrieve data prior to lightbox
type: 'GET',
url: $href,
dataType: 'html',
cache: false,
beforeSend: function() {
showLoadingGraphic();
},
success: function(data) {
$("#dashboard_dialog").prepend(data);
$("#preferences_form").hide();
modalDialog({//disable close on escape/overlay on first login
title: 'Quotation preferences',
width: '860px',
height: '553px',
inline: true,
href: '#preferences_form',
overlayClose: false,
escKey: false,
onLoadCall: function() {
// destroy the 'quotations' datatable as interferes with new one
$('#quotations').dataTable().fnDestroy();
$("#cboxClose").hide(); //hide close button for first login
$("#preferences_form").show();
// initialise datatables on 'quote_prefs' table
initialiseQuoteFavouritesSelectionTable();
},
onClosedCall: function() {//remove form from DOM
$("#preferences_form").empty().remove();
}
});
},
error: function(xhr) {//error handling
});
[/code]
So as we have destroyed the previous table when the dialog is closed it returns a JS error in IE7 and IE6 saying that it cannot find the 'quotations' tabel to initialise it.
Thanks for your time for looking at this, it is greatly appreciated.
Ryan
If that isn't the answer, can you post a link please (or send it to be directly if you don't want to make it public: http://datatables.net/contact ).
Allan
We are working locally so will be unabel to provide a direct link as we cannot deploy to our externally accessible site with this defect.
I hope to get a demo version in JSFiddle runnign today where i shall try and replicate the defect.
Speaking to johnc this morning he may have mroe information to post in a mo.
Thanks,
Ryan
When we reinitialise the table it sees the expando and therefore tries to find the corresponding entry in the JQuery cache, which does not exist, hence throw a null object error.
Not too sure whether it is a JScrollPane issue or JQuery. However someone has encountered a similar problem and has recommended a fix see http://bugs.jquery.com/ticket/8235.
SCRIPT5007: Unable to get value of the property 'jQuery15108300618450999001': object is null or undefined
at jquery.min.js, line 16 character 18471
I'm using jQuery 1.5.1.
For the moment I'm getting round this by just disabling the functionality which relies on fnDestroy() for IE8 and below users (it's OK in IE9).
[Maybe there's a better way of doing what I want to do without having to use fnDestroy()? I'm offering users a button which allows them to switch between using paging and vertical scrolling. I'm doing this by destroying the datatable and then reinitialising a new one.]
Campbell
Allan
JQuery 1.4.4 is OK, so I'm back to this for now.
Regards,
Dave
Allan