Hi All
I’m using the amazing flop/flop_phoenix libraries for pagination. I’m using liveview streams to retrieve a list of customer transactions ordered by a date field. The pagination works really well but when I create a record it gets inserted at the bottom of the current paginated list i.e. it doesn’t take account of the date entered. If I reresh the page all works well and my new record appears in the correct place.
Does anyone know if it is possible to retrieve the newly created record but in the correct place in the paginated order.
As an example. If I create a record with a date that would normally appear on Page 5 of my paginated list but I’m looking at Page 2 when I create the record I’d really like the display to update/jump to Page 5.
cheers
Dave
Hello and welcome!
Flop is very nice indeed
I also have trouble deciding on UX for this type of thing. In short, Flop isn’t going to deal with this for you (if that’s what you’re asking). While there are some tricks online, as far as I’ve ever known there isn’t any reliable way to find out what page something is on other than loading page after page until you find it (or using some trick that gets you close). Or course you can just load the IDs but if you have a ton of rows this isn’t efficient at all. If you don’t have a lot of records then you could load all the ids into a list, paginate it yourself, and find it but ya, still not ideal!
In terms of adding a record to the correct spot on the current page, all I do is reset the stream and reload the records. This is by far the path of least resistance. I’m not worried even a little bit about the performance here, especially since BEAM doesn’t need to build the entire world just to run a web request. It could cause problems if your app is highly collaborative. It could help to know more about your app but I usually just try and design the UI around these problems. I’ve even worked on a scheduling app where the list of work orders was so huge and constantly growing and changing that it didn’t even make sense to paginate it—it was search-only.
Thank you so much @|sodapopcan. I’ve been thinking about this for a few days now and coming to the same conclusion as yourself (reset the stream and relaod the records).
cheers
Dave
1 Like