Need help with paginating data in weblistbox

Hello,
Up until recently I didn’t need it, but now I think I do and I don’t seem to get a handle of how to do it.
Basically, I am receiving lot’s of data entries from a database (sql queries in code) and want to present them paginated in a weblistbox. What’s the most basic way of achieving this?
Thank you!

I would say that you can create a specific function like

GetPageOfWhatever(pageNumber As Integer, itemsPerPage As Integer = 10) As RowSet

Returns Nil if such page contains 0 items

Create navigational buttons, request the page number x+1 or x-1, and populate the page accordingly.

Internally you make the appropriate SELECT to retrieve that specific block of itemsPerPage rows.

The simplistic way of retrieving a block of rows is using the LIMIT SQL clause where you can specify the number of rows to return + offset.

But YOU can design a more elaborated and performant query replacement later and update your function.

The answer depends largely on whether you are using web 1 or web 2.

Using the older web 1 framework, you’d do just what Rick suggests.

Using web 2 however is a little trickier. There, The WebListBox is already lazy loading the data, that is, loading only a little of the data at a time. If you are simply using AddRow though, the framework is creating an in-memory SQLite database to hold the data. It would be better to set up a DataSource and pull the records yourself when they are requested.

Paginated like this?

1 Like

Yup. That’s the one. Didn’t think of search, but now that I see it there, makes sense… :))

web 2

I understand that Xojo Web 2 Weblistbox is based on Datatables (the screenshot I posted), I don’t think that pagination is available in Xojo, @Greg_O may know more about this and tell us if a Feature Request is possible to have that pagination option (for @Ricardo_Cruz to implement).

That can be a problem for, I don’t know, 1,000,000+ rows? That’s why people use paging in some contexts, to avoid massive data transfers at once and memory hog/overflow.

Also, large data browsing use dynamic loading, when just a small set of a rowset is loaded to fulfill the current view, the selection behind just holds the intended IDs, request a block, pot into view, discard when out of view.

hmm… so no one does pagination in web 2?

yes, I am using AddRow… is there a way to access the in-memory sqlite database? to perform searches for example?

That pagination, no.

We try not to have Weblistbox with thousand of results, and if we do, we use DataSource.

No. It’s not very user friendly in any case. It has lots of extra metadata to make it work.

You can however set the SearchCriteria property to have it do a full text search on the contents.

the table is too buggy. But you can make your own using containers for the rows. Not the easiest way, but you can get better results. Once you have the custom table, you can use the LIMIT and OFFSET clause to get the paginated data.

1 Like

Got it. Thanks.

I remember at some point in a previous version, searchcriteria didn’t worked for me. time to try it again. Thanks.

I was afraid of this solution, but sounds to be what I have to do. Thank you.