I'm using the Dexie database. To add to the end of the table:
tabs.add({}, tabs.getIndex(tabs.getSelected()) + 1)
How to add an item to the top of the table?
I tried these options:
tabs.add({}, 0)
tabs.add({})
tabs.put({})
I'm using the Dexie database. To add to the end of the table:
tabs.add({}, tabs.getIndex(tabs.getSelected()) + 1)
How to add an item to the top of the table?
I tried these options:
tabs.add({}, 0)
tabs.add({})
tabs.put({})
Sami,
One way to get an ordered list of items out of a Dexie table would be to use sortBy()
Here is an example using an imaginary table called messages that has two fields - name and date:
db.messages
.where('name')
.equals('fred')
.sortBy('date').then(function(returnedMessages) {
for (i = 0; i < returnedMessages.length; i++) {
console.log(returnedMessages[i].date);
}
});
If you want to reverse the sort use reverse() :
db.messages
.where('name')
.equals('fred')
.reverse()
.sortBy('date').then(function(returnedMessages) {
for (i = 0; i < returnedMessages.length; i++) {
console.log(returnedMessages[i].date);
}
});
Hope that helps!
For reference, here are the two documentation pages I sourced for this information:
http://dexie.org/docs/Collection/Collection.sortBy()
http://dexie.org/docs/Table/Table.reverse().html
Frank