Titanium Community Questions & Answer Archive

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

To know the number of search results

Is it possible to know the number of rows in the tableview of a search result ?

— asked September 20th 2010 by Yannis Sgarra
  • search
  • searchbar
  • tableview
0 Comments

5 Answers

  • Unless you want to modify the Titanium source code, I think at present all you can do is manually count the rows from the original table view which match the search criteria.

    Alternatively, you could disengage the search bar from the table view and implement your own search function which shows the relevant results in the table view and counts them at the same time. That may not fit with your current design though.

    — answered September 21st 2010 by James K
    permalink
    0 Comments
  • Not sure how you're returning your results but maybe you could increment a 'counter' variable if you use a loop to create a tableview of results??

    — answered September 23rd 2010 by Kelly Redd
    permalink
    0 Comments
  • increament a counter value when u add a tableview row i.e., row.add(something)
    i mean keep this in a loop with a counter value increament

    — answered September 24th 2010 by Varun Atluri
    permalink
    0 Comments
  • I agree with James K I implemented my own search function a here is the code

    // array of the data
    var data = [] ;

    // table view
    var tableview = Ti.UI.createTableView({
    data : data
    });

    // Search bar
    var searchBar = Titanium.UI.createSearchBar({
    showCancel: true,
    top: 0
    });

    // result number
    var resultsNumber = Ti.UI.createLabel({
    backgroundGradient: {
    type: 'linear',
    colors: ['#919faa', '#bac3cb'],
    startPoint: {
    x: 0,
    y: 0
    },
    endPoint: {
    x: 'auto',
    y: 'auto'
    },
    backFillStart: true
    },
    color: '#FFF',
    height: 20,
    top: 43
    });

    currentWind.add(searchBar);
    currentWind.add(resultsNumber);
    searchBar.hide();
    resultsNumber.hide();

    // Event of the search

    var right_exist = true;
    right_nav.addEventListener('click',function(e) {

        if (right_exist) {
            currentWind.hideNavBar();
            tableview.top = 60;
            searchBar.show();
            resultsNumber.show();
            right_exist = false;
        }
        searchBar.addEventListener('change',function(evt) {
            var data1 = [];
            var x = 0;
            for (var c = 0 ; c < data.length ; c++) {
                if ( data[c].text.search(/evt.value/i) != -1) {
                       data1[x] = data[c];
                       x++;
                }
            }
            tableview.setData(data1);
            resultsNumber.text = ' ' + data1.length + " result(s) found";
        });
        searchBar.addEventListener('cancel',
        function(ev) {
            searchBar.hide();
            searchBar.blur();
            resultsNumber.hide();
            currentWind.showNavBar();    
            tableview.top = 0;
            right_exist = true;
        });
    }
    

    });

    And I works perfectly

    — answered October 14th 2010 by Ahmed Hammami
    permalink
    0 Comments
  • I will check this out. Really this search feature. Thanks. The code doesn't seem to run. as you typed it here though.

    — answered October 1st 2011 by Leonardo Amigoni
    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.