Fork me on GitHub
#clerk
<
2023-05-23
>
chromalchemy23:05:55

Is there a way to show ALL the rows of an auto-expanded table by default? My clerk/table viewer is showing only the first 20 rows (can click to show the rest). There are only about 40 rows total, so I dont think it needs to be limited for perf reasons.. I am using this metadata:

^{:nextjournal.clerk/visibility {:result :show}
  :nextjournal.clerk/auto-expand-results? true
  :nextjournal.clerk/budget 1000}
 (clerk/table items)

👍 4
Andrea10:05:19

this is one of the aspects that we need to make easier or at least document better, this has been asked a lot but (I think) it didn’t make it in the https://book.clerk.vision/#elisions yet. The table viewer injects their own sub-viewers at “runtime” so you need to take this into account if you want to disable pagination. So one way to achieve this is

(ns scratch.pagination
  (:require [nextjournal.clerk :as clerk]
            [nextjournal.clerk.viewer :as viewer]))

(clerk/add-viewers! [(update viewer/table-viewer :transform-fn #(comp %2 %1)
                             (fn [wrapped-value]
                               (update wrapped-value :nextjournal/viewers
                                       clerk/update-viewers {:page-size #(dissoc % :page-size)})))])

(clerk/table (map vector (range 30)))

👍 2
Andrea10:05:33

that disables pagination for all clerk/table calls in the namespace, while if you want to restrict to single values you can do

(def unpaginated-table-viewer
  (update viewer/table-viewer :transform-fn #(comp %2 %1)
          (fn [wrapped-value]
            (update wrapped-value :nextjournal/viewers
                    clerk/update-viewers {:page-size #(dissoc % :page-size)}))))

(clerk/with-viewer unpaginated-table-viewer
  (map vector (range 30)))

👍 6
🙌 2
chromalchemy16:05:50

That works for me!! Thanks, dont think I would have figured that out. plus_one for already great but evolving docs.