All Projects → stephenmoloney → scrivener_list

stephenmoloney / scrivener_list

Licence: MIT License
A Scrivener compatible extension that allows pagination of a list of elements.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to scrivener list

mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (+347.83%)
Mutual labels:  pagination, paginate
React Paginate
A ReactJS component that creates a pagination
Stars: ✭ 2,169 (+9330.43%)
Mutual labels:  pagination, paginate
paginathing
a jQuery plugin to paginate your DOM easily.
Stars: ✭ 23 (+0%)
Mutual labels:  pagination, paginate
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (+200%)
Mutual labels:  pagination, paginate
vue-tiny-pagination
A Vue component for create a tiny pagination with Flexbox
Stars: ✭ 20 (-13.04%)
Mutual labels:  pagination, paginate
loopback-paginator
No description or website provided.
Stars: ✭ 13 (-43.48%)
Mutual labels:  pagination
react-strap-table
react table (client and server-side) based on bootstrap.
Stars: ✭ 28 (+21.74%)
Mutual labels:  pagination
flop
Filtering, ordering and pagination for Ecto
Stars: ✭ 56 (+143.48%)
Mutual labels:  pagination
docsify-pagination
↔️ Pagination for docsify
Stars: ✭ 80 (+247.83%)
Mutual labels:  pagination
MR.EntityFrameworkCore.KeysetPagination
Keyset/Seek/Cursor pagination for Entity Framework Core.
Stars: ✭ 19 (-17.39%)
Mutual labels:  pagination
mongoose-graphql-pagination
GraphQL cursor pagination (Relay-like) for Mongoose models.
Stars: ✭ 29 (+26.09%)
Mutual labels:  pagination
gorm-cursor-paginator
A paginator doing cursor-based pagination based on GORM
Stars: ✭ 92 (+300%)
Mutual labels:  pagination
pagi
A better WordPress pagination.
Stars: ✭ 30 (+30.43%)
Mutual labels:  pagination
checkbox.sh
Interactive checkboxes (menu) with pagination and vim keybinds for bash
Stars: ✭ 26 (+13.04%)
Mutual labels:  pagination
Pageable
An easy way to Pagination or Infinite scrolling for TableView/CollectionView
Stars: ✭ 44 (+91.3%)
Mutual labels:  pagination
react-crud-table
A table that includes all the CRUD operations.
Stars: ✭ 34 (+47.83%)
Mutual labels:  pagination
Exopite-Multifilter-Multi-Sorter-WordPress-Plugin
Display and/or sort/filter any page or post types by multiple taxonomies or terms (like post by categories and/or tags) with AJAX. Exopite multifilter, multi-sortable, multi selectable, multi filterable sortable Wordpress Plugin.
Stars: ✭ 18 (-21.74%)
Mutual labels:  pagination
uni-z-paging
【uni-app自动分页器】超简单!仅需两步轻松完成完整分页逻辑(下拉刷新、上拉加载更多),分页全自动处理。支持自定义加载更多的文字或整个view,自定义下拉刷新样式,自动管理空数据view等。
Stars: ✭ 91 (+295.65%)
Mutual labels:  pagination
pykeyboard
Best Keyboard and Pagination for the Pyrogram Library.
Stars: ✭ 42 (+82.61%)
Mutual labels:  pagination
laravel-pagination-with-havings
Makes it possible to use pagination with havings in queries with Laravel.
Stars: ✭ 66 (+186.96%)
Mutual labels:  pagination

Scrivener.List

Build Status Hex Version Hex docs

Scrivener.List is a Scrivener compatible extension that allows the pagination of a list of elements.

Features

  1. Scrivener.List extends the protocol Scrivener.Paginater.paginate/2 from the scrivener library.
  2. Scrivener.List also extends the function MyApp.Repo.paginate/2 from the scrivener_ecto library.

Using the second feature is entirely optional. It's provided as a convenience where the scrivener_ecto library is also being used in the project and gives access to the pre-configured MyApp.Repo module.

Usage

1. Usage without a Repo module

Scrivener.paginate(list, config)

Arguments (without a repo)

  • list: A list of elements to be paginated

  • config: A configuration object with the pagination details. Can be in any of the following formats:

    • %{page: page_number, page_size: page_size} (map)
    • [page: page_number, page_size: page_size] (Keyword.t)
    • %Scrivener.Config{page_number: page_number, page_size: page_size} (Scrivener.Config.t)

max_page_size cannot be configured with method 1.

Examples

def index(conn, params) do
  config = maybe_put_default_config(params)

  page = 
    ["C#", "C++", "Clojure", "Elixir", "Erlang", "Go", "JAVA", "JavaScript", "Lisp",
      "PHP", "Perl", "Python", "Ruby", "Rust", "SQL"]
    |> Enum.map(&(&1 <> "  " <> "language"))
    |> Scrivener.paginate(config)

  render conn, :index,
    people: page.entries,
    page_number: page.page_number,
    page_size: page.page_size,
    total_pages: page.total_pages,
    total_entries: page.total_entries
end

defp maybe_put_default_config(%{page: page_number, page_size: page_size} = params), do: params
defp maybe_put_default_config(_params), do: %Scrivener.Config{page_number: 1, page_size: 10}
list = ["C#", "C++", "Clojure", "Elixir", "Erlang", "Go", "JAVA", "JavaScript", "Lisp",
        "PHP", "Perl", "Python", "Ruby", "Rust", "SQL"]
        
Scrivener.paginate(list, %Scrivener.Config{page_number: 1, page_size: 4}) # %Scrivener.Config{}
Scrivener.paginate(list, page: 1, page_size: 4) # keyword list
Scrivener.paginate(list, %{page: 1, page_size: 4}) # map
Scrivener.paginate(list, %{page: 1}) # map with only page number (page_size defaults to 10)

2. Usage with a Repo module

Usage without a Repo is entirely optional and is added to Scrivener.List for convenience. Firstly, see Scrivener.Ecto and configure the MyApp.Repo module.

Example Repo configuration

defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres
  use Scrivener,
    page_size: 10,
    max_page_size: 100
end
MyApp.Repo.paginate(list, config)

Arguments (with a repo)

  • list: A list of elements to be paginated

  • config: A configuration object with the pagination details. Can be in any of the following formats:

    • %{page: page_number, page_size: page_size} (map)
    • [page: page_number, page_size: page_size] (Keyword.t)

max_page_size can be configured with method 1. See Scrivener.Ecto.

Example

Example based on scrivener_ecto readme.

def index(conn, params) do
  %{age: age, name: name} = params["search"] 
  
  page = MyApp.Person
  |> where([p], p.age > ^age)
  |> order_by([p], desc: p.age)
  |> preload(:friends)
  |> MyApp.Repo.all()
  |> Enum.filter(fn(person) -> person.data.friend.name = name end)
  |> MyApp.Repo.paginate(params)

  render conn, :index,
    people: page.entries,
    page_number: page.page_number,
    page_size: page.page_size,
    total_pages: page.total_pages,
    total_entries: page.total_entries
end

Installation

Add scrivener_list to your list of dependencies in mix.exs:

def deps do
  [
    {:scrivener_list, "~> 2.0"}
  ]
end

Tests

MIX_ENV=test mix test

Acknowledgements

The introduction of the protocol for scrivener enabled the separation of this package into it's own repository.

Licence

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].