Re: [whatwg] Sort child nodes of a DOM node.

2010-08-04 Thread Ian Hickson
On Fri, 4 Jun 2010, Biju wrote:

 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=sortshort_desc_type=allwordssubstrresolution=---
 
 Example 2: there are bug report in mozilla asking sorting in XUL grids
 https://bugzilla.mozilla.org/showdependencytree.cgi?id=482890hide_resolved=1

This would indeed be useful. It seems like something that should be in DOM 
Core, though, rather than HTML. Do we have anyone editing Web DOM Core 
these days?

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: [whatwg] Sort child nodes of a DOM node.

2010-08-04 Thread Jon Barnett
On Fri, Jun 4, 2010 at 1:49 AM, Biju bijumaill...@gmail.com wrote:

 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=sortshort_desc_type=allwordssubstrresolution=---

 Example 2: there are bug report in mozilla asking sorting in XUL grids

 https://bugzilla.mozilla.org/showdependencytree.cgi?id=482890hide_resolved=1


This sounds more akin to the thread with the subject line Adding ECMAScript
5 array extras to HTMLCollection
It's already easy enough to do once you've copied the nodes into an array:

var rowsArray = convertNodeListIntoJSArray(tBody.rows); // assuming you've
written such a function
rowsArray.sort(compare_func);
tBody.innerHTML = ;
rowsArray.forEach(function(row) { tBody.appendChild(row) });

I'd rather just see some kind of resolution to mixing in Array methods into
the HTMLCollection object.  Since HTMLCollection objects are often 'live' it
would just be:

tBody.rows.sort(compare_func);

I have no opinion on how Array methods should be mixed into HTMLCollection
objects, since the difficulty seems to be more in implementation than
devising a web authors' wishlist, but that's what I'd rather see.

-- 
Jon Barnett


[whatwg] Sort child nodes of a DOM node.

2010-06-04 Thread Biju
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=sortshort_desc_type=allwordssubstrresolution=---

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