W3C home > Mailing lists > Public > whatwg@whatwg.org > December 2012

Re: [whatwg] Sortable Tables

From: Ian Hickson <ian@hixie.ch>
Date: Fri, 28 Dec 2012 08:21:16 +0000 (UTC)
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Message-ID: <Pine.LNX.4.64.1212280815120.12992@ps20323.dreamhostps.com>
Cc: WHATWG List <whatwg@whatwg.org>
On Thu, 27 Dec 2012, Tab Atkins Jr. wrote:
> On Dec 27, 2012 6:04 PM, "Ian Hickson" <ian@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.   `._.-(,_..'--(,_..'`-.;.'
Received on Friday, 28 December 2012 08:21:40 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:50 UTC