TableView > Enable EDIT Mode and SELECT multiple rows
I'm looking to do something similar to what you see in MAIL where you click EDIT and little circles appear on left side. Then you can select multiple rows and run an action on those rows (delete, move, etc) from a menu at the bottom.
I know there's EDIT which causes DELETE buttons to appear on the left side to delete one row, but what I want is to be able to select multiple rows and run a function on click of a toolbar button.
Does that exist in the API in some way or do I have to build this stuff manually (yikes!)
thanks
Fish
3 Answers
-
Has anyone found a way to do this? I see there's a listing in the bug/feature tracker for something like this. But its not scheduled to be worked on.
https://appcelerator.lighthouseapp.com/projects/32238/tickets/842-create-table-view-options-api
-
You could do something along the lines of:
- add a boolean variable to each row, such as
row.isSelected
- add an 'edit' or 'select multiple rows' button on the title bar (or wherever)
- create an eventListener on the table that listens for taps on rows and sets that variable to true if selected (if the edit button is active)
tableView.addEventListener('click', function(e)
- push all "selected" rows into an array
if (e.rowData.isSelected) { someArray.push(e.row) //push row into an array
- do what you want with the rows in the array
Of course, that's not the most elegant way of putting it, but I hope the logic is clear. :)
- add a boolean variable to each row, such as
-
Anyone know why this doesn't work as expected:
tableview.addEventListener('click',function(e){ Ti.API.log('e.row.bool_selected',e.row.bool_selected); e.row.bool_selected = e.row.bool_selected ? 0 : 1; e.row.indicator.backgroundColor = (e.row.bool_selected ? '#0F0' : '#F00'); Ti.API.log('e.row.bool_selected',e.row.bool_selected); });
The logs come out as expected and the indicator (a simple square view at the moment) does toggle between green and red but if it toggles to green and then I click another row the one that was green toggles back to red?
I also tried e.rowData.bool_selected but had same result.Is there a setting for tableViews to enable multiple selection its acting as if you can only ever select one at a time