[whatwg] Sort child nodes of a DOM node.

Biju bijumaillist at gmail.com
Thu Jun 3 23:49:40 PDT 2010


There are many cases where we want to sort child nodes of a DOM node.
Many times it is TR nodes of a TBODY

Right now user writes javascript code to achive that.
Dont you think it is better if there was built DOM method for each node.
Additionally the method will have a sort function parameter to compare elements
the same way as in JavaScript Array.sort(compare_func)

function compare_func(a,b){
 if(isHeaderRow(a))  return -1;
 if(isHeaderRow(b))  return 1;
 if(a.textContent == b.textContent) return 0;
 if(a.textContent < b.textContent) return -1;
 return 1;
}
tablebody.sortChildNodes(compare_func)

Use cases:-
Example 1: column sorting in yahoo mail

Example 2: you can sort this listing by clicking the column headers
https://bugzilla.mozilla.org/buglist.cgi?short_desc=sort&short_desc_type=allwordssubstr&resolution=---

Example 2: there are bug report in mozilla asking sorting in XUL grids
https://bugzilla.mozilla.org/showdependencytree.cgi?id=482890&hide_resolved=1


More information about the whatwg mailing list