LostKobrakai
For pagination many people (like me) use scrivener and scrivener_ecto, which works great for offset based pagination. What never really fit my work though was scrivener_html, because I often don’t use frameworks and it took over link generation and styles so extensively.
A thread here on the forums today made me clean up some code I wrote a few days ago for a new project and release it on hex:
https://github.com/madeitGmbH/numerator
The package does not generate any markup at all, but instead creates a list of elements, which describe the pagination. You need to keep GET parameters on the urls, because the paginated content is filtered? Numerator doesn’t care. You want to use custom styles? Go ahead. You need to display the pagination in a CLI? No problem.
iex(1)> Numerator.build(%{page: 6, last: 17}, show_first: true, show_last: true)
[
%{page: 5, type: :prev},
%{page: 1, type: :page},
%{type: :ellipsis},
%{page: 4, type: :page},
%{page: 5, type: :page},
%{page: 6, type: :current},
%{page: 7, type: :page},
%{page: 8, type: :page},
%{type: :ellipsis},
%{page: 17, type: :page},
%{page: 7, type: :next}
]
It does support a scrivener page struct as first argument as well, so there’s no need to convert the map parameters manually.
I’ve also added an example implementation for bootstrap in the readme: numerator/README.md at master · LostKobrakai/numerator · GitHub
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
I just released an update to the package:
0.2.1
Small number:
1..100; Large number:1..100_000; Number of pages to show:5Before:
After:
Additionally I’d like to note, that for all of you using liveview this library might be worth looking into. It will allow proper change tracking as all the markup is handled in the template and not in some function call the template engine has no way to look into.
lucaong
Nice library! I was looking for something similar and was about to build something myself. Your update message comes at the perfect time, as I missed your first announcement. Great job!
cnck1387
I recently started using this library. It works really nicely with scrivener_ecto.
LostKobrakai
I just pushed an update with a breaking change (0.3.0) where
:show_firstand:show_lastpages are tagged:firstand:lastrespectively – instead of just:page– when they’re separated from the normal pagination pages by an:ellipsis. So now they can be styled differently once the ellipsis starts appearing.Kurisu
Please @LostKobrakai, is this still what you use or would recommend with the Numerator package today for pagination?
LostKobrakai
I haven’t been in the need for implementing pagination in a while, but I’d still use this. The returned list should play well with liveviews change tracking