View Full Version : Using filter method from Data Store

8 Oct 2012, 8:07 AM
Good morning everyone!

I have this piece of code to filter some json results retrieved from a database

xtype: 'button',
text: 'Pesquisar',
renderTo: 'alunos',
handler: function(){
load.filter('name', Ext.getCmp("nomeAluno").getValue() , true, false );

I use this in a search field. The problem?
Let's say I want to find everyone named 'Bruno' on my database, I type 'Bruno' on the textfield, click on search and I will get a lot of Brunos

Bruno Miranda
Bruno Fonseca

BUT if I search for Miranda, it won't return the first Bruno. It only looks up the first word of every record, but I'd like it to match "Bruno Miranda" too, if I search for "Miranda"

Does anyone have a suggestion?
Thanks in advance!

8 Oct 2012, 11:05 AM

First of all, do not forget to set the remoteFilter config in your store to true.

Second, to list all the matches from the database depends on how you are hadling the search on the server side; in your sql query.

If you are doing
WHERE name = 'Bruno'

it is only going to retrieve the Brunos.

If you use
WHERE name LIKE '%Miranda%'

it is going to retrieve all the records that have 'Miranda' in it.

Hope it helped!

8 Oct 2012, 12:35 PM
Thanks for the reply!
I think I didn't explain myself properly.

This application consist in a system to record students frequency, I retrieve all students from database once, so the operator will lookup for the students among that set of data. I think this approach is better because I want to avoid doing lots of querys, I think it should be enough to just filter the records each time the operator search for a student name (this way is super fast!).

So, is it possible to do this way? If I had to do remote querys all the time, it would be daam slow..

Thanks Loiane (I'm a big fan of your work :)) )

8 Oct 2012, 1:09 PM

I got you now!

The filter method from Store accepts an object called Ext.util.Filter.

So you can do like this:

store.filter([Ext.create.('Ext.util.Filter', {property: 'name', value: 'some value', anyMatch: true})]);

And with the config anyMatch, it will return what you are looking for. :)

9 Oct 2012, 11:06 AM
Thanks but it still not working, I got a blank response as result of using this

handler: function(){ load.clearFilter(); load.filter([Ext.create('Ext.util.Filter', {property: 'name', value: Ext.getCmp("nomeAluno").getValue(), anyMatch: true})]); } }

and this way, filter doesn't work at all.

I'm still trying, but if someone find out a solution, I'd be grateful to see!

9 Oct 2012, 12:34 PM
Just got it working!

handler: function(){
property: 'name',
value: Ext.getCmp('nomeAluno').getValue(),
anyMatch: true,
caseSensitive: false

I don't know why it doesn't work with Ext.create inside but it's working very well now.
Thanks for the help.

2 Apr 2013, 5:43 AM
I have a datagrid and a textfield on top of grid

If i type something in textbox it should basically match in all columns and display the result.
Right now I am using the below code by using filterby method to filter a record based on single column

var searchvalue = text.getValue();
var name= record.data.firstname;
if(name.indexOf(value.toLowerCase()) == 0){
return true;
return false;

Please help me as my grid has many columns and i want to search in all the columns and return if any1 is matched
I saw the above approach of filter method, but can you post some code on how to apply to my code via using filter method.

2 Apr 2013, 6:32 AM
One way to my above code is i write multiple if condition

if(record.data.firstName == searchValue || record.data.lastName==searchValue)
return true;
return false;

But I want a generic search where I use the same thing for different grid and it will take care of finding the column name and return the filtered record