Let SortTable and asp.net Ajax get along

Source: Internet
Author: User

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','');
}
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.