Created
April 17, 2014 02:50
-
-
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 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The custom TableRow | |
<Alloy> | |
<TableViewRow id="row"> | |
<Label id="nameOfRow"></Label> | |
</TableViewRow> | |
</Alloy> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not working for me. :(