Skip to content

Latest commit

 

History

History
178 lines (119 loc) · 3.91 KB

quick-start.md

File metadata and controls

178 lines (119 loc) · 3.91 KB
order icon
4
rocket-24

Quick Start

If you want to just try Pagy before using it in your own app, you have a couple of alternatives...

+++ Browser

!!!success Try it now!

Run the interactive demo from your terminal:

gem install pagy
pagy demo

...and point your browser to http://0.0.0.0:8000 !!!

+++ Console

Interact with every method, helper and extra in a IRB console without any setup:

gem install pagy

...and use it without any app

+++

1. Install

+++ With Bundler

If you use Bundler, add the gem in the Gemfile, optionally avoiding the next major version with breaking changes ( see RubyGem Specifiers):

gem 'pagy', '~> 9.1' # omit patch digit

+++ Without Bundler

If you don't use Bundler, install and require the Pagy gem:

gem install pagy
require 'pagy'

+++

2. Configure

+++ With Rails Download the configuration file linked below and save it into the config/initializers dir

!file

+++ Without Rails Download the configuration file linked below and require it when your app starts

!file +++

!!! Pagy doesn't load unnecessary code in your app! Uncomment/edit the pagy.rb file in order to explicitly require the extras you need and eventually customize the static Pagy::DEFAULT variables in the same file.

You can further customize the variables per instance, by explicitly passing any variable to the Pagy*.new constructor or to any pagy* backend/controller method. !!!

3. Backend Setup

+++ Standard

Include the backend

include Pagy::Backend

Use the pagy method

@pagy, @records = pagy(Product.some_scope)

+++ Search For search backends see: elasticsearch_rails, meilisearch, searchkick, ransack.

+++ Special You may also use the calendar, countless, geared, incremental, auto-incremental, infinite and keyset pagination

+++

4. Render the pagination

+++ Server Side !!! success Your pagination is rendered on the server !!!

Include the frontend

include Pagy::Frontend

Use a fast helper

<%# Note the double equals sign "==" which marks the output as trusted and html safe: %>
<%== pagy_nav(@pagy) %>

Pick a stylesheet or a CSS framework

  • For native pagy helpers (used also with tailwind), you can integrate the Pagy Stylesheets
  • For different CSS frameworks and different helpers (static, responsive, compact, etc.), you can look at the bootstrap, bulma extras

+++ Javascript Framework

!!! success Your pagination is rendered by Vue.js, react.js, ... !!!

Require the metadata extra

require 'pagy/extras/metadata'

Add the metadata to your JSON response

render json: { data: @records, pagy: pagy_metadata(@pagy, ...) }

+++ API Service

!!! success Your API is consumed by some client !!!

Consider using the Keyset pagination

Orders of magnitude faster on big data... see Pagy::Keyset

Require the headers extra

require 'pagy/extras/headers'

Add the pagination headers to your responses

after_action { pagy_headers_merge(@pagy) if @pagy }

Render your JSON response as usual

render json: { data: @records }

+++