CutCodeDown

Web Development => Snippet Sharing => Topic started by: Jason Knight on 10 Dec 2020, 08:03:53 am

Title: JavaScript: Easy Table Sorting
Post by: Jason Knight on 10 Dec 2020, 08:03:53 am
Wrote a medium article on the topic refining someone else's example in preparation for expanding it further:
https://deathshadow.medium.com/javascript-table-sorting-part-1-of-2-start-out-simple-1df3e0be8d4e

As always, example directory for those of you who hit up against the read limit:
https://cutcodedown.com/for_others/medium_articles/tableSort/simple/

With a .rar of the whole deal in there.

The script itself isn't too complex, at 1.83k it basically is a snippet.

The whole intent being that if you have a well-formed semantic table with TH, THEAD, TBODY, and so forth, a few simple data- attributes is all we need as hooks for JS to perform our sorts, and a bit of CSS to add the visual sort state. About as "plug and play" as you can get with vanilla scripting.

Which is what I liked about the original guy's article here:
https://medium.com/javascript-in-plain-english/easy-table-sorting-with-javascript-370d8d97cad8
Title: Re: JavaScript: Easy Table Sorting
Post by: Jason Knight on 11 Dec 2020, 06:48:16 am
Part 2 is up:
https://deathshadow.medium.com/javascript-table-sorting-part-2-of-2-enhancement-18fe607842b6

For the meat of it:
https://cutcodedown.com/for_others/medium_articles/tableSort/robust/

And I even made a pen as I know some folks prefer that. (not a fan personally)
https://codepen.io/jason-knight/pen/jOMVzMw