How to update a row in TableView?

I have created a table view without problem.

For example, there are 5 rows of data like this

item 1 - good

item 2 - good

item 3 - good

item 4 - good

item 5 - good

And for some reason (e.g. a network request/response), I need to update row 3 from “item 3 - good” to

“item 3 - bad”

How do I do it?

Is it possible to update a single row?

Or I have to delete all rows and insert all of them again?

Well if you keep a reference to the objects that you put in each row and you just need to change some color or text you can do that. However if you need to change an image in the row or completely change the look of it, then you need to go another way. Either way you need to now the index of the row you want to change. What you can do to force an update of a row and get it’s onRowRender to trigger again is this:

if tableView.\_view.\_rows[rowIndex] then --check if the rows view actually exists as off screen rows get removed display.remove(tableView.\_view.\_rows[rowIndex].\_view) tableView.\_view.\_rows[rowIndex].\_view = nil tableView:reloadData() -- will call onRowRender for rows that are on or near the screen and don't have a view end

Thanks primoz.cerar

Is there any detail documentation about the code you shared?

Are _view._rows & _view._rows[xxx]._view defined by the user or Corona?

In onRowRender(), I insert display objects to “event.row”, is this _view._row[xxx]_._view ?

Yes event.row is rows _view. They are created by Corona when creating the widget, This is undocumented it is based on my examining the widget values at runtime and the widget source. As Rob Miracle pointed out in another thread any values that have an _ in front of their name are meant to be private and are subject to change in future releases. This however is unlikely to change unless they rewrite the entire code of the table view.

Thanks a lot for the clarification.

Just so you know. Widgets are open source sou you can grab the source from github and include that in your project. That will guarantee that nothing will break in the next release. You have to manually update the source code though when it is updated in the github repository if you need something new that has been added or bug fixes.

Well if you keep a reference to the objects that you put in each row and you just need to change some color or text you can do that. However if you need to change an image in the row or completely change the look of it, then you need to go another way. Either way you need to now the index of the row you want to change. What you can do to force an update of a row and get it’s onRowRender to trigger again is this:

if tableView.\_view.\_rows[rowIndex] then --check if the rows view actually exists as off screen rows get removed display.remove(tableView.\_view.\_rows[rowIndex].\_view) tableView.\_view.\_rows[rowIndex].\_view = nil tableView:reloadData() -- will call onRowRender for rows that are on or near the screen and don't have a view end

Thanks primoz.cerar

Is there any detail documentation about the code you shared?

Are _view._rows & _view._rows[xxx]._view defined by the user or Corona?

In onRowRender(), I insert display objects to “event.row”, is this _view._row[xxx]_._view ?

Yes event.row is rows _view. They are created by Corona when creating the widget, This is undocumented it is based on my examining the widget values at runtime and the widget source. As Rob Miracle pointed out in another thread any values that have an _ in front of their name are meant to be private and are subject to change in future releases. This however is unlikely to change unless they rewrite the entire code of the table view.

Thanks a lot for the clarification.

Just so you know. Widgets are open source sou you can grab the source from github and include that in your project. That will guarantee that nothing will break in the next release. You have to manually update the source code though when it is updated in the github repository if you need something new that has been added or bug fixes.