PivotTableUI in clojurescript from react-pivottable on change interface not render new status

247 views Asked by At

The component is loaded correctly with the initial data, but the data does not change when the state is changed from the interface, what can I be doing wrong?

not change the table

(ns ui.pivottable.react-pivottable
   (:require ["react-pivottable/PivotTableUI" :default PivotTableUI]
             ["react-pivottable/TableRenderers" :as TableRenderers]
             ["react-plotly.js" :default Plot]
             ["react-pivottable/PlotlyRenderers" :as create-plotly-renderers]
             [reagent.core :as r]))


(defn pivottable []
  (let [state (r/atom  {:data (clj->js [[:name "Alice" :age 30 :city "New York"]
                                         [:name "Bob" :age 35 :city "Chicago"]
                                         [:name "Charlie" :age 40 :city "New York"]])
                         :aggregator-name "Count"
                         :renderer-name "Table"
                         :rows [:name]
                         :cols [:age]})
       component (r/adapt-react-class PivotTableUI)
       plotly-renderers (create-plotly-renderers Plot)
       table-renderers TableRenderers
       params {:rows [:name]
               :cols [:age]
               :on-change #(do (reset! state  (.assign js/Object #js {} %))
                               ;; (reset! state (clj->js %) another try, it's the same)
                            (.log js/console @state))
               :renderers  (.assign js/Object #js {}  plotly-renderers table-renderers)}]

    [component (merge @state params)]))
1

There are 1 answers

1
Jose Sánchez On

Diego. You are using let instead of r/with-let. Therefore, when you change the state of the atom the component is rendered and the atom is initialised with the data again.