© 2018 Domizio DemichelisMIT License

Extras

Pagy comes with a few optional extensions/extras:

Extra Description Links
array Paginate arrays efficiently avoiding expensive array-wrapping and without overriding array.rb, documentation
bootstrap Nav, responsive and compact helpers and templates for the Bootstrap pagination component bootstrap.rb, documentation
bulma Nav, responsive and compact helpers and templates for the Bulma pagination component bulma.rb, documentation
elasticsearch_rails Paginate elasticsearch_rails gem results efficiently elasticsearch_rails.rb, documentation
foundation Nav, responsive and compact helpers and templates for the Foundation pagination component foundation.rb, documentation
i18n Use the I18n gem instead of the pagy implementation i18n.rb, documentation
items Allow the client to request a custom number of items per page with a ready to use selector UI items.rb, documentation
materialize Nav, responsive and compact helpers for the Materialize CSS pagination component materialize.rb, documentation
navs Add responsive and compact generic/unstyled nav helpers navs.rb, documentation
out_of_range Allow for easy handling of out of range pages out_of_range.rb, documentation
searchkick Paginate arrays efficiently avoiding expensive array-wrapping and without overriding searchkick.rb, documentation
semantic Nav helpers for the Semantic UI CSS pagination component semantic.rb, documentation
trim Remove the page=1 param from links trim.rb, documentation

Synopsys

Extras are not loaded by default, so you should require them explicitly in your pagy.rb initializer (see Configuration):

require 'pagy/extras/bootstrap'
require 'pagy/extras/...'

Description

Extras don’t define any new module or class, they just re-open the Pagy class and modules, adding the extra methods as they were part of the loaded pagy gem. This neatly separates the core code from the optional extras, still keeping its usage as simple as it were part of the core.

Methods

All the added methods are documented in the respective extras.

Javascript

The compact and responsive navs, and the items extra use javascript, so if you use any of them you should load the pagy.js file, and run Pagy.init() on window load.

In rails apps

Add the assets-path in the pagy.rb initializer:

Rails.application.config.assets.paths << Pagy.root.join('javascripts')

Add the pagy javascript to the application.js:

//= require pagy

Add an event listener for turbolinks:

window.addEventListener("turbolinks:load", Pagy.init);

In non-rails apps

Ensure the pagy/extras/javascripts/pagy.js script gets served with the page and add an event listener like:

window.addEventListener('load', Pagy.init);

or execute the Pagy.init() using jQuery:

$( window ).load(function() {
  Pagy.init()
});