GithubHelp home page GithubHelp logo

lightquake / yesod-paginator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pbrisbin/yesod-paginator

2.0 2.0 0.0 99 KB

Pagination in yesod applications

License: BSD 3-Clause "New" or "Revised" License

Haskell 100.00%

yesod-paginator's Introduction

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.

yesod-paginator's People

Contributors

lightquake avatar pbrisbin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.