Skip to content

Commit 8091abc

Browse files
committed
Support empty tables
1 parent 2ae7c02 commit 8091abc

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/nextjournal/clerk_table_stats.cljc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@
438438
(and (map? data) (sequential? (first (vals data)))) (normalize-map-of-seq opts data)
439439
(and (sequential? data) (map? (first data))) (normalize-seq-of-map opts data)
440440
(and (sequential? data) (sequential? (first data))) (viewer/normalize-seq-of-seq data)
441+
(empty? data) {:rows []}
441442
:else nil)
442443
stats (compute-table-summary opts)
443444
active-filters (compute-filters-data opts)
@@ -514,12 +515,13 @@
514515
:autocomplete-data autocomplete-data
515516
:state state})
516517
(update :nextjournal/render-opts dissoc :computed-columns :pre-process-stats)
517-
(assoc :nextjournal/value (cond->> []
518-
(seq rows) (cons (viewer/with-viewer table-body-viewer (merge (-> applied-viewer
519-
(select-keys [:page-size])
520-
(set/rename-keys {:page-size :nextjournal/page-size}))
521-
(select-keys wrapped-value [:nextjournal/page-size]))
522-
(map (partial viewer/with-viewer table-row-viewer) rows)))
518+
(assoc :nextjournal/value (cond->> [(viewer/with-viewer table-body-viewer (merge (-> applied-viewer
519+
(select-keys [:page-size])
520+
(set/rename-keys {:page-size :nextjournal/page-size}))
521+
(select-keys wrapped-value [:nextjournal/page-size]))
522+
(if (seq rows)
523+
(map (partial viewer/with-viewer table-row-viewer) rows)
524+
[(viewer/html [:span.italic "this table has no rows"])]))]
523525
head (cons (viewer/with-viewer (:name table-head-viewer table-head-viewer) head)))))
524526
(-> wrapped-value
525527
viewer/mark-presented

0 commit comments

Comments
 (0)