Generally it's easier to sort the data before it gets put into hiccup table
formatting. Is there any reason not to?

On Feb 24, 2017 5:41 PM, "John Gabriele" <jmg3...@gmail.com> wrote:

> I'm using hiccup, and I'd like to build a table, but then have the option
> to re-order it (sort its rows by a column of my choosing). I want a
> `sort-table-by` function.
>
> That is, if I've got
>
>
> Color   Size
> ------  ----
> red     2
> green   7
> blue    4
>
>
> (or, as a data structure: `(def tbl [:table [:tr [:th "Color"] [:th
> "Size"]] [:tr [:td "red"] [:td 2]] [:tr [:td "green"] [:td 7]] [:tr [:td
> "blue"] [:td 4]]])`)
>
> I'd like to be able to do `(sort-table-by tbl 0)` and get
>
>
> Color   Size
> ------  ----
> blue    4
> green   7
> red     2
>
>
> or `(sort-table-by tbl 1)` and get
>
>
> Color   Size
> ------  ----
> red     2
> blue    4
> green   7
>
>
> Where it gets tricky though is when your table has various attribute maps
> in it, and also when some of the values you're sorting on may be links.
>
> A first try at a solution yields ... oh man, {sigh, deep breath} this,
> which doesn't work:
> <https://gist.github.com/uvtc/ca819f08fe7ead81e13055f001a994e3>.
>
> Thanks!
> -- John
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to