avo
avo copied to clipboard
Add option to configure via_per_page on has_many
Feature
Currently, it seems only possible to set a global via_per_page.
It would be useful to have the ability to override that value in the resource itself.
API could be something like:
module Avo
module Resources
class CatalogProduct < Avo::BaseResource
def fields
field :certifications, as: :has_many, per_page: 72
end
end
end
or alternatively, we could default it per resource.
module Avo
module Resources
class CatalogCertification < Avo::BaseResource
self.via_per_page = 72
self.per_page = 24
def fields
# ...
end
end
end
This is useful because in most case, we want a smaller pagination window, but we do have a few workflows where it's useful to see a large amount of items for triggering action on a batch of records.
Current workarounds
Not aware of any
Screenshots or screen recordings
Additional context
I think this can be useful, thanks for submitting it @smathieu
API suggestion:
module Avo
module Resources
class CatalogCertification < Avo::BaseResource
self.pagination = -> do
{
via_per_page: 72
per_page: 24
}
end
def fields
# ...
end
end
end
This way inside pagination proc we can do some custom logic looking into params to check if is association or not and set pagination params accordingly.
You can set the via_per_page globally right now.
Otherwise, IDK is self.via_per_page would do it justice.
I would rather do the first option:
field :certifications, as: :has_many, per_page: 72
If the global configuration is enough for you, @smathieu, then it's ok to close this issue. If you need something more granular, we'll merge a PR with that. Unfortunately, we can't prioritize and work on it right now.
The global configuration doesn't work very well for us, as we do have a use case where we need ~100 records rendering in a page, but that's way too much for other views.
This isn't super urgent for us, but we'd definitely benefit from the option to configure it.
All proposed API would work, but I think I prefer the per field proposed by @adrianthedev
Got it!
Yes, the field config should work better from the same reason that you want to configure the per_page only in some scenarios.
I added the Help wanted label. Maybe someone wants to pick it up.
Please assign to me
Thank you @G-Simpson!
+1 from https://discord.com/channels/740892036978442260/1125160641569771550/1309337580143251536