To know the number of search results
Is it possible to know the number of rows in the tableview of a search result ?
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.
-
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??
-
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 -
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
-
I will check this out. Really this search feature. Thanks. The code doesn't seem to run. as you typed it here though.