yesod-paginator-0.2: A pagination approach for yesod

Safe HaskellSafe-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, and one for paginating directly out of the database, you provide the same filters as you would to selectList.

Both functions return a tuple: the first element being the list of items to display on this page and the second being a widget showing the pagination navagation links.

Synopsis

Documentation

paginateSource

Arguments

:: Int

items per page

-> [a]

complete list of items

-> GHandler s m ([a], GWidget s m ()) 

Paginate an existing list of items.

 getSomeRoute = do
     things' <- getAllThings

     (things, widget) <- paginate 10 things'

     defaultLayout $ do
         [whamlet|
             $forall thing <- things
                 ^{showThing thing}

             <div .pagination>
                  ^{widget}
             |]

selectPaginated :: (MonadTrans (PersistEntityBackend v), PersistEntity v, PersistQuery (PersistEntityBackend v) (GHandler s m)) => Int -> [Filter v] -> [SelectOpt v] -> PersistEntityBackend v (GHandler s m) ([Entity v], GWidget s1 m1 ())Source

Paginate directly out of the database.

 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}
             |]

paginationWidgetSource

Arguments

:: Int

current page

-> Int

items per page

-> Int

total number of items

-> GWidget s m () 

A widget showing pagination links. Follows bootstrap principles. Utilizes a "p" GET param but leaves all other GET params intact.