Details
Description
Setting Titanium.UI.SearchBar value after creating tableview (or listview) is not reflecting in search results.
Use the following code
var fruits = [ {title: 'Apples'}, {title: 'Bananas'}, {title: 'Strawberry'}, {title: 'Pineapple'},{title: 'Apples'}, {title: 'Bananas'}, {title: 'Strawberry'}, {title: 'Pineapple'}, {title: 'Apples'}, {title: 'Bananas'}, {title: 'Strawberry'}, {title: 'Pineapple'},{title: 'Apples'}, {title: 'Bananas'}, {title: 'Strawberry'}, {title: 'Pineapple'}, {title: 'Apples'}, {title: 'Bananas'}, {title: 'Strawberry'}, {title: 'Pineapple'},{title: 'Apples'}, {title: 'Bananas'}, {title: 'Strawberry'}, {title: 'Pineapple'}, {title: 'Apples'}, {title: 'Bananas'}, {title: 'Strawberry'}, {title: 'Pineapple'},{title: 'Apples'}, {title: 'Bananas'}, {title: 'Strawberry'}, {title: 'Pineapple'} ];
|
|
var sampleWindow = Ti.UI.createWindow();
|
var navWindow = Ti.UI.iOS.createNavigationWindow({
|
window: sampleWindow
|
});
|
|
var search = Ti.UI.createSearchBar({hintText: "search by name", showCancel: true});
|
search.addEventListener("return", searchBarReturn);
|
|
var tableView = Ti.UI.createTableView();
|
tableView.addEventListener("click", tableClicked);
|
|
tableView.search = search;
|
tableView.searchHidden = true;
|
tableView.filterAttribute = 'customAttr';
|
|
sampleWindow.add(tableView);
|
|
fillTableData(fruits);
|
|
function fillTableData(_data){
|
var tempData = [];
|
for(var i=0, j=_data.length;i<j;i++){
|
var row = Ti.UI.createTableViewRow({
|
height: 40,
|
backgroundColor: "#fff",
|
customAttr: _data[i].title
|
});
|
|
row.add(Ti.UI.createLabel({
|
left:'5%',
|
width:'90%',
|
height:'100%',
|
text: _data[i].title
|
}));
|
|
tempData.push(row);
|
}
|
tableView.setData(tempData);
|
}
|
|
function tableClicked(){
|
Ti.API.warn("table clicked!");
|
}
|
|
function searchBarReturn(){
|
search.blur();
|
}
|
|
|
navWindow.addEventListener('open', function() {
|
search.value = 'App';
|
});
|
|
navWindow.open();
|
Actual: All items are shown irrespective of setting search string.
Expected: Items should be filtered as per search string.