Does AshAdmin support pagination?

I want to use AshAdmin. The tables I use contain a couple of 10,000 entries. Too many for a single page. I haven't seen pagination yet. Is it already implemented or is there some config switch which limits the queries?
11 Replies
ZachDaniel
ZachDaniel3y ago
Yep! You just need to enable pagination on the read action
Stefan Wintermeyer
I am struggling a bit with this. How would I implement that in this code?
actions do
defaults [:read, :update, :destroy]

create(:create) do
argument :level_id, :string
primary? true
change manage_relationship(:level_id, :level, type: :append_and_remove)
end
end
actions do
defaults [:read, :update, :destroy]

create(:create) do
argument :level_id, :string
primary? true
change manage_relationship(:level_id, :level, type: :append_and_remove)
end
end
I can't find anything about configuring it here on this page https://hexdocs.pm/ash/pagination.html Or am I barking at the wrong tree and I have to add this in the LiveView files? Which ones would that be?
ZachDaniel
ZachDaniel3y ago
Definitely something you want to implement using the core pagination features 🙂
read :read do
primary? true # add this if you’re overriding the primary read
pagination offset?: true, keyset?: true
end
read :read do
primary? true # add this if you’re overriding the primary read
pagination offset?: true, keyset?: true
end
And then you can use Api.read(…, page: [limit: …]) And there are helpers in AshPhoenix.LiveView to encode/decode to/from params to store pagination params in the irl **url
Ash HQ Bot
Ash HQ Bot3y ago
Ash HQ
Guide: Pagination
Read the "Pagination" guide on Ash HQ
Ash HQ
Guide: Actions
Read the "Actions" guide on Ash HQ
ZachDaniel
ZachDaniel3y ago
wanted to try out the new bot. Can you see the guides it returned? I think its visible to everyone not just me
Stefan Wintermeyer
Thank you! pagination offset?: true, keyset?: true made all the difference. It is not my call to make but I think that should be the default. I started the admin interface the first time and nothing happend. It was super sluggish. I thought it was broken. It took me a while to realize that it simply was because I was reading a table with some 40,000 entries and obviously that would become a sluggish webpage.
ZachDaniel
ZachDaniel3y ago
🤔 Yeah, I could see an argument for pagination being the default, but Ash actions are pretty generalized. Not all data layers support limits/offsets in the first place, although that can of course be simulated on top of any data layer You can also just do offset?: true depends on what you want. It probably won't change in the near future though TBH. Would break a lot of workflows if a bunch of actions all of a sudden were paginatable, mostly because ash_graphql switches on wether or not the view is paginatable to automatically change resolvers to return pages
Stefan Wintermeyer
Could a warning message in the ash_admin GUI be a help for newbies? Something like: "This table contains more than 1,000 rows. It will be slow to work with. Please consider paginating it. See https://documentation."
ZachDaniel
ZachDaniel3y ago
🤔 Yeah, I think thats a good idea Perhaps we could even just automatically limit the results to 1000 if its not paginatable and put a message at the top "only showing 1000 results, to show more, make this action paginatable" That prevents the performance issues and is informative
Stefan Wintermeyer
👍
ZachDaniel
ZachDaniel3y ago
okay, this is the behavior on main I can't do a release while ash_admin points at 1.7 rc, but once 1.7 is actually out we can release it

Did you find this page helpful?