The number of items for a page in Kaminari is defined by:
My question is, how to obtain that number of items in view?
Update
Pardon me for being not clear. What I want is to show is the order of item in each page. I have a table header:
<th>#</th>
And several columns below:
<td><%= (@sales.current_page - 1) * some_ruby_code + index + 1 %></td>
My question is what some_ruby_code
should be?
1) If I substitute some_ruby_code
with Sale.per_page
, it will throw error when I decided to delete per_page
.
2) If I substitute some_ruby_code
with Kaminari.config.default_per_page
, it won't show the proper value when I add per_page
in model.
I want to know whether there are a method in Kaminari which detects the existence of per_page
, return its value if exists, or Kaminari.config.default_per_page
otherwise.
Thank you!
You can use Sale.default_per_page
.
See https://github.com/kaminari/kaminari/blob/1-0-stable/kaminari-core/lib/kaminari/models/configuration_methods.rb#L16
You can use ActiveRecord's limit_value
method for this, since Kaminari internally uses limit and offset.
User.all.limit(10).limit_value
=> 10
With kaminari is the same:
User.page(3).per(10).limit_value
=> 10
User.page(3).per(10).offset_value
=> 20
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With