Handle a database query and/or array-math to paginate a list and produce a pagination widget suitable for Bootstrap.
Paginate directly out of the database:
getPageR :: Handler Html
getPageR = do
(things, widget) <- runDB $ selectPaginated 10 [] []
defaultLayout $ do
[whamlet|
$forall thing <- things
^{showThing $ snd thing}
^{widget}
|]
Or an existing list in memory:
getPageR :: Handler Html
getPageR = do
things' <- getAllThings
(things, widget) <- paginate 10 things'
defaultLayout $ do
[whamlet|
$forall thing <- things
^{showThing thing}
^{widget}
|]
Just provide the pagination widget:
getPageR :: Handler Html
getPageR = do
cur <- getCurrentPage
let limit = 10
(items, total) <- runSphinxSearch "query" limit
defaultLayout $ do
[whamlet|
$forall thing <- things
^{showThing thing}
^{defaultWidget cur limit total}
|]
getPageR :: Handler Html
getPageR = do
(things, widget) <- selectPaginatedWith myWidget 10 [] []
defaultLayout $ do
-- ...
where
myWidget :: PageWidget App
myWidget = paginationWidget $ PageWidgetConfig
{ prevText = "Newer"
, nextText = "Older"
, pageCount = 7
, ascending = False
, showEllipsis = False
, listClasses = ["pagination", "pagination-centered"]
}
$ cabal install warp
$ cabal install
$ runhaskell ./Test.hs
$ $BROWSER http://localhost:3000