Skip to content Skip to sidebar Skip to footer

Unexpected Behavior Sorting By Number/date In Indexeddb

For my databse i've created an index called time on created_at: var os = thisDB.createObjectStore(name, { keyPath : 'id' }); os.createIndex('time', 'created_at', {unique: false })

Solution 1:

You can sort ascending/descending in the openCursor function by giving it the second parameter: index.openCursor(undefined, "next"); or "prev" for descending.

Sorting should work on the index, also when you do not provide a next or prev (next is default). When you call openCursor on the index, it loops them in the same way chrome-dev-tools shows them when clicking the "time" index in the debugger.

Are you using the shim by any chance (maybe for iOS/android)? (https://github.com/axemclion/IndexedDBShim), because it is a known issue sorting doesn't really work there. If you aren't sure then I guess this paragraph doesn't apply to you..

EDIT You are problably not using the shim because I see a screenshot of the indexedDb from chrome dev-tools, wich you could not have done when using the shim as it uses a different storage mechanism).

Post a Comment for "Unexpected Behavior Sorting By Number/date In Indexeddb"