evrencoskun / TableView

TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
MIT License
3.14k stars 459 forks source link

Columns: can't refresh column headers #140

Closed raucascrokkia closed 6 years ago

raucascrokkia commented 6 years ago

Hi evrencoskun, First of all, thanks for your work and support.

i've created a simple app that reflects exactly a table on db. So, imagine you have a table with columns A,B,C and 2 rows. TableView is created on it and on first load shows exactly what has to do. Then, I add a new row (with empty cells) by Custom Dialog. Row is inserted in table on db, then i call mTableViewAdapter.setAllItems and TableView reflects the modify. I see one more row with all empty cells. Awesome. Now, i add a new column D by Custom Dialog. Column is created in table on db (i see it), then i recall mTableViewAdapter.setAllItems and TableView does NOT reflect the modify. I see the same columns A,B,C. I have to close and reopen App for seeing D column too. I don't understand why. Is it a bug ?

tuvirus commented 6 years ago

Hello @raucascrokkia ,

As i think, what you're trying to achieve is to update the the table in realtime. Since on the activity is not in an actual loop or inside a for to update it, you wont see the column D because it doesn't exist in the actual context (even if you added on db). Because it need to rebuild the whole table again. So you invalidate the activity, means to reload therefore will rebuild with the new column but rebuild the whole activity looks bad for user. Another workaround is to setup a listener so it can update your view, set the new column D and set all items again. Which the tableview has listeners to refresh thought, must have a notifyDataSetChanged. I assume on your custom dialog you call a method to insert data to db, call a method to rebuild your table.

raucascrokkia commented 6 years ago

Thanks for reply @tuvirus , Exactly, i'm trying to manipulate a table on db and i am using this tableView like user interface. I remove a column on tableView, i remove a column on db. I remove a row on tableView, i remove a row on db. I thought that just by call setAllItems method passing it refreshed items list everytime, i could refresh the entire tableView: mTableViewAdapter.setAllItems( TableDb.getColumnHeaderList(), TableDb.getRowHeaderList(), TableDb.getCellList());

Now i changed the approach. When i remove a column from tableView, i remove it by removeColumn method and then i remove it on db too. Same for row. I have to do 2 step for each function (add/remove column/row)

raucascrokkia commented 6 years ago

My mistake. When i add or remove a column from db, i do not close connection on it. So, on db, the change is active (when i download db file and navigate it, all is correct, i do not see removed column for example), but, when i use Cursor for reading table, it's like it reads from a previous table snapshot. I don't know how it works exactly. Despite i begin a transaction, for alter table and drop a column, despite i call commit at the end of it, anyway Cursor reads old columns.

Instead, if i reads table info by

pragma table_info(table_name)

i don't see dropped column as expected.

By the way, now it works like a charm. Thanks for your support.