Skip to content

Instantly share code, notes, and snippets.

@casevictor
Created April 17, 2014 02:50
Show Gist options
  • Save casevictor/10949598 to your computer and use it in GitHub Desktop.
Save casevictor/10949598 to your computer and use it in GitHub Desktop.
A way to implement Titanium.UI.SearchBar with custom UI.tableRows using Alloy ( Android and iOS platforms )
//On iOS the default is 'Search', On Android the default is empty
$.search.hintText = 'Deep Search'
if(OS_IOS){
//Equals to tableRow.js new property
$.table.filterAttribute="filter";
}
if(OS_ANDROID){
//Android only works with title :(
$.table.filterAttribute="title";
//Pasted from API documentation
$.table.addEventListener('click', function(){
$.search.value = "";
$.search.hide();
$.search.show();
});
}
// A simple Window with one TableView that contains a SearchBar
<Alloy>
<Window id="tableWin">
<TableView id="table" separatorColor='silver'>
<SearchBar id="search"></SearchBar>
</TableView>
</Window>
</Alloy>
//Variable received by createController(...)
var name = arguments[0] || {};
//On Android the SearchBar only looks to the title property
if(OS_ANDROID){
$.row.title = name;
}
//On iOS the SearchBar accepts customs properties, for instance we named 'filter'
if(OS_IOS){
$.row.filter = name;
}
$.nameOfRow = name;
// The custom TableRow
<Alloy>
<TableViewRow id="row">
<Label id="nameOfRow"></Label>
</TableViewRow>
</Alloy>
@madushan1026
Copy link

This is not working for me. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment