I believe many people may have used sorttable This table element to sort the JS class library.
SortTable only need to set the class of the table to achieve a simple application.
But if you are quoting the sorttable and using the ASP.net Ajax. Oh, this is absolutely lively. Like an enemy.
Error Tip:
Sys.ArgumentTypeException:Object of type ' Object ' cannot be converted to type ' Array '
After several hours of effort, through the firefox+firebug to help, finally found the crux. There is a collision between the foreach implementation inside sorttable and the asp.net ajax foreach implementation.
Of course, it's not easy to disable the foreach in Ajax.NET Ajax. Can only let the sorttable inside of the failure of the foreach. By analyzing the foreach inside the sorttable, the foreach implementation in the sorttable is discarded and the implementation code is removed, then the foreach is changed to a for implementation. Finally...... Get along with each other.
Of course there is a better way to change the method, that is, to rename the methods of the foreach, but found that the sorttable reference foreach is a little bit, so use for.
There are two places to change:
First place:
//原始代码
// Array.forEach(document.getElementsByTagName('table'), function(table) {
// if (table.className.search(/\bsortable\b/) != -1) {
// sorttable.makeSortable(table);
// }
// });
// alert(document.getElementsByTagName('table').length);
// //修改代码
for(i=0; i
{
// alert(document.getElementsByTagName('table').length);
table=document.getElementsByTagName('table')[i];
if (table.className.search(/\bsortable\b/) != -1)
{
sorttable.makeSortable(table);
}
};
Second place:
//原始代码
//forEach(theadrow.childNodes, function(cell) {
// if (cell.nodeType == 1) {
// cell.className = cell.className.replace('sorttable_sorted_reverse','');
// cell.className = cell.className.replace('sorttable_sorted','');
// }
// });
//修改代码
for(i=0; i
{
var cell=theadrow.childNodes[i];
if (cell.nodeType == 1) { // an element
cell.className = cell.className.replace('sorttable_sorted_reverse','');
cell.className = cell.className.replace('sorttable_sorted','');
}
};