Sorting causes IE to throw "A script on this page is causing internet explorer to run slowly"

Sorting causes IE to throw "A script on this page is causing internet explorer to run slowly"

LeadVisionaryLeadVisionary Posts: 8Questions: 0Answers: 0
edited November 2010 in Bug reports
I recently updated jQuery to the latest (from the Google CDN) from version 1.3.2 on an application using DataTables 1.4.9. The application seems to work fine, but on a page with 335 records and a custom sort function it issues a warning in IE, seen in this question:
http://stackoverflow.com/questions/212550/a-script-on-this-page-is-causin

It looks like over 5 million javascript commands are running. Here are the sort functions:

/* Define two custom functions (asc and desc) for columns for content*/
function spanNumericCompare(x, y) {
var x = parseInt($(a).text());
var y = parseInt($(b).text());
return x - y;
}

function spanStringCompare(x, y) {
var x = parseInt($(a).text());
var y = parseInt($(b).text());
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
jQuery.fn.dataTableExt.oSort['span-asc'] = function (a, b) {
return spanNumericCompare(a, b);
};
jQuery.fn.dataTableExt.oSort['span-desc'] = function (a, b) {
return -1 * spanNumericCompare(a, b);
};
jQuery.fn.dataTableExt.oSort['spanString-asc'] = function (a, b) {
return spanStringCompare(a, b);
};
jQuery.fn.dataTableExt.oSort['spanString-desc'] = function (a, b) {
return -1 * spanStringCompare(a, b);
};

The compare functions are trying to extract information from a [number or string] element and sort that way.

I tried upgrading to the latest DataTables (1.7.2), but it appears to still be doing it. What are common ways of troubling-shooting these types of sorting issues with DataTables?

Replies

  • LeadVisionaryLeadVisionary Posts: 8Questions: 0Answers: 0
    It apparently has nothing to do with the sort functions. I just took those out and it's still throwing that warning. Was there a breaking change to sorting from jQuery 1.3.2 to jQuery 1.4?
  • _andreas__andreas_ Posts: 4Questions: 0Answers: 0
    Hi,

    I'm stuck with the same problem. I have a datatable with about ~600 rows / 3 cols. FF sorts just fine, but IE throws the error message which you have posted above.

    If you force the second sort mehtod by doing something like this "if ( false && !window.runtime )" in _fnSort it works for me.

    Sorting is still slow, but its better without having the error message ;-)

    Good night
    Andreas
  • jlermanjlerman Posts: 2Questions: 0Answers: 0
    edited November 2010
    From what I've read (i.e. there may be more to it than I've found so far) the message is IE's way of "protecting" the end-user and it's doing it based on the # of lines of script being executed. There are a few lines of script in the datatables api (a few million I think :) ) . The more rows I have in my table, the more freuqently I see the message when a function (e.g. sorting) is processing.

    I'm new to datatables and using the latest version (1.7.4) so I don't have any experience with sorting in IE8 without seeing the messages. But based on the other posts in the thread this seems to be new behavior.

    Either way, this is definitely a big problem.

    FWIW, I've seen this workaround but not tried it (http://www.picnet.com.au/blogs/Guido/post/2010/03/04/How-to-prevent-Stop-running-this-script-message-in-browsers.aspx) .
  • jlermanjlerman Posts: 2Questions: 0Answers: 0
    edited November 2010
    p.s., _andreas suggestion works great. I made the mod in the jquery.dataTables.js file, in the _fnSort function at what I'm seeing as line 4303. There's a comment that says "DataTables offers two different methods for doing the 2D array sorting..." followed by an if block.

    changed from [code]if (!window.runtime)[/code]
    to [code] if (false && !window.runtime)[/code]
This discussion has been closed.