Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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!

— asked May 25th 2010 by Curtis Olson
1 Comment
  • This thread is a mess with all the double and triple posts, and the fact that there are so many non-answer answers. Either way, gets an upvote from me as I hope this gets fixed (resolved)

    — commented June 17th 2011 by Shane Sievers

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.

    — answered February 27th 2012 by Allen Hartwig
    permalink
    1 Comment
    • My mistake. This is not working. It was an optical illusion.

      — commented February 27th 2012 by Allen Hartwig
  • 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.

    — answered May 25th 2010 by Chris Reed
    permalink
    0 Comments
  • 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?

    — answered June 2nd 2010 by Joe Maffia
    permalink
    0 Comments
  • 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?

    — answered June 2nd 2010 by Joe Maffia
    permalink
    0 Comments
  • 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?

    — answered June 2nd 2010 by Joe Maffia
    permalink
    0 Comments
  • dupe post. whoops.

    — answered August 13th 2010 by Michael Stack
    permalink
    0 Comments
  • 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.

    — answered August 13th 2010 by Michael Stack
    permalink
    0 Comments
  • I have the same problem. Is there no solution for this?

    — answered August 21st 2010 by Mario Müller
    permalink
    0 Comments
  • I have the same problem. Is there no solution for this?

    — answered August 21st 2010 by Mario Müller
    permalink
    0 Comments
  • I have the same problem. Is there no solution for this?

    — answered August 21st 2010 by Mario Müller
    permalink
    0 Comments
  • Sorry for the multipost. I got an red error message and tried it several times to post.

    — answered August 21st 2010 by Mario Müller
    permalink
    0 Comments
  • same problem with tableviewsections. any idea?

    — answered November 30th 2010 by dev 1605
    permalink
    0 Comments
  • 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?

    — answered February 9th 2011 by Patrick Ballantyne
    permalink
    4 Comments
    • Bump. Anyone? I forgot to mention that I am working with Ti 1.5.1 on Ubuntu with Android simulator APi 2.2

      — commented February 15th 2011 by Patrick Ballantyne
    • I've tried all of these on iPhone 4.3. Row height=0 works on Android. I can also set height to 1, but when I try 0 the row shows at default height.

      — commented April 21st 2011 by Joe iEntry
    • Any fresh thoughts on this issue? I'm currently circumventing the problem by moving the "hidden" rows into a separate array. Joe iEntry's "table.data[0].rows[i].height = 1;" works as well, however, I think we can agree that neither of these solutions are ideal.

      — commented May 24th 2011 by Kyle W
    • I still haven't found a better way. Another idea that is quite impractical, but perhaps will fit someone's situation, is to store the row as a variable and then delete the row. As long as you re-insert them the lower indexed row first with insertRowAfter (or before).

      — commented May 25th 2011 by Joe iEntry
  • 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

    — answered February 17th 2011 by Christoph Berger
    permalink
    1 Comment
    • @Christoph, this would work except you can't work with the child elements of the table row view after they are added this way. Unless I'm doing that wrong, too.

      Thanks

      — commented June 17th 2011 by Shane Sievers
  • Any help on this one? Setting height to 1 still shows a small row.

    — answered February 15th 2012 by Tharwat Abdul-Malik
    permalink
    0 Comments
  • 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);
    
    — answered February 27th 2012 by Allen Hartwig
    permalink
    0 Comments
  • So What is the solution to this ?????????????

    — answered April 8th 2013 by J B
    permalink
    0 Comments
  • 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];
    }
    
    — answered April 8th 2013 by J B
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.