Custom search result table view.
I generate a table with this piece of code, but when i search thru it with a searchbar it doens't give any results.
Any help on how to resolve this AND style the search result table view?
var data = [];
for (var x=0;x<40;x++)
{
var image = Titanium.UI.createImageView({
url:'../../assets/icons/building.png',
left:'5',
width:'54', height:'53'
});
var name = Ti.UI.createLabel({
text:'Abdijmuseum',
color: "#38bad9",
font:{fontSize:16,fontWeight:'bold'},
width:'230',
left:65,
top:-15
});
var distance = Ti.UI.createLabel({
text:'120 km',
width:'auto',
color:'#666666',
font:{fontSize:12},
left:65,
top:20
});
var rightButton = Titanium.UI.createButton({
backgroundImage: '../../assets/icons/arrow_right.png',
width:9,
height: 14,
right:10
});
rightButton.addEventListener('click',function(e)
{
//Ti.API.info("button click on row. index = "+e.index+", row = "+e.source.row+", section = "+e.source.section+",rightButton = "+rightButton);
});
var row = Ti.UI.createTableViewRow({
height:'auto',
selectedBackgroundColor: 'white',
color:"white",
widgetname:'xxxxx', // acts as search key
backgroundImage:'../../assets/icons/rowbg.png',
visible:false
});
row.add(image);
row.add(name);
row.add(distance);
row.add(rightButton);
row.widgetname = 'xxxxx';
data[x] = row;
row.addEventListener('click',function(e)
{
//Ti.API.info("row click on row. index = "+e.index+", row = "+e.row+", section = "+e.section+", source="+e.source);
});
}
var search = Titanium.UI.createSearchBar({
showCancel: true,
barColor: '#4ec4de',
filterAttribute: 'widgetname'
});
// create table view
var tableview = Titanium.UI.createTableView({
data:data,
//style: Titanium.UI.iPhone.TableViewStyle.GROUPED,
//separatorStyle:Ti.UI.iPhone.TableViewSeparatorStyle.NONE,
//rowHeight:80,
minRowHeight:55,
search:search
//maxRowHeight:500,
});
/*
// create table view event listener
tableview.addEventListener('click', function(e)
{
Ti.API.info("row click on table view. index = "+e.index+", row = "+e.row+", section = "+e.section+", source="+e.source);
// event data
var index = e.index;
var section = e.section;
var row = e.row;
var rowdata = e.rowData;
Titanium.UI.createAlertDialog({title:'Table View',message:'row ' + row + ' index ' + index + ' section ' + section + ' row data ' + rowdata}).show();
});
*/
// add table view to the window
Titanium.UI.currentWindow.add(tableview);
5 Answers
-
Your table view should look like this, if you want to search widget
// create table view var tableview = Titanium.UI.createTableView({ data:data, //style: Titanium.UI.iPhone.TableViewStyle.GROUPED, //separatorStyle:Ti.UI.iPhone.TableViewSeparatorStyle.NONE, //rowHeight:80, minRowHeight:55, search:search //maxRowHeight:500, filterAttribute:'widgetname' });
Note the
filterAttribute
I've addedHope this helps
-
Hi there,
Can't be done. All you can do is set the 'title' field (for the row) to the text you want displayed in the results view.
Chris.
-
If i set the title you will see on this screenshot the background is not ok.
http://dl.dropbox.com/u/26043/screenshots/Schermafbeelding%202010-06-20%20om%2015.50.28.png
with this piece of code
var row = Ti.UI.createTableViewRow({ height:'auto', selectedBackgroundColor: 'white', color:"transparent", title:'title', // acts as search key backgroundImage:'../../assets/icons/rowbg.png', visible:false });
-
Add the "selectedColor" attribute to your row.. this will hide the text in both normal and selected states… works for me with a backgroundColor and selectedBackgroundColor.. haven't tried it with a backgroundImage on the row yet.
Then you can search away!
var row = Ti.UI.createTableViewRow({ color: 'transparent', selectedColor: 'transparent' });
-
Complementing the first post, the error is in the placement of 'filterAttribute'
The correct way is:
var search = Titanium.UI.createSearchBar({ showCancel: true, barColor: '#4ec4de', }); var tableview = Titanium.UI.createTableView({ data:data, //style: Titanium.UI.iPhone.TableViewStyle.GROUPED, //separatorStyle:Ti.UI.iPhone.TableViewSeparatorStyle.NONE, //rowHeight:80, minRowHeight:55, search:search filterAttribute: 'widgetname', //maxRowHeight:500, });
But I think that only works on iOS.
In Android could not make it work!!I opened a review in Appcelerator Jira for this case…