Need help with Custom Query Pagination

Problem is that you don’t have any of this, as you do in a paged query

image

Maybe check some article of how offset/limit work for mysql. Example
https://www.sqlshack.com/learn-mysql-what-is-pagination/

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.

Well the pagination generator component expects a paged query. You should create a custom paging for your custom query.

Can you give a bit more detail, @Teodor?

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.

OK. I was hoping there was a Wappler way of achieving it so it behaves like the paged query does.

Is this worth a feature request?

Well as it’s a custom query we don’t know what to expect from it :slight_smile: You just need to se it up as per your query results.

I was hoping that if the convention was stuck to in the custom query (limit and offset) then the visual elements could still work within Wappler?

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

Hi Brian, don’t suppose you have managed to win the war and so get chance to look at this little problem have you?

Sorry mate, family stuff got in the way but i will get onto it asap, maybe this evening

No problem, any help is much appreciated :slight_smile:

Have to call it a night Neil but thought i would share my thought process in case it helps, maybe a few other members may wish to chirp in

The paged query returns a number of additional information which is not included in the standard query

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

So i have the idea of creating a custom object within a set value like below to duplicate the required data

and populate it with the required JSON (hard coded values at this stage for testing)

image

At present i have an output of:

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 :slight_smile:

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):

image

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?

2 Likes

Thanks for your efforts so far Brian. Great progress. Hopefully others can contribute.

Interesting approach and sounds logical. I’ll have a go at that later tomorrow. Cheers

That is an excellent idea. I keep overlooking views but when I use them I wonder why I don’t use them more often!

1 Like

May be obvious, but if you’re new to views, I’d recommend prefixing the name with something like ‘view_’ to differentiate them easily in lists.

1 Like

Or you can go berserk and build a custom module.