Delete all rows in a tableview with a single click
Hi there,
has anyone a good way to "clear" the table?
I want to build a button which deletes all my rows, so that i can add some new data in my tableview.
4 Answers
-
Accepted Answer
var rd = [];
tableView.data = rd; -
When creating you TableView, you have check something:
if you use tableView.setData() to populate you tableView, and you try to clear it with setData([]), it won't work!
//This won´t work! //Clearing the tableView with tableView.setData([]) WON'T work! var data = []; for(var i = 0; i<10; i++) { var row = Ti.UI.createTableViewRow(); data.push(row); } tableView.setData(data); //CLEARING THE TABLE //You will have to do something like this: if (tableView.data.length > 0) { for (var i = tableView.data[0].rows.length-1; i >= 0; i--) { tableView.deleteRow(i); } }
If you use tableView.appendRow() to populate you tableView, then setData([]) will work just fine!
//This will work! //Clearing the tableView with tableView.setData([]) WILL work! for(var i = 0; i<10; i++) { var row = Ti.UI.createTableViewRow(); tableView.appendRow(row); } //CLEARING THE TABLE tableView.setData([]);
-
the_table.setData([]);
does not work ?
-
I tried it with that, but it has no effect to my Table,still all entrys are in it.