1. #1
    Sencha User
    Join Date
    Apr 2010
    Location
    Brazil
    Posts
    13
    Vote Rating
    0
    Answers
    1
    andre_mendesc is on a distinguished road

      0  

    Default 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!

  2. #2
    Sencha User loiane's Avatar
    Join Date
    Aug 2009
    Posts
    184
    Vote Rating
    53
    Answers
    7
    loiane is a jewel in the rough loiane is a jewel in the rough loiane is a jewel in the rough

      0  

    Default


    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

  3. #3
    Sencha User
    Join Date
    Apr 2010
    Location
    Brazil
    Posts
    13
    Vote Rating
    0
    Answers
    1
    andre_mendesc is on a distinguished road

      0  

    Default


    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 )

  4. #4
    Sencha User loiane's Avatar
    Join Date
    Aug 2009
    Posts
    184
    Vote Rating
    53
    Answers
    7
    loiane is a jewel in the rough loiane is a jewel in the rough loiane is a jewel in the rough

      0  

    Default


    Thanks!

    I got you now!

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

    So you can do like this:

    PHP Code:
    store.filter([Ext.create.('Ext.util.Filter', {property'name'value'some value'anyMatchtrue})]); 
    And with the config anyMatch, it will return what you are looking for.
    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

  5. #5
    Sencha User
    Join Date
    Apr 2010
    Location
    Brazil
    Posts
    13
    Vote Rating
    0
    Answers
    1
    andre_mendesc is on a distinguished road

      0  

    Default


    Thanks but it still not working, I got a blank response as result of using this
    PHP Code:
                    handler: function(){                                load.clearFilter();                                load.filter([Ext.create('Ext.util.Filter', {property'name'value:  Ext.getCmp("nomeAluno").getValue(), anyMatchtrue})]);                                     }                } 
    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!

  6. #6
    Sencha User
    Join Date
    Apr 2010
    Location
    Brazil
    Posts
    13
    Vote Rating
    0
    Answers
    1
    andre_mendesc is on a distinguished road

      0  

    Default GOT IT

    GOT IT


    Just got it working!

    Code:
                    handler: function(){
                            load.clearFilter();
                            load.filter([
                                    {
                                    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.

  7. #7
    Sencha Premium Member
    Join Date
    Nov 2012
    Location
    Bangalore
    Posts
    79
    Vote Rating
    1
    rupamkhaitan is on a distinguished road

      0  

    Default 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.

  8. #8
    Sencha Premium Member
    Join Date
    Nov 2012
    Location
    Bangalore
    Posts
    79
    Vote Rating
    1
    rupamkhaitan is on a distinguished road

      0  

    Default


    One way to my above code is i write multiple if condition

    Code:
    if(record.data.firstName == searchValue || record.data.lastName==searchValue)
       return true;
    else
      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

Thread Participants: 2

Tags for this Thread