View Source Torch.PaginationView (Torch v5.2.0)

Summary

Functions

Generates a "Next >" link to the next page of results. The link is only returned if there is another page.

Generates a "N" link to a page of results (where N is the page number).

Render pagination links directly from a Plug.Conn

Generates a "< Prev" link to the previous page of results. The link is only returned if there is a previous page.

Render Torch pagination links based on current page, sort, and filters

Functions

Link to this function

next_link(assigns)

View Source (since 5.0.0)

Generates a "Next >" link to the next page of results. The link is only returned if there is another page.

Examples

iex> a = %{__changed__: nil, query_string: "", conn_params: %{page: 2}, page_number: 2, total_pages: 4}
...> next_link(a) |> Phoenix.HTML.Safe.to_iodata() |> IO.iodata_to_binary()
"<a href=\"?page=3\">Next &gt;</a>"

If there is no available next page, returns an empty string:

iex> a = %{__changed__: nil, query_string: "", conn_params: %{page: 2}, page_number: 2, total_pages: 2}
...> next_link(a) |> Phoenix.HTML.Safe.to_iodata() |> IO.iodata_to_binary()
""

Attributes

  • query_string (:string) - Defaults to "".
  • conn_params (:any) (required)
  • page_number (:integer) (required)
  • total_pages (:integer) (required)
Link to this function

page_link(assigns)

View Source (since 5.0.0)

Generates a "N" link to a page of results (where N is the page number).

Examples

iex> a = %{__changed__: %{}, query_string: "", conn_params: %{page: 1}, page_number: 14}
...> page_link(a) |> Phoenix.HTML.Safe.to_iodata() |> IO.iodata_to_binary()
"<a href=\"?page=14\" class=\"\">14</a>"

It will also allow customizing of the "active" link:

iex> a = %{__changed__: %{}, query_string: "", conn_params: %{page: 1}, page_number: 14, is_active: true}
...> page_link(a) |> Phoenix.HTML.Safe.to_iodata() |> IO.iodata_to_binary()
"<a href=\"?page=14\" class=\"active\">14</a>"

Attributes

  • query_string (:string) - Defaults to "".
  • conn_params (:any) (required)
  • page_number (:integer) (required)
  • is_active (:boolean) - Defaults to false.

Render pagination links directly from a Plug.Conn

Link to this function

prev_link(assigns)

View Source (since 5.0.0)

Generates a "< Prev" link to the previous page of results. The link is only returned if there is a previous page.

Examples

iex> a = %{__changed__: nil, query_string: "", conn_params: %{page: 3}, page_number: 3}
...> prev_link(a) |> Phoenix.HTML.Safe.to_iodata() |> IO.iodata_to_binary()
"<a href=\"?page=2\">&lt; Prev</a>"

If the current page is 1, returns an empty string:

iex> a = %{__changed__: nil, query_string: "", conn_params: %{page: 1}, page_number: 1}
...> prev_link(a) |> Phoenix.HTML.Safe.to_iodata() |> IO.iodata_to_binary()
""

Attributes

  • query_string (:string) - Defaults to "".
  • conn_params (:any) (required)
  • page_number (:integer) (required)
Link to this function

torch_pagination(assigns)

View Source (since 5.0.0)

Render Torch pagination links based on current page, sort, and filters

Attributes

  • page_number (:integer) (required)
  • page_size (:integer) (required)
  • total_pages (:integer) (required)
  • total_entries (:integer) (required)
  • distance (:integer)
  • sort_field (:string)
  • sort_direction (:string)
  • query_string (:string) (required)
  • conn_params (:map) (required)