3 ms·
It seems like you're simultaneously saying "sorting doesn't belong as a language function in JavaScript" and "we shouldn't ship a sorting routine to the client,
by chipotle_coyote 6y ago
It seems like you're simultaneously saying "sorting doesn't belong as a language function in JavaScript" and "we shouldn't ship a sorting routine to the client," which seems...odd. If the page view needs sorting, then isn't that the use case where we can most say that there is, in fact, a point to "shipping sort magic to the client"?
(Also, you can do an HTML table sort in about 10 pretty short lines of code[1], so this seems like a kind of weird hill to die on.)
[1]: https://stackoverflow.com/questions/14267781/sorting-html-table-with-javascript#14268260 https://stackoverflow.com/questions/14267781/sorting-html-ta...
- 6510 6y agoJS should have an array sort function. HTML should have sort-able tables. We know what they look like. We shouldn't have to pump up our pages with a bazillion lines of js just to implement something entirely obvious. IOW: If there is a table it doesn't hurt to be able to sort it by default. The example is great! 10 lines... no wait... 30 lines... then you have something that... or no wait, it sorts numbers alphabetically. The cursor is wrong. There is no accessibility. The little arrows are missing ▲ ▼ did I pick the right ones? They look bulky, better add another span inside the th? Oh I clicked the th twice now the text is highlighted. Why should I need to implement this myself? I'm not inventing anything new? I don't want to be dealing with colspan but we all know how it should work? I know its wrong but I usually leave out the <thead>, tables render just fine without it but when something generates tables like that the script needs to be re-examined to figure out why it doesn't work. There is some unknown number of other ways to break it. A default implementation could deal with some common units out of the box. Monday could go in front of Tuesday, 50 cm could be smaller than 1 m, $100 could be bigger than $20. Just the simple obvious stuff. For everything else something like <th sort="foo"> with: foo = (a,b) => a.length - b.length List items are a bit less obvious but I'm sure we can think of something sensible. Perhaps sorting by child class? What is the drawback?