input_nav_js  JavaScript Setup Required!
input_nav_js combines navigation and pagination info in a single compact element.
It is the fastest and lightest navigator, recommended when you care about efficiency and server load while still needing a UI (see Maximize performance).
It works with all paginators but :keyset.
<%== @pagy.input_nav_js(**options) %> <%# default pagy style %>
<%== @pagy.input_nav_js(:bootstrap, **options) %>
<%== @pagy.input_nav_js(:bulma, **options) %>
require 'pagy/console'
=> true
>> @pagy, @records = pagy(:offset, collection.new, page: 3)
=> [#<Pagy::Offset:0x00007f0802afd168 @request=#<Pagy::Request:0x00007f0802c830c8 @options={page: 3, request: #<Pagy::Request:0x00007f0802c830c8 ...>, client_limit: nil, limit: 20, count: 1000}, @base_url="http://www.example.com", @path="/path", @params={example: "123"}, @cookie=nil>, @options={limit: 20, limit_key: "limit", page_key: "page", page: 3, client_limit: nil, count: 1000}, @limit=20, @count=1000, @page=3, @last=50, @offset=40, @in_range=true, @from=41, @to=60, @in=20, @previous=2, @next=4>, [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]]
>> puts @pagy.input_nav_js
<nav class="pagy input-nav-js" aria-label="Pages" data-pagy="WyJpbmoiLCIvcGF0aD9leGFtcGxlPTEyMyZwYWdlPVAgIiwiUCAiXQ=="><a href="/path?example=123&page=2" rel="prev" aria-label="Previous"><</a><label>Page <input name="page" type="number" min="1" max="50" value="3" aria-current="page" style="text-align: center; width: 2rem; padding: 0;"><a style="display: none;">#</a> of 50</label><a href="/path?example=123&page=4" rel="next" aria-label="Next">></a></nav>
=> nil
>> puts @pagy.input_nav_js(:bulma, id: 'input-nav', aria_label: 'My pages')
<nav id="input-nav" class="pagy-bulma input-nav-js pagination" aria-label="My pages" data-pagy="WyJpbmoiLCIvcGF0aD9leGFtcGxlPTEyMyZwYWdlPVAgIiwiUCAiXQ=="><ul class="pagination-list"><li><a href="/path?example=123&page=2" class="pagination-previous" rel="prev" aria-label="Previous"><</a></li><li class="pagination-link"><label>Page <input name="page" type="number" min="1" max="50" value="3" aria-current="page"style="text-align: center; width: 2rem; line-height: 1.2rem; border: none; border-radius: .25rem; padding: .0625rem; color: white; background-color: #485fc7;"><a style="display: none;">#</a> of 50</label></li><li><a href="/path?example=123&page=4" class="pagination-next" rel="next" aria-label="Next">></a></li></ul></nav>
=> nil
:pagy/nil- Pagy default style
:bootstrap- Set
classes: 'pagination pagination-sm any-class'style option to override the default'pagination'class. :bulma- Set
classes: 'pagination is-small any-class'style option to override the default'pagination'classes.
id: 'my-nav'- Set the
idHTML attribute of thenavtag. aria_label: 'My Label'Override the default
pagy.aria_label.navstring of thearia-labelattribute.
See ARIA.The
navelements arelandmark rolesand should be distinctly labeled!
Override the default :aria_labels for multiple navs with distinct values!
<%# Explicitly set the aria_label %>
<%== @pagy.series_nav(aria_label: 'Search result pages') %>
anchor_string: 'data-turbo-frame="paginate"'- Concatenate a verbatim raw string to the internal HTML of the anchor tags. It must contain properly formatted HTML attributes. It's not suitable for
*_hashhelpers. absolute: true- Makes the URL absolute.
path: '/my_path'- Overrides the request path in pagination URLs. Use the path only (not the absolute URL). (see Override the request path)
fragment: '...'- URL fragment string.
querify: tweak-
Set it to a
lambdato directly edit the passed string-keyed params hash itself. Its result is ignored.tweak = ->(q) { q.except!('not_useful').merge!('custom' => 'useful') }
Overriding *_js helpers is not recommended
The *_js helpers are tightly coupled with the JavaScript code, so any partial overriding on one side would be quite fragile and might break in future releases.