简体   繁体   English

rails pagey 一页上有多个表

[英]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.我在一页上有两个不同的表格,我想在每个表格上使用 pagy。

For sorting/searching I changed names of each pagy object so I did it like为了排序/搜索,我更改了每个页面 object 的名称,所以我这样做了

 @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.这适用于排序和搜索,但是当我尝试更改页面时,它会发送页面参数并尝试更改每个表的页面,因此如果一个表有 5 页和另一个 10 页,我尝试移至第 10 页失败因为其中一个表不能移动到不存在的表。

I was thinking to change page param (for example page_inv and page_ord) but how to do that?我正在考虑更改页面参数(例如 page_inv 和 page_ord),但该怎么做呢? Or is there some easy way how to change page only for table from selected pagy object?或者是否有一些简单的方法可以仅从选定的 pagy object 中更改表格的页面?

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.正如您已经理解的那样,pagy 使用默认的:page_param (即:page ):如果您在同一页面中使用多个实例,则应区分不同实例的:page_param ,否则它们将使用相同的。

You can pass that in the pagy method (as you did with :items ).您可以在pagy方法中传递它(就像您对:items所做的那样)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM