I had the same problem, and cursor.advance(40) is what you want to use.
One thing that took me a while to figure this out can be useful for others, if you want to move the cursor and openCursor().onsuccess over the results, you will need to call them in separate openCursor().onsuccess or implement some kind of tracking to both of them were thrown in one request or an InvalidStateError exception which should be thrown. This can be done like this:
Individual handlers
// advance first store.openCursor().onsuccess = function(event) { var cursor = event.target.result; cursor.advance(40); }; // then iterate objectStore.openCursor().onsuccess = function(event) { var cursor = event.target.result; cursor.continue(); });
Same handler
// create flag for advancing var advancing = true; store.openCursor().onsuccess = function(event) { var cursor = event.target.result; // advancing if (advancing === true) { cursor.advance(40); // set advancing flag to false so we don't advance again advancing = false; } // continuing else { cursor.continue(); } }
Specification: http://www.w3.org/TR/IndexedDB/#widl-IDBCursor-advance-void-unsigned-long-count MDN reference with an example: https://developer.mozilla.org/en-US/docs /Web/API/IDBCursor.advance
Pete newnham
source share