Mi Ro
Mi Ro

Reputation: 760

rails pagy multiple tables on one page

I have two different tables on one page and I want to use pagy on each of them.

For sorting/searching I changed names of each pagy object so I did it like

 @pagy_inv, @invoices = pagy @invoices.reorder(sort_column_show_city_invoices => sort_direction_show_city_invoices), items: params.fetch(:count, 10)

and

 @pagy_ord, @orders = pagy @orders.reorder(sort_column_show_city_orders => sort_direction_show_city_orders), items: params.fetch(:count, 10)

which works fine for sorting and searching, but when I try to change page, it sends page parameter and tries to change page for every table and therefore if one table has like 5 pages and another 10 and I try to move to page 10 it fails because one of the table cannot move to not existing table.

I was thinking to change page param (for example page_inv and page_ord) but how to do that? Or is there some easy way how to change page only for table from selected pagy object?

Upvotes: 0

Views: 1032

Answers (1)

user712557
user712557

Reputation: 347

As you already understood, pagy use a default :page_param (which is :page): if you use more than one instance in the same page you should differentiate the :page_param of different instances or they will use all the same.

You can pass that in the pagy method (as you did with :items).

Upvotes: 1

Related Questions