[whatwg] Sortable Tables

Ian Hickson ian at hixie.ch
Fri Dec 28 00:21:16 PST 2012


On Thu, 27 Dec 2012, Tab Atkins Jr. wrote:
> On Dec 27, 2012 6:04 PM, "Ian Hickson" <ian at hixie.ch> wrote:
> > > 2. What values should the sort property allow. One idea is that it 
> > > takes a JS function similar to what JavaScript's sort function 
> > > takes. If you leave it out then it just does alphanumeric sort.
> >
> > I was going to have a comparator function, but I couldn't see a sane 
> > way to make it work in the face of hostile functions that mutate the 
> > DOM, so I dropped it. You can do custom sort orders by giving a key in 
> > the <data> element's value="" attribute, though.
> 
> In JS, the comparator passed to sort() can potentially mutate the array 
> that's being sorted, or delete it entirely. JS engines cope somehow. 
> It's silly to not support a custom comparator here, since any problems 
> you can possibly come up with are already present in the existing 
> Array#sort function.

If you can work out how to spec it, I'm all for it. I couldn't figure out 
how to do it in a way that didn't have a very high chance of being 
misimplemented and probably becoming an attack vector.

I don't think an array is as dodgy as DOM manipulation, by the way. For 
example, arrays don't have origins, you can't change their prototype by 
appending the entries to another document, you can't navigate away from an 
array, you can't make one entry in the array be a child of another entry 
in the array, when sorting an array you only have one list of entries to 
sort, not one per column, and you use the same comparator for all entries, 
you don't mix it with a non-JS comparator. And that's just the problems I 
could think of off the top of my head; I'm not at all convinced I even 
understand the problem well enough to enumerate all the issues.

Note that using the 'sort' event you can manually implement the sorting if 
you want to; it'll fire whenever the browser would otherwise sort. So the 
capability is there, just not in the convenient comparator function form. 
(Canceling the sort event overrides the UA's normal sorting behaviour.)

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



More information about the whatwg mailing list