1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    47
    Vote Rating
    0
    borden0108 is on a distinguished road

      0  

    Default Filtering A List Through a Store

    Filtering A List Through a Store


    Hi,

    I want to filter a List. I used .filter in sencha touch 1 on the store binded to the list. With Sencha Touch 2 i have not been able to use the .filter after putting the store into a varible


    My Store
    Code:
    Ext.require('Timetabler.model.User');
    Ext.define('Timetabler.store.User',{
        extend:'Ext.data.Store', 
        config:{
            model: 'Timetabler.model.User',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url : '/php/get.php?id=300068',
                reader: 'json'
            }
        },
        
    });
    My List
    Code:
    Hello = Ext.create('Timetabler.store.User');
                Ext.define('Timetabler.view.Day', {
                        extend: 'Ext.List',
                        alias : ['widget.TodayList'],
                        config: {
                            store:Hello,
                            itemTpl:'<div id="tall">{PeriodNumber}</div><div id="bold">{ClassDescription}</div>  <div id="room">{Room} - {ClassCode}</div>',
                             fullscreen: true
                        },
                        
                        
                    });
    My Filter
    Code:
    Hello.filter("DayNumber",2)
    Matt

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,408
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You shouldn't create a store instance and use it in Ext.define like that. The one store will be shared among all instances of the list. If you want that then you should use storeId. To create a store instance in your list config, you can use the alias of the store. To setup an alias in the store you can do this:

    Code:
    Ext.define('Timetabler.store.User',{
        extend:'Ext.data.Store',
        alias  : 'store.user',
    
        requires : [ 'Timetabler.model.User' ], //do this, not Ext.require
    
        config:{
            model: 'Timetabler.model.User',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url : '/php/get.php?id=300068',
                reader: 'json'
            }
        }
    });
    You can see the text in red and the alias is a two part string delimited by a period, first part is the type of alias (store in this case) and the second part is the store type (user in this case).

    Now to handle this your list should look like this:

    Code:
    Ext.define('Timetabler.view.Day', {
        extend: 'Ext.List',
        xtype : 'TodayList',
        
        config: {
            store: { type : 'user' },
            itemTpl:'<div id="tall">{PeriodNumber}</div><div id="bold">{ClassDescription}</div>  <div id="room">{Room} - {ClassCode}</div>',
            fullscreen: true
        }
    });
    Highlighted in red here is how to reference the store type from the alias that we specified in the store. Now when the a list is created a new store instance is also created.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    47
    Vote Rating
    0
    borden0108 is on a distinguished road

      0  

    Default Thanks

    Thanks


    That works but how do i filter the store/list ?

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,408
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Either by using the filters property on the store or the filter methods.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    47
    Vote Rating
    0
    borden0108 is on a distinguished road

      0  

    Default -

    -


    Could you provide an example? Please

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,408
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    http://docs.sencha.com/touch/2-0/#!/...-method-filter

    And there is an example of using the filters property towards the top.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  7. #7
    Sencha User
    Join Date
    Jun 2011
    Posts
    47
    Vote Rating
    0
    borden0108 is on a distinguished road

      0  

    Default


    I had a look at this it only lets you filter the store if it is created with Ext.Create() where as because I am using mvc i need to use Ext.define()

    My Code:
    Code:
    Ext.define('Timetabler.store.User',{
        extend:'Ext.data.Store',
        alias  : 'store.user',
    
    
        requires : [ 'Timetabler.model.User' ], //do this, not Ext.require
    
    
        config:{
            model: 'Timetabler.model.User',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url : '/php/get.php?id=300068',
                reader: 'json'
            }
        }
    });
    What do i put here to filter it?

    Example Code:
    Code:
    var store =Ext.create('Ext.data.Store',{ 
       autoLoad:true,
        model:"User",
        proxy:{
            type:'ajax',
            url :'users.json',
            reader:{
                type:'json',
                rootProperty:'users'
            }
        }
    });
    
    store.filter("SomePropety",2);
    
    Thanks Matt

  8. #8
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,408
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Ok, but did you read the part about looking at the example where it has filters as a property of the store?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  9. #9
    Sencha User
    Join Date
    Jun 2011
    Posts
    47
    Vote Rating
    0
    borden0108 is on a distinguished road

      0  

    Default


    Yes, I did read that. I need to filter the store using a list selector and use the filter dynamicly. I am racking my brains trying to solve this and need a bit of help.

  10. #10
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,408
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    What do you mean list selector? There are only two ways to filter, either with the filters property for filtering when the store is created or with the filter/filterBy method after the store has been created.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1