Results 1 to 5 of 5

Thread: filter store without duplication to an other store

  1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    6
    Vote Rating
    0
      0  

    Default filter store without duplication to an other store

    Hi,I ama a begginer in extjs developpement and i have a problem to filter a store
    I have a store containing data which can find duplicates like this example:
    var store = Ext.create('Ext.data.JsonStore', {
    fields: ['id','name' ],
    data: [
    {'id':1,'name':'name1'},
    {'id':2,'name':'name2' },
    {'id':3,'name':'name2'},
    {'id':4,'name':'name1'},
    {'id':5,'name':'name3'}
    ]
    });
    I want to apply a filter to extract this data store to another store (array. ..) the value of field 'name' and the number of occurrences of each value of the field:
    As this example:
    var store1 = Ext.create('Ext.data.Store', {
    fields:['value', 'occurence'],
    data:[
    {'name1', 2},
    {'name2', 2},
    {'name3', 1}
    ] });
    I try to use find() and filter() but i failed to have a store that perofrms the search.
    I need your help

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,381
    Answers
    3997
    Vote Rating
    1536
      0  

    Default

    Code:
    store.filter('name', 'name1');
    var count = store.getCount();
    Should give you how many records are in the store after the filter.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    6
    Vote Rating
    0
      0  

    Default

    Hi,
    thank for your help, but i dont like pass a value in the filter parameters,
    just, i must dynamically filter duplicate values of a store and return the unique items names and their number of occurences

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      0  

    Default

    The store's collect method can tell you the deduplicated value list but it won't tell you counts.

    To get counts you could maybe use each to iterate over the store and count up how many of each value you see.

  5. #5
    Sencha User
    Join Date
    Oct 2012
    Posts
    6
    Vote Rating
    0
      0  

    Default

    thank, i used the collect method and i solved the problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •