PDA

View Full Version : problem while implementing free text search in sencha search field.



arihant0073
27 Nov 2011, 3:10 AM
Hi,
i am trying to search in a list using searchfield. i have written code as below.
-----------------------------------------------------------------------------


ListDemo.searchPanel = new Ext.Panel (
{
layout: 'fit',
floating: true,
width: '40%',
height: '100%',
dockedItems :
[
{
xtype: 'toolbar',
ui: 'light',
dock: 'top',
items: [
{
id: 'searchField',
xtype: 'searchfield',
placeHolder: 'Search',
name: 'searchField',
showClear: true,
listeners: {

keyup: function()
{

var searchTerm = this.getValue();

if (searchTerm) {

ListDemo.ListStore.filterBy(function(record){
var fieldDataFirst = record.data.RequestNo.toLowerCase().indexOf(searchTerm.toLowerCase())
var fieldDataLast = record.data.Priority.toLowerCase().indexOf(searchTerm.toLowerCase());
var fieldDataTrans = record.data.TransactionID.toLowerCase().indexOf(searchTerm.toLowerCase());
var fieldDataDesc = record.data.Description.toLowerCase().indexOf(searchTerm.toLowerCase());


if (fieldDataFirst > -1 || fieldDataLast > -1 || fieldDataTrans > -1 || fieldDataDesc > -1)

return record;
});
}
else {
ListDemo.ListStore.clearFilter();

}
}


} // listener


-------------------------------------------------------------------------------------------
first of all, i am not able to set the value of this searchfield outside its listener.
The main problem i have is, i have grouped items of this list as per alphabets.
When i scroll down to group 'M' and search something which is there in group 'D', it shows me a blank screen. it doesnt automatically focus to the required field. what can be done in this case?

mitchellsimoens
27 Nov 2011, 7:20 AM
I would use RegEx for the filtering.