Created
August 21, 2015 09:44
-
-
Save maxweber/84c90855a6fb8e0ff6ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns sortable-table.core | |
(:require [reagent.core :as reagent :refer [atom]])) | |
(def data | |
(atom | |
{:header ["Id" "Name" "City"] | |
:rows [["1" "Joe" "New York"] | |
["2" "Harry" "Boston"] | |
["3" "Alicia" "Miami"]]})) | |
(defn table [data] | |
[:table | |
[:tr | |
(map-indexed | |
(fn [idx column] | |
[:th | |
{:onClick | |
(fn [e] | |
(swap! data update-in [:rows] | |
(fn [rows] | |
(sort-by | |
#(get % idx) | |
rows))))} | |
column]) | |
(:header @data))] | |
(map | |
(fn [row] | |
[:tr | |
(map | |
(fn [column] | |
[:td column]) | |
row)]) | |
(:rows @data))]) | |
(defn current-page [] | |
[:div [table data]]) | |
;; ------------------------- | |
;; Initialize app | |
(defn mount-root [] | |
(reagent/render [current-page] (.getElementById js/document "app"))) | |
(defn init! [] | |
(mount-root)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment