I have trawled through the community posts but can’t find a difinitive, simple answer. How do I set-up pagination for a page resulting from a Custom Query?
I have never tried this but the answer probably lies in using the MySql LIMIT and OFFSET clauses to your custom query.
LIMIT is self explanatory and defines the number of records returned
OFFSET is the record offset for the query which is a record offset, not a page offset.
Wappler deals with page offsets so the query would need to use an offset of $_GET.limit * $_GET.offset
So your custom query would effectively need
LIMIT :P2 OFFSET :P2 * :P3
(this suggestion comes without guarantee or warranty, written or implied )
Hi Teodor, thanks for the advice and the link. I understand the theory behind LIMIT and OFFSET. I don’t understand how I can link the pagination component to a custom query in Wappler.
Just add prev/next buttons … call the server action and send the paging data via your GET vars (limit/offset).
If you want to have [1][2]…[99] buttons then you will have to make the calculations/logic for these yourself.
I will have a “play” and see what i can do when i finally finish my war with docker.
I suspect multiple queries will actually be required (based on the same inputs) , one for the data and one for the pagination
I dont think this can be generated via a query only
Not sure how we can reproduce that in total but thought perhaps if we could feed the data module via the custom query and the additional info via a separate object to “feed” the paginator
The custom query is easy and produced the correct output but without paging
Now it the time to confess JSON is not my strong point
In the latter query part the JSON does not appear correctly formed and I am struggling to resolve that
Secondly, at this stage i have no idea how to insert live values for the hard coded values when i get it right!
But it is a start.
If you have any ideas, feel free or if you./ anyone thinks this approach is a lame duck or has a better idea then I would prefer to know now than later
Alternatively there may be a way of doing this by directly manipulating the query parameters here, perhaps via the state manager (would need a custom paginator):
Just a thought here, as i don’t know what your custom query is and what are you using it for @UKRiggers
Why not create a view and do all the custom work there, then you can load this view in Wappler, create a paged query using it and generate paging?