Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Pagination in yesod applications
Haskell
tree: 44fe23f0fe

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Yesod
LICENSE
README.md
Setup.hs
yesod-paginator.cabal

README.md

Yesod paginator

import Yesod.Paginator

Do you have some [Thing] that you've already selected out of your DB, maybe composed from multiple tables, and you just want to paginate this big list?

getPageR :: Handler RepHtml
getPageR = do
    things' <- getAllThings

    -- note: things will be the same type as things'
    (things, widget) <- paginate 10 things'

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

            ^{widget}
            |]

Do you have a single table of records and you want to paginate them, selecting only the records needed to display the current page?

getPageR :: Handler RepHtml
getPageR = do
    (things, widget) <- runDB $ selectPaginated 10 [] []

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

            ^{widget}
            |]

Notes:

selectPaginated can be thought of a direct drop-in for selectList. This means it can be thrown inside any existing runDB block. Example here

paginationWidget is also available if you've already got more complicated database code doing the record pagination but you just want the pretty links. Example here.

Something went wrong with that request. Please try again.