Hide tableview rows
I want to hide/show table view rows. I'm trying to somewhat recreate the filtering done by the search field on a tableview.
I also want to allow the user to pick from a list or enter a custom value text box at the top of the table view. As they type into the text box, I would like to have the textview filter rows that only match the text field.
I have everything working except I can't figure out how to use 'visible:true' on the table rows. There is a reference to it in the tableviewrow doc, but I can't figure out how to access that object from a tableview.
https://developer.appcelerator.com/apidoc/mobile/1.3/Titanium.UI.TableViewRow-object
Thanks!
18 Answers
-
I was able to make a solution in SDK 1.8.1 on iOS. By setting the height of the row to 0 and temporarily clearing the content, you are able to hide the row.
Below is a basic example of how to accomplish this. For this example, the only contents of the row is a
title
.var table = Ti.UI.createTableView(); //load up some data var data = []; for (i=0;i<10;i++){ var row = Ti.UI.createTableViewRow({ title: 'Row ' + i }); data.push(row); } table.setData(data); //custom hide/show functions table._hideRow = function(index){ table.data[0].row[index]._title = table.data[0].row[index].title; table.data[0].row[index].title=''; table.data[0].row[index].height=0; }; table._showRow = function(index){ table.data[0].row[index].title = table.data[0].row[index]._title; table.data[0].row[index].height='auto'; }; //let's hide the 6th row table._hideRow(5);
Hope this helps.
-
Hi there Curtis,
Not a direct answer to your question, but setting rowHeight to zero might be an alternative method - if all else fails.
cheers,
Chris. -
same situation here… I can set a different background colour but if I try to use "visible" or "height" nothing change!
Is this a bug?
-
same situation here… I can set a different background colour but if I try to use "visible" or "height" nothing change!
Is this a bug?
-
same situation here… I can set a different background colour but if I try to use "visible" or "height" nothing change!
Is this a bug?
-
dupe post. whoops.
-
Setting height to 0, visible to false or using .hide() does nothing to hide a row. Nothing has changed in 3 months. I would really like to be able to hide rows or insert them into sections as needed.
-
I have the same problem. Is there no solution for this?
-
I have the same problem. Is there no solution for this?
-
I have the same problem. Is there no solution for this?
-
Sorry for the multipost. I got an red error message and tried it several times to post.
-
same problem with tableviewsections. any idea?
-
Has anyone found the answer to this question? I've tried setting the following TableViewRow within the tableview.eventListener:
row.height =0;
row.visible = false;.. and I also tried:
row.hide();none of the above seem to work. Any ideas?
-
Perhaps you need to delete the row entirely, using tableView.deleteRow().
To make it visible again, create a new row, restore its content, and insert it using tableView.insertRowAfter() (or …Before()).
Just an idea. I haven't tried it myself yet.
HTH,
Christoph -
Any help on this one? Setting height to 1 still shows a small row.
-
Try this instead:
var table = Ti.UI.createTableView(); //load up some data var data = []; for (i=0;i<10;i++){ var row = Ti.UI.createTableViewRow({ title: 'Row ' + i }); data.push(row); } table.setData(data); var hiddenRows = []; //array to hold our hidden rows //custom hide/show functions table._toggleRow = function(index){ if (hiddenRows.indexOf(index)<0) { hiddenRows.push(index); //add the row to the hide array } else { hiddenRows.splice(hiddenRows.indexOf(index),1); //remove the row from the hide array } var tempData = data.splice(0); for (i in hiddenRows){ tempData.splice(i,1); } table.setData(tempData); }; table._resetRows = function(){ table.setData(data); }; //let's hide the 6th row table._toggleRow(5);
-
So What is the solution to this ?????????????
-
Ok find a way to do this. Maybe not the best in term of performance but it's working…. The idea is to listen to the change event of the table's search component. Inside the listener look the text of the search bar. If the text is empty set the data containing the rows to null.Otherwise set the data as the initial data and the search will filter the results to show :)
It's working for me like shown below. Please notice that i have 2 sections inside my tableView.
var sectionFert = Ti.UI.createTableViewSection({ headerTitle: 'Fertilizers' }); var sectionComm = Ti.UI.createTableViewSection({ headerTitle: 'Commodities' }); var sectionFert_saved; var sectionComm_saved; var search = Titanium.UI.createSearchBar({ barColor:'#aaa', showCancel:false, top:50, height:'45dp', // left:'10dp', // right:'10dp' }); var table = Ti.UI.createTableView({ data: [sectionFert_saved, sectionComm_saved], search:search, left:'10dp', right:'10dp', height:Ti.UI.FILL, separatorColor :'white', backgroundColor :'transparent', filterAttribute:'my_filter', }); search.addEventListener('change', changeListener); fillTable(); // This function just fill sectionFert and sectionComm with rows function changeListener(e) { var searchText = e.source.getValue(); Ti.API.info("searchText="+searchText); if(searchText=="") { sectionFert_saved=null; sectionComm_saved=null; } else { sectionFert_saved = sectionFert; sectionComm_saved = sectionComm; } table.data = [sectionFert_saved, sectionComm_saved]; }