Search code examples
ag-gridclojurescriptreagent

Ag-grid clojurescript sortable key doesn't work


I am trying to make a grid with ag-grid and activate sortable and filter, but it doesn't work towards localhost. In the columndefinition, I use ''':sortable true''' ''':filter true''''

But nothing happens. Does anyone know what is wrong? enter image description here

(ns reagent-ag-grid-ex.core
    (:require
     [reagent.core :as r]
     [cljsjs.ag-grid-react]
     [reagent-ag-grid-ex.state :as state]))

;; -------------------------
;; Views

(def ag-adapter (r/adapt-react-class (.-AgGridReact js/agGridReact) ))


;;(defn get-cols [entry]
;;  (into [] (map #(hash-map :headerName (-> % key name) :field (-> % key name)) entry)))
;;columnDefs: [ {headerName: "Make", field: "make"}, {headerName: "Model", field: "model"}, {headerName: "Price", field: "price"} ]
;;rowData: [ {make: "Toyota", model: "Celica", price: 35000}, {make: "Ford", model: "Mondeo", price: 32000}, {make: "Porsche", model: "Boxter", price: 72000}]

(def deafult-col-w 200)

(defn width-helper [lst]
  (+ (* deafult-col-w (count lst)) 2))

(defn home-page []
  [:div [:h2 "Ekspono tag-model"]
   [:p "My portfolio / Top Index " [:a {:style {:background-color "#C0C0C0" :float "right" :color "black"} 
                                        :href "https://www.google.com" :target "_blank"} "Show problems"]]
   [:div {:className "ag-theme-balham" :style {:height 200 :width (width-helper state/cols) :color "purple"}}
    [ag-adapter {"columnDefs"  state/cols 
                 "rowData" state/rows
                 "defaultColDef" {:sortable true
                                  :width deafult-col-w}}]]

   [:div [:a {:href "https://www.tabyenskilda.se/fredrik-cumlin/" :target "_blank"} 
          "@copyright Fredrik Cumlin"]]])

;; -------------------------
;; Initialize app

(defn mount-root []
  (r/render [home-page] (.getElementById js/document "app")))

(defn init! []
  (mount-root))


Solution

  • Upgrade to latest ag-grid-react cljsjs distribution (21.0.1-1) - e.g. using lein project.clj switch dep to [cljsjs/ag-grid-react "21.0.1-1"]. Should work on this version.

    Also as a side note, no need to specify prop keys with strings, you can use keywords - it's a bit more idiomatic.