Would someone be willing to show a working example of this…?
I’m about to hit the sack, but I can point you at my “Table” custom component, and how it does pagination: Building a rich table as a custom component
Specifically, when pagination is enabled, it sets up an iterator and stores it:
self._data_iter = iter(self._data)
When it wants to display data, it then repeatedly pulls elements out of this iterator into its list of realised rows (aka self._data_seen
):
seen_len = len(self._data_seen)
if seen_len < self._page_start + self._page_len and seen_len < self._data_len:
# We need to realise more from the iterator
try:
while seen_len < self._page_start + self._page_len:
self._data_seen.append(self._data_iter.next())
except StopIteration:
self._data_len = len(self._data_seen)
But it only does this bit-by-bit, when you hit the “Next” button. So you can have a table displaying “Rows 1-10 of 100000”, and its only loaded those ten rows from the iterator. When you hit the “next page” button, it will load the next 10 rows from the iterator, so now self._data_seen
has 20 rows in it.
(Apologies for that code, btw - I would write it a lot more clearly if I were doing it today.)