Commit 1b759a79 authored by Heinz N. Gies's avatar Heinz N. Gies

Improve pagination and fix wrong page after search

parent d00f8413
......@@ -128,9 +128,13 @@
match (re-matches #".*[?]page=([0-9]+)$" href)
entries (count all-rows)
sel-page (if match (str->int (second match)) 0)
page-size 20
max-page (Math/ceil (/ entries page-size))
page-size 5
max-page (dec (Math/ceil (/ entries page-size)))
_ (pr "max-page:" max-page)
_ (pr "sel-page:" sel-page)
page (min max-page sel-page)
_ (pr "page:" page)
all-rows (drop (* page page-size) all-rows)
all-rows (take page-size all-rows)
set-filter (mk-filter-field section)
......@@ -159,27 +163,28 @@
{}
(b/button-group
{:class "fctabuttons"}
(b/button {
:bs-size "small"
:disabled? (= page 0)
:on-click #(let [new-page (max 0 (dec (:page state)))]
(om/set-state! owner :page new-page)
(goto (ppath new-page)))} "<")
(let [pagination-buttons 20
p-start (max 0 (- page (/ pagination-buttons 2)))
pages (min pagination-buttons (max 1 (- max-page p-start)))]
(map (fn [p]
(b/button {:bs-size "small"
;;:bs-style (if (= page p) "primary" "danger")
:style {:color (if (= page p) "blue" "black")}
:on-click #(do (om/set-state! owner :page p)
(goto (ppath p)))} p))
(take pages (iterate inc p-start))))
(b/button {:bs-size "small"
:disabled? (= page (dec max-page))
:on-click #(let [new-page (min max-page (inc (:page state)))]
(om/set-state! owner :page new-page)
(goto (ppath new-page)))} ">")))
(if (> max-page 0)
[(b/button {
:bs-size "small"
:disabled? (= page 0)
:on-click #(let [new-page (max 0 (dec (:page state)))]
(om/set-state! owner :page new-page)
(goto (ppath new-page)))} "<")
(let [pagination-buttons 20
p-start (max 0 (- page (/ pagination-buttons 2)))
pages (min pagination-buttons (max 1 (- (inc max-page) p-start)))]
(map (fn [p]
(b/button {:bs-size "small"
;;:bs-style (if (= page p) "primary" "danger")
:style {:color (if (= page p) "blue" "black")}
:on-click #(do (om/set-state! owner :page p)
(goto (ppath p)))} p))
(take pages (iterate inc p-start))))
(b/button {:bs-size "small"
:disabled? (= page (dec max-page))
:on-click #(let [new-page (min max-page (inc (:page state)))]
(om/set-state! owner :page new-page)
(goto (ppath new-page)))} ">")])))
(table/render section all-rows {:root root :actions actions :fields display-fields :set-filter set-filter :show fields})
(well/well section all-rows {:root root :actions actions :set-filter set-filter :show fields})
)))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment