tableview Rendering order

Hi,

I am dealing with my first tableview displaying a list of user generated data. This data get saved on a sqlite table.

Everything so far is saved and rendered pretty well. But since I’m new both to sqlite and corona I’m not able to get the indexing properly in order to get the newest row added on top of list instead of at the bottom.

Here’s how I set the sqlite table:

local path = system.pathForFile("db.sqlite", system.DocumentsDirectory);     local db = sqlite.open(path);     db:exec("CREATE TABLE IF NOT EXISTS info (id integer PRIMARY KEY, name text, data integer, datetime text);")

Every new entry in the table get index by increment of +1. So by setting it like this when I load this sqlite table on my tableview the latter entry gets diplayed at the bottom of the list and the first on the first row, while I’d obviously would like to have the order of rows/items reverted.

How do I logically proceed to do that??

Thank you…

Really no help???

This seems to me to be something obvious I am missing. Every tableview I have seen in apps that take and save user generated data displays the freshest input on the top row and going down you have the older entries in chronological input order…

Is that difficult to logically have a method to do that? Please help me…

maybe just need a “ORDER BY id DESC” in your sql

worked!!!

Magic. Thanks a lot @davebollinger!!!

Only one more doubt: now when I load from the sqlite file the tableview displays rows in the proper chronological order, but since my data is user-generated (input through a textfield) when I input a new entry the new row in question gets sent at the bottom of the list. This seems to me, but I’m not sure, related to the corona widget end of the process. Any idea on how to make newly generated rows (on scene) to be placed at the top of the tableview??

Thanks again, great help!!!

caveat:  i don’t use tableview any more (use my own instead) so am a a bit rusty.  and i don’t know what might have been fixed since, but i had problems with “dynamic” rows too.  (a common “symptom” that something went wrong was messed up category row rendering)  i’d always end up calling :deleteAllRows() and rebuilding the entire thing from scratch.  maybe someone who’s more current w tableview could offer a better suggestion.  hth

aaaaaaand that worked too!!!

placed in the right position in the code and followed with a proper re-render I’m getting the effect I need!

…at least so far in the testing process, in fact it seems pretty much of a clunky approach to the whole already-complicated tableview handling… so if anyone has a better system he/she wants to share that would be great!

Anyway @davebollinger you helped a great deal. Immense thanks to you, man !

The tableView is nothing more than a set of display groups that show in order.  You decided what order the tableView’s rows are populated in and it’s up to you to have your data sorted before you insert them into the tableView.  The tableView is not designed to be your actual data.

There is a function called table.sort() (http://docs.coronalabs.com/api/library/table/sort.html) that can be used to sort your in-memory data table and then you can load your tableView by looping over the table in order.

Rob

Really no help???

This seems to me to be something obvious I am missing. Every tableview I have seen in apps that take and save user generated data displays the freshest input on the top row and going down you have the older entries in chronological input order…

Is that difficult to logically have a method to do that? Please help me…

maybe just need a “ORDER BY id DESC” in your sql

worked!!!

Magic. Thanks a lot @davebollinger!!!

Only one more doubt: now when I load from the sqlite file the tableview displays rows in the proper chronological order, but since my data is user-generated (input through a textfield) when I input a new entry the new row in question gets sent at the bottom of the list. This seems to me, but I’m not sure, related to the corona widget end of the process. Any idea on how to make newly generated rows (on scene) to be placed at the top of the tableview??

Thanks again, great help!!!

caveat:  i don’t use tableview any more (use my own instead) so am a a bit rusty.  and i don’t know what might have been fixed since, but i had problems with “dynamic” rows too.  (a common “symptom” that something went wrong was messed up category row rendering)  i’d always end up calling :deleteAllRows() and rebuilding the entire thing from scratch.  maybe someone who’s more current w tableview could offer a better suggestion.  hth

aaaaaaand that worked too!!!

placed in the right position in the code and followed with a proper re-render I’m getting the effect I need!

…at least so far in the testing process, in fact it seems pretty much of a clunky approach to the whole already-complicated tableview handling… so if anyone has a better system he/she wants to share that would be great!

Anyway @davebollinger you helped a great deal. Immense thanks to you, man !

The tableView is nothing more than a set of display groups that show in order.  You decided what order the tableView’s rows are populated in and it’s up to you to have your data sorted before you insert them into the tableView.  The tableView is not designed to be your actual data.

There is a function called table.sort() (http://docs.coronalabs.com/api/library/table/sort.html) that can be used to sort your in-memory data table and then you can load your tableView by looping over the table in order.

Rob