🖥 TECH >> Applying pagination in IndexedDB data read
Oct 1, 2021
Data can be read in a paginated form from IDB using IDB cursors. One can leverage the advance()
of IDBCursor
to efficiently advance to the page indices. Here’s the sample code.
For a startIndex(10)
and stopIndex(25)
, the code will return data from the store starting from key index 10 to 25. Note that for the very beginning, i.e for startIndex = 1
, no cursor advancement is made.
cursor.advance(startIndex — 1 );
Since, the cursor initially points to the first element, the advanced index is reduced by 1 for arithmetic equality.