Menu ▾ ▴

#27 Fix for slow sorting of large tables

open
nobody
5
2010-01-14
2010-01-14
Ravi Menon
No

Hi,
Thanks for providing this amazing script.

I made a change to the script to make sorting large tables faster. This change works for IE:
1. Create a hidden <SPAN> element :
var hiddenSpan,
In the init() function:
hiddenSpan=createElement("SPAN");
hiddenSpan.style.visibility="hidden";

2. In the moveRows(table, newRows) function,
{
//Changed to make the moving quicker.
isOdd = false;
var sz="";
for (var j = 0; j < table.tBodies[0].rows.length; j++)
{
doStripe(newRows[i]);
sz = sz + newRows[j].outerHTML;
}
hiddenSpan.innerHTML = '<table><tbody>' + sz;
table.replaceChild(hiddenSpan.firstChild.firstChild, table.tBodies[0]);

}
This uses the hiddenSpan to replace the rows in the tbody object.
In IE, you can't directly use the innerHTML property.
I got this idea from this site http://www.ericvasilik.com/2006/07/code-karma.html and thought I might share it with the community.

Thanks,
Ravi.

Discussion


Log in to post a comment.