| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Yesod.Paginator
Description
There are two pagination functions. One for arbitrary items where you provide the list of things to be paginated:
getSomeRoute = do
-- 10 items per page
pages <- paginate 10 =<< getAllThings
defaultLayout $ do
[whamlet|
$forall thing <- pageItems $ pagesCurrent pages
^{showThing thing}
$# display at most 5 page elements, with current page middle-ish
^{simple 5 pages}
|]
And another for paginating directly out of the database, you provide the same
arguments as you would for :selectList
getSomeRoute something = do
pages <- runDB $ selectPaginated 10 [SomeThing ==. something] []
defaultLayout $ do
[whamlet|
$forall thing <- pageItems $ pagesCurrent pages
^{showThing $ entityVal thing}
^{simple 5 pages}
|]
Synopsis
- data PageNumber
- data PerPage
- data ItemsCount
- data Pages a
- pagesCurrent :: Pages a -> Page a
- data Page a
- pageItems :: Page a -> [a]
- paginate :: MonadHandler m => PerPage -> [a] -> m (Pages a)
- paginateWith :: MonadHandler m => PaginationConfig -> [a] -> m (Pages a)
- selectPaginated :: (MonadHandler m, PersistEntity record, PersistEntityBackend record ~ BaseBackend backend, PersistQueryRead backend) => PerPage -> [Filter record] -> [SelectOpt record] -> ReaderT backend m (Pages (Entity record))
- selectPaginatedWith :: (MonadHandler m, PersistEntity record, PersistEntityBackend record ~ BaseBackend backend, PersistQueryRead backend) => PaginationConfig -> [Filter record] -> [SelectOpt record] -> ReaderT backend m (Pages (Entity record))
- simple :: Natural -> PaginationWidget m a
- simpleWith :: PaginationConfig -> Natural -> PaginationWidget m a
- ellipsed :: Natural -> PaginationWidget m a
- ellipsedWith :: PaginationConfig -> Natural -> PaginationWidget m a
- data PaginationConfig = PaginationConfig {}
- newtype PageParamName = PageParamName {}
Type-safe numerics
data PageNumber Source #
Instances
Instances
| Enum PerPage Source # | |
| Eq PerPage Source # | |
| Integral PerPage Source # | |
Defined in Yesod.Paginator.Pages | |
| Num PerPage Source # | |
| Ord PerPage Source # | |
Defined in Yesod.Paginator.Pages | |
| Read PerPage Source # | |
| Real PerPage Source # | |
Defined in Yesod.Paginator.Pages Methods toRational :: PerPage -> Rational # | |
| Show PerPage Source # | |
| PathPiece PerPage Source # | |
Defined in Yesod.Paginator.Pages | |
data ItemsCount Source #
Instances
Paginated data
Instances
| Functor Pages Source # | |
| Foldable Pages Source # | |
Defined in Yesod.Paginator.Pages Methods fold :: Monoid m => Pages m -> m # foldMap :: Monoid m => (a -> m) -> Pages a -> m # foldMap' :: Monoid m => (a -> m) -> Pages a -> m # foldr :: (a -> b -> b) -> b -> Pages a -> b # foldr' :: (a -> b -> b) -> b -> Pages a -> b # foldl :: (b -> a -> b) -> b -> Pages a -> b # foldl' :: (b -> a -> b) -> b -> Pages a -> b # foldr1 :: (a -> a -> a) -> Pages a -> a # foldl1 :: (a -> a -> a) -> Pages a -> a # elem :: Eq a => a -> Pages a -> Bool # maximum :: Ord a => Pages a -> a # minimum :: Ord a => Pages a -> a # | |
| Traversable Pages Source # | |
| Eq a => Eq (Pages a) Source # | |
| Show a => Show (Pages a) Source # | |
pagesCurrent :: Pages a -> Page a Source #
The current page
Instances
| Functor Page Source # | |
| Foldable Page Source # | |
Defined in Yesod.Paginator.Pages Methods fold :: Monoid m => Page m -> m # foldMap :: Monoid m => (a -> m) -> Page a -> m # foldMap' :: Monoid m => (a -> m) -> Page a -> m # foldr :: (a -> b -> b) -> b -> Page a -> b # foldr' :: (a -> b -> b) -> b -> Page a -> b # foldl :: (b -> a -> b) -> b -> Page a -> b # foldl' :: (b -> a -> b) -> b -> Page a -> b # foldr1 :: (a -> a -> a) -> Page a -> a # foldl1 :: (a -> a -> a) -> Page a -> a # elem :: Eq a => a -> Page a -> Bool # maximum :: Ord a => Page a -> a # | |
| Traversable Page Source # | |
| Eq a => Eq (Page a) Source # | |
| Show a => Show (Page a) Source # | |
Paginators
paginateWith :: MonadHandler m => PaginationConfig -> [a] -> m (Pages a) Source #
Paginate a list of items given a pagination config
selectPaginated :: (MonadHandler m, PersistEntity record, PersistEntityBackend record ~ BaseBackend backend, PersistQueryRead backend) => PerPage -> [Filter record] -> [SelectOpt record] -> ReaderT backend m (Pages (Entity record)) Source #
Paginate out of a persistent database
selectPaginatedWith :: (MonadHandler m, PersistEntity record, PersistEntityBackend record ~ BaseBackend backend, PersistQueryRead backend) => PaginationConfig -> [Filter record] -> [SelectOpt record] -> ReaderT backend m (Pages (Entity record)) Source #
Paginate out of a persistent database given a pagination config
Widgets
simple :: Natural -> PaginationWidget m a Source #
Simple widget, limited to show the given number of total page elements
Pseudo-HTML for , on page 1:simple 5
<ul .pagination>
<li .prev .disabled><a>«
<li .active .disabled><a>1
<li .next><a href="?p=2">2
<li .next><a href="?p=3">3
<li .next><a href="?p=4">4
<li .next><a href="?p=5">5
<li .next><a href="?p=2">»
And page 7:
<ul .pagination>
<li .prev><a href="?p=6">«
<li .prev><a href="?p=5">5
<li .prev><a href="?p=6">6
<li .active .disabled><a>7
<li .next><a href="?p=8">8
<li .next><a href="?p=9">9
<li .next><a href="?p=8">»
simpleWith :: PaginationConfig -> Natural -> PaginationWidget m a Source #
ellipsed :: Natural -> PaginationWidget m a Source #
Show pages before and after, ellipsis, and first/last
ellipsedWith :: PaginationConfig -> Natural -> PaginationWidget m a Source #
Pagination configuration
data PaginationConfig Source #
Constructors
| PaginationConfig | |
newtype PageParamName Source #
Constructors
| PageParamName | |
Fields | |
Instances
| Eq PageParamName Source # | |
Defined in Yesod.Paginator.PaginationConfig Methods (==) :: PageParamName -> PageParamName -> Bool # (/=) :: PageParamName -> PageParamName -> Bool # | |
| Read PageParamName Source # | |
Defined in Yesod.Paginator.PaginationConfig Methods readsPrec :: Int -> ReadS PageParamName # readList :: ReadS [PageParamName] # | |
| Show PageParamName Source # | |
Defined in Yesod.Paginator.PaginationConfig Methods showsPrec :: Int -> PageParamName -> ShowS # show :: PageParamName -> String # showList :: [PageParamName] -> ShowS # | |
| PathPiece PageParamName Source # | |
Defined in Yesod.Paginator.PaginationConfig | |