This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-12
Channels
- # announcements (7)
- # babashka (13)
- # beginners (14)
- # business (7)
- # clerk (4)
- # clj-kondo (21)
- # clojure (42)
- # clojure-denmark (5)
- # clojure-dev (16)
- # clojure-europe (27)
- # clojure-finland (1)
- # clojure-nl (1)
- # clojure-norway (36)
- # clojure-sweden (2)
- # clojure-uk (34)
- # clojurescript (29)
- # datomic (15)
- # emacs (1)
- # hyperfiddle (13)
- # jobs (11)
- # joyride (8)
- # malli (15)
- # missionary (10)
- # off-topic (5)
- # portal (6)
- # releases (3)
- # shadow-cljs (9)
- # spacemacs (28)
- # specter (2)
- # squint (12)
I noticed that a static build "cuts" of my tables, and instead of being able to press to "load more data", I see "xxx elided". Can I somehow change this ? So my long tables are rendered initially "short", but a reader of the static can expands, if he wants.
you might solve that issue by handling pagination entirely on the client side, via a custom viewer, roughly along these lines:
(ns scratch.debug
{:nextjournal.clerk/visibility {:code :hide}}
(:require [nextjournal.clerk :as clerk]
[nextjournal.clerk.viewer :as viewer]))
(def table-viewer-with-client-pagination
(update viewer/table-viewer
:add-viewers viewer/add-viewers
[(assoc viewer/table-body-viewer
:render-fn '(fn [xs opts]
(let [!visible-rows (nextjournal.clerk.render.hooks/use-state 10)]
[:tbody
(into [:<>]
(nextjournal.clerk.render/inspect-children opts)
(take @!visible-rows xs))
[:tr.border-t.dark:border-slate-700
[:td.py-1.relative.bg-indigo-50.hover:bg-indigo-100.cursor-pointer
{:col-span (:num-cols opts) :on-click (fn [_] (swap! !visible-rows + 10))}
[:span.sticky.px-2 "more..."]]]])))]))
(clerk/with-viewer
table-viewer-with-client-pagination
{::clerk/page-size nil}
(clerk/use-headers (mapv (constantly (vec (range 10)))
(range 80))))
I think that would work until we find a more principled way to do thatOr, to apply the above approach to all clerk/table
invokations:
(ns scratch.debug
{:nextjournal.clerk/visibility {:code :hide}}
(:require [nextjournal.clerk :as clerk]
[nextjournal.clerk.viewer :as viewer]))
(def table-viewer-with-client-pagination
(update (dissoc viewer/table-viewer :page-size)
:add-viewers viewer/add-viewers
[(assoc viewer/table-body-viewer
:render-fn '(fn [xs opts]
(let [!visible-rows (nextjournal.clerk.render.hooks/use-state 10)]
[:tbody
(into [:<>]
(nextjournal.clerk.render/inspect-children opts)
(take @!visible-rows xs))
[:tr.border-t.dark:border-slate-700
[:td.py-1.relative.bg-indigo-50.hover:bg-indigo-100.cursor-pointer
{:col-span (:num-cols opts) :on-click (fn [_] (swap! !visible-rows + 10))}
[:span.sticky.px-2 "more..."]]]])))]))
(clerk/add-viewers! [table-viewer-with-client-pagination])
(clerk/table
(clerk/use-headers (mapv (constantly (vec (range 10)))
(range 100))))
Thanks, will try it out ASAP.