Created
May 12, 2019 03:11
-
-
Save dustingetz/daae1c37d767811e921f402fdeec16a0 to your computer and use it in GitHub Desktop.
react virtualized data grid clojurescript
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
(defn row [ctx k] | |
^{:key (pr-str k)} | |
[:> js/ReactVirtualized.Column | |
{:label (reagent.core/as-element [hyperfiddle.ui/field [k] ctx]) | |
:dataKey (hypercrud.transit/encode k) | |
:cellDataGetter | |
(fn [m] | |
(let [k (hypercrud.transit/decode (aget m "dataKey")) | |
ctx (aget m "rowData") | |
#_#_ctx (hypercrud.browser.context/attribute ctx k)] | |
;(hypercrud.browser.context/data ctx) | |
(reagent.core/as-element | |
[hyperfiddle.ui/field [k] ctx]))) | |
:width 60}]) | |
(defn cell [ctx jm] | |
(let [columnIndex (goog.object/get jm "columnIndex") | |
rowIndex (goog.object/get jm "rowIndex") | |
react-key (goog.object/get jm "key") | |
style (goog.object/get jm "style") | |
cols (hypercrud.browser.context/children ctx) | |
row (get @(:hypercrud.browser/result ctx) rowIndex) | |
row-key (hypercrud.browser.context/row-key ctx row) | |
ctx (hypercrud.browser.context/row ctx row-key) | |
col-key (get (vec cols) columnIndex) | |
#_#_ctx (hypercrud.browser.context/attribute ctx col-key)] | |
(reagent.core/as-element | |
[:div {:key react-key :style style} | |
#_[hyperfiddle.ui/field [col-key] ctx] | |
(pr-str [c r]) | |
]))) | |
(defn rv-grid [ctx props] | |
(let [ctx (assoc ctx | |
;:hypercrud.browser/head-sentinel true | |
:hyperfiddle.ui/layout :hyperfiddle.ui.layout/table) | |
items (hypercrud.browser.context/data ctx)] | |
[:> js/ReactVirtualized.AutoSizer | |
(fn [m] | |
(reagent.core/as-element | |
[:> js/ReactVirtualized.Grid | |
{:cellRenderer (partial cell ctx) | |
:columnCount (count (hypercrud.browser.context/children ctx)) | |
:columnWidth 60 | |
:height 300 | |
:className "inspector hyperfiddle unp" | |
:width (aget m "width") | |
:rowHeight 30 | |
:rowCount (count items)}]))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment