I'm new to IndexedDb, I'm using it in a Windows 8 app. I'm trying to sort the results of a query by more than one index. In other words, I have an object store with objects that all have date and last name properties. I want to sort first by date, then by last name. Is there a way to do this with IndexedDB? Or will I have to sort the results of the query with JavaScript?
In indexeddb, composite index (array keyPath) is used for such multiple sorting as follow:
objectStore.createIndex('date, last', ['date', 'last']);
Unfortunately, IE10 does not support composite index.
Since IE10 doesn't support array keypaths for indexes you're going to have to do the filter yourself. If you want to hand-roll it I'd focus on creating an index on what will be your biggest key (so the one that will have the most different values) and have IDB do the query against that and then write your own filter against the rest of the items inside the onsuccess method of your cursor walking.
Alternatively you could look at a 3rd-party IDB wrapper to do it, db.js has a fluent query API which allows you to combine index queries with custom callback filtering (see here).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With