Dissolver v0.9.3 Dissolver View Source
Pagination for Ecto and Phoenix.
Dissolver is the continuation and fork of the fine work kerosene Out of respect to the authors of kerosene I won't be publishing this on https://hex.pm/ untill and if this becomes the replacement for kerosene.
Until then you will need to install this from github.
Installation
add Dissolver to your mix.exs dependencies:
def deps do
[
{:dissolver, github: 'MorphicPro/dissolver'}
]
end
Next provide Dissolver your Repo module via the config. Add the following to your config:
...
config :dissolver,
repo: MyApp.Repo
per_page: 2
import_config "#{Mix.env()}.exs"
For more information about the configuration options look at the Configurations section
Now you are ready to start using Dissolver.
Usage
Start paginating your queries
def index(conn, params) do
{products, paginator} =
Product
|> Product.with_lowest_price
|> Dissolver.paginate(params)
render(conn, "index.html", products: products, paginator: paginator)
end
Add the view helper to your view
defmodule MyApp.ProductView do
use MyApp.Web, :view
import Dissolver.HTML
end
Generate the links using the view helper in your template
<%= paginate @conn, @paginator %>
Importing Dissolver.HTML
provides your template access
to Dissolver.HTML.paginate/3
as the prior example shows.
The Dissolver.HTML.paginate/3
can take a host of options to aid
the theme from how many links to show (window: integer
) to what the
link labels should read.
By default the theme used to generate the html is the Dissolver.HTML.Simple
theme.
It will only provide the very basic prev|next buttons. For more theme options, including providing
your own, read the following Configurations
Configuration
This module uses the following that can be set as globals in your config/config.ex
configurations
:repo
- Required Your app's Ecto Repo:theme
(default:Dissolver.HTML.Simple
) - A module that implements theDissolver.HTML.Theme
behavior There are a few pre defiend theme modules found indessolver/html/
Dissolver.HTML.Simple
- This is the default with only previous | next linksDissolver.HTML.Bootstrap
- A Bootstrap 4 themeDissolver.HTML.Foundation
- A Foundation themeDissolver.HTML.Materialize
- A Materialize themeDissolver.HTML.Semantic
- A Semantic UI themeDissolver.HTML.Tailwind
- A Tailwind CSS theme
:per_page
(default: 20) - The global per page setting:max_per_page
- The max value for:per_page
, if nil this will default to:per_page
:max_page
- The limit of pages allow to navigate regardless of total pages found This option is ignored if not provided and defaults to total pages found in the query.:max_count
- The max limit of total items that will looked up:lazy
(default: false) - This option if enabled will result in allDissolver.paginate/3
calls return an Ecto.Query rather than call Repo.all. This is useful for when you need to paginate on an association via a preload. TODO: provide example. Note you will also want to pass the:total_count
option while using lazy. ##
Link to this section Summary
Link to this section Functions
paginate(query, params, opts \\ [])
View Sourcepaginate(Ecto.Query.t(), map(), nil | keyword()) :: {list(), Dissolver.Paginator.t()}