Hybrid View

  1. #1
    Sencha User
    Join Date
    Feb 2010
    Posts
    34
    Vote Rating
    0
    umit is on a distinguished road

      0  

    Default store with distinct option

    store with distinct option


    Hallo!
    I wrote a function, that you can use for distinct Element filtering.
    The purpose is if you get resultsets with joins and have more entries, and you want to show the entries in more than one combobox you will get double entries, if you use the same store.
    You may want to filter this "double entries".
    Of corse you could make 2 requests to the server, but why bother the server with requests, if the client can do it(you may have performace issues on the server).

    If your store looks like this:
    Name
    Anton
    Toni
    Toni

    you will get this:
    Name
    Anton
    Toni

    Here the code:
    function getDistinctStore(store,distinctKey){//info: store is a json store
    var newstore=new Ext.data.ArrayStore();
    var record;
    store.data.each(function(rec){
    if(record==null){
    newstore.add(rec);
    record=rec;
    }
    else
    if(record.get(distinctKey)!=rec.get(distinctKey)){
    newstore.add(rec);
    record=rec;
    }
    });
    return newstore;
    }
    It would be nice if Ext would have this as standard.
    greets umit

  2. #2
    Sencha User
    Join Date
    Feb 2012
    Posts
    10
    Vote Rating
    0
    dhilchrist is on a distinguished road

      0  

    Default Distinct rows from an Ext.data.XmlStore

    Distinct rows from an Ext.data.XmlStore


    Distinct rows from an Ext.data.XmlStore?? (Extjs 3.3.0 lib)

    how can I retrieve distinct rows from an XmlStore,

    Data Set
    Job operation RunId Status
    a launch 123 Pass
    a lunch 123 Pass
    a hold 124 Wait
    a hold 124 wait

    Result set,
    I wanted to display only 2 rows based on RunId

    a launch 123 Pass
    a hold 124 wait

  3. #3
    Sencha User
    Join Date
    Feb 2010
    Posts
    34
    Vote Rating
    0
    umit is on a distinguished road

      0  

    Default


    Hi,
    use the filter function from the store,
    i wrote this, when i was new to extjs and the implementation of mine has some kinda problems e.g. the store has to be sorted.


    For your solution the filter function should do it, based on the criteria to filter(if you have the runid as seperate field in the store).
    so something like:

    Code:
    var addedRunIds=[];
    myXmlStore.filterBy(function(rec){
    if(addedRundIds.indexOf(rec.get("runid")==-1){//does not contain it
    addedRunIds.add(rec.get("runid")); return true;
    } return false;
    }
    You can also make a new store and add to to the store instead of filtering it.
    greets
    Last edited by umit; 9 Jul 2012 at 11:22 PM. Reason: -1 instead of 1

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    10
    Vote Rating
    0
    dhilchrist is on a distinguished road

      0  

    Default xmlstore filterby, extjs 3.3.0

    xmlstore filterby, extjs 3.3.0


    thanks umit,
    i tried like this but getting errors..expected string, identifier, number!!
    store.load({
    callback : function() {
    var addedRunIds=new Array();
    for (var i = 0; i < store.getCount() - 1; i++) {
    record = store.getAt(i);
    store.filterBy({
    function(record){
    if(addedRunIds.indexOf(record.get("TESJobRunID")==1){//does not contain it
    addedRunIds.add(record.get("TESJobRunID"));
    return true;
    }
    return false;
    }
    });
    }
    }
    });

  5. #5
    Sencha User
    Join Date
    Feb 2010
    Posts
    34
    Vote Rating
    0
    umit is on a distinguished road

      0  

    Default


    Hi,
    You have 2 variables with the name record, it is difficult to tell which one is the one you use, you should take a different name like record2, otherwise you have to work with this.record, but that's fuzzy.

    And when you use indexOf it return -1 when it cant find the record, not 1, sry i wrote 1 ...

    try this
    Code:
    store.load({
    	callback : function() {
    		var addedRunIds=[];
    		store.filterBy(function(rec){
    			if(addedRunIds.indexOf(record.get("TESJobRunID")==-1){//does not contain it
    				//so add it and show it
    				addedRunIds.push(rec.get("TESJobRunID"));
    				return true;
    			}
    			return false;
    		});
    	} 
    });
    What is the content of TESJobRunID ?

    Is it:
    a launch 123 Pass
    a lunch 123 Pass
    a hold 124 Wait
    a hold 124 wait

    or
    123
    123
    124
    124

    if it is the 1. you have to split it to get the id.

  6. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    10
    Vote Rating
    0
    dhilchrist is on a distinguished road

      0  

    Default


    the contents of TESJobRunId are
    123
    123
    124
    124

Similar Threads

  1. count distinct for a particular column
    By emmas in forum Ext GWT: Discussion
    Replies: 1
    Last Post: 23 Aug 2010, 1:26 PM
  2. Editable Grid with All ComboBoxes, and Distinct values?
    By jwong in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 9 Dec 2009, 3:52 AM
  3. How to specify jsonData as option in store.load()?
    By dbassett74 in forum Ext 3.x: Help & Discussion
    Replies: 9
    Last Post: 16 Jul 2009, 5:34 PM
  4. Editable Grid with All ComboBoxes, and Distinct values?
    By jwong in forum Ext GWT: Help & Discussion (1.x)
    Replies: 4
    Last Post: 19 Jun 2008, 2:16 PM
  5. how to distinct editorGrid's cellclick from celldblclick
    By lixiaoxu85 in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 28 Apr 2008, 7:13 PM

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar