0
votes

I added search icon to my tab panel which has navigationview containing searchfield in the tool bar docked top. My question is I want to getvalue from the searchfield and send it store to find the match..if there is any match I want those items to be displayed in the list below the searchfield tool bar. I did lot of search but I cant find any relevant example that helps me. Any kind of help would be appreciated.

Here is my view ..

items: [{
    xtype: 'toolbar',
    docked: 'top',
    style: 'background:darkgray',
    items: [{
            xtype: 'searchfield',
            placeHolder: 'Search... '
    }, {
            xtype: 'button',
            iconCls: 'search',
            iconMask: true,
            ui: 'confirm',
            action: 'search-app'


    }]
 }, {//here I want to show my filtered data 
    xtype: 'list',
    itemId: 'searchlist',
    store: 'SearchItemStore',
    onItemDisclosure: true,
    emptyText: 'No data found!',
    itemTpl: '{Name}'
 }]

In my controller I am calling the button and adding the function like this:

mySearchFunction: function(element , e, eOpts) { 
    var searchPattern = this.getSearchFieldAction().getValue(); 
    var store = Ext.getStore('ProductStore');
    // here I want to set the param that has to send to the store proxy..I am really not sure how this works 
    store.find(fieldName, value, [startIndex], [anyMatch], [caseSensitive], [exactMatch] ); 
}
1
Are you using MVC? If so, how are you controlling what happens when the Search button is tapped?kevhender

1 Answers

0
votes

What you are looking for is the store.filter() method.

store.filter('fieldToSearch', searchPattern);

See the docs here: http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.Store-method-filter

Another alternative is store.filterBy(), which takes a function as an argument. If the function returns true, that record is included in the filtered store. Docs: http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.Store-method-filterBy