-
8 Oct 2012 8:07 AM #1
Unanswered: Using filter method from Data Store
Unanswered: Using filter method from Data Store
Good morning everyone!
I have this piece of code to filter some json results retrieved from a database
Code:{ xtype: 'button', text: 'Pesquisar', renderTo: 'alunos', handler: function(){ load.clearFilter(); 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
Etc...
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 #2
Hi,
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!Sencha/Java evangelist
Author of ExtJS 4 First Look and Mastering Ext JS books
English blog: http://loianegroner.com
Portuguese blog: http://loiane.com
Sencha Examples: https://github.com/loiane
-
8 Oct 2012 12:35 PM #3
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 #4
Thanks!
I got you now!
The filter method from Store accepts an object called Ext.util.Filter.
So you can do like this:
And with the config anyMatch, it will return what you are looking for.PHP Code:store.filter([Ext.create.('Ext.util.Filter', {property: 'name', value: 'some value', anyMatch: true})]);
Sencha/Java evangelist
Author of ExtJS 4 First Look and Mastering Ext JS books
English blog: http://loianegroner.com
Portuguese blog: http://loiane.com
Sencha Examples: https://github.com/loiane
-
9 Oct 2012 11:06 AM #5
Thanks but it still not working, I got a blank response as result of using this
and this way, filter doesn't work at all.PHP Code:handler: function(){ load.clearFilter(); load.filter([Ext.create('Ext.util.Filter', {property: 'name', value: Ext.getCmp("nomeAluno").getValue(), anyMatch: true})]); } }
I'm still trying, but if someone find out a solution, I'd be grateful to see!
-
9 Oct 2012 12:34 PM #6
GOT IT
GOT IT
Just got it working!
I don't know why it doesn't work with Ext.create inside but it's working very well now.Code:handler: function(){ load.clearFilter(); load.filter([ { property: 'name', value: Ext.getCmp('nomeAluno').getValue(), anyMatch: true, caseSensitive: false }]); } }
Thanks for the help.
-
2 Apr 2013 5:43 AM #7
multiple column search in grid store using filter
multiple column search in grid store using filter
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();
this.getGridPanel().store.filterBy(function(record){
var name= record.data.firstname;
if(name.indexOf(value.toLowerCase()) == 0){
return true;
}
else{
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 #8
One way to my above code is i write multiple if condition
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 recordCode:if(record.data.firstName == searchValue || record.data.lastName==searchValue) return true; else return false;



Reply With Quote