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

Link to this section Summary

Link to this section Functions

Link to this function

paginate(query, params, opts \\ [])

View Source
paginate(Ecto.Query.t(), map(), nil | keyword()) ::
  {list(), Dissolver.Paginator.t()}