| Safe Haskell | Safe-Infered |
|---|
Yesod.Paginator
Description
Inspiration from a concept by ajdunlap: http://hackage.haskell.org/package/yesod-paginate
But uses an entirely different approach.
There are two pagination functions. One for arbitrary items where you provide the list of things to be paginated:
getSomeRoute = do
things' <- getAllThings
(things, widget) <- paginate 10 things'
defaultLayout $ do
[whamlet|
$forall thing <- things
^{showThing thing}
<div .pagination>
^{widget}
|]
And another for paginating directly out of the database, you provide
the same filters as you would to selectList.
getSomeRoute something = do
-- note: things is [Entity val] just like selectList returns
(things, widget) <- runDB $ selectPaginated 10 [SomeThing ==. something] []
defaultLayout $ do
[whamlet|
$forall thing <- things
^{showThing $ entityVal thing}
<div .pagination>
^{widget}
|]
Both functions return a tuple: the first element being the list of items (or Entities) to display on this page and the second being a widget showing the pagination navagation links.
Documentation
paginateWith :: PageWidget s m -> Int -> [a] -> GHandler s m ([a], GWidget s m ())Source
selectPaginated :: (PersistEntity val, PersistQuery (PersistEntityBackend val) (GHandler s m), MonadTrans (PersistEntityBackend val)) => Int -> [Filter val] -> [SelectOpt val] -> PersistEntityBackend val (GHandler s m) ([Entity val], GWidget s m ())Source
selectPaginatedWith :: (PersistEntity val, PersistQuery (PersistEntityBackend val) (GHandler s m), MonadTrans (PersistEntityBackend val)) => PageWidget s m -> Int -> [Filter val] -> [SelectOpt val] -> PersistEntityBackend val (GHandler s m) ([Entity val], GWidget s m ())Source
module Yesod.Paginator.Widget