1. #1
    Ext User
    Join Date
    Sep 2007
    Posts
    42
    Vote Rating
    0
    aresot is on a distinguished road

      0  

    Default Finding Record in the Store

    Finding Record in the Store


    I have JsonStore object and I need to find record with exact match for specific field. I tried 2 things:
    1) when building JSON output on server side I added "id" param like that:
    {"grid":[{"id":"1","m_regnum":"1610002346"}]}
    then on browser side I call store.getById("1") but get undefined as return
    2) I try calling store.find("id","1") and it does return correct index but... its partialmatch. In other words if I have another record with "id":13, it also will be found.

    Is there way to either do complete match for the field or what do I make wrong in my #1 approach?

    Thank you.

  2. #2
    Ext User
    Join Date
    Jul 2007
    Posts
    3,128
    Vote Rating
    1
    devnull is an unknown quantity at this point

      0  

    Default


    does the reader have an 'id' config property defined that maps to the field you wish to use as an id?

  3. #3
    Ext User
    Join Date
    Sep 2007
    Posts
    42
    Vote Rating
    0
    aresot is on a distinguished road

      0  

    Default


    Yes it does but I think it creates "id" property instead of Reader internal id. Anyhow I solved this by just scanning through records:
    Code:
    store.each(function(rec) {
        if(ReloadTable._items[rec.get("id")])    /* do something*/{break;}
    });

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    57
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Quote Originally Posted by aresot View Post
    I have JsonStore object and I need to find record with exact match for specific field. I tried 2 things:
    1) when building JSON output on server side I added "id" param like that:
    {"grid":[{"id":"1","m_regnum":"1610002346"}]}
    then on browser side I call store.getById("1") but get undefined as return
    2) I try calling store.find("id","1") and it does return correct index but... its partialmatch. In other words if I have another record with "id":13, it also will be found.
    Thank you.
    That's what find is for.

    If you want to get by ID, use getById!

    http://extjs.com/deploy/dev/docs/?cl...member=getById

  5. #5
    Ext User
    Join Date
    Sep 2007
    Posts
    42
    Vote Rating
    0
    aresot is on a distinguished road

      0  

    Default


    But that was my original problem. See my #1 last phrase:
    then on browser side I call store.getById("1") but get undefined as return

    My point was that looks like getById() uses internal id generated by Store and ignores "id" property passed by the server in the JSON.

  6. #6
    Ext User
    Join Date
    Sep 2007
    Posts
    42
    Vote Rating
    0
    aresot is on a distinguished road

      0  

    Default


    I think I know what is going on.
    Since Im using JsonStore object I do not explicitly specify "reader". Documentation says following: JsonStore is pre-configured with a built-in Ext.data.HttpProxy and Ext.data.JsonReader. Question now is what is the "id" config property that JsonStore sets for the JsonReader. Apparently nothing. I was hoping that JsonStore would at least setup id:"id" as default but its not the case.

    I set "id":id in the JsonStore and everything started to work.
    Note to myself: pay attention to the bold statements in the help.
    Here is what I missed from the documentation: Note: Although they are not listed, this class inherits all of the config options of Store, JsonReader.

  7. #7
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    6
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    This confused me in the beginning. Don't confuse the id you pass from the server and assign in your store with the record id used by ext. I went through my code and changed all references to "id" that were coming from server to "primaryKey" for example just to clarify in my head what was going on.

  8. #8
    Ext User
    Join Date
    Jul 2009
    Posts
    1
    Vote Rating
    0
    twacaser is on a distinguished road

      0  

    Default


    It took me a couple of tries to get this right. When defining the store, it worked when I specified the field name for the 'id' property in the store, not the field number as I saw in another note.

    store: new Ext.data.JsonStore(
    {
    id: 'item_id',
    totalProperty:'totalCount',
    root:'list',
    url:'items.php',
    fields:
    [ { name:'item_id', type:'int' },
    { name:'name' },
    { name:'item_type' },
    { name:'item_lvl', type:'int' }
    ]
    } ),

    Then, to find the row number, you can use the following to select a grid item.

    var itemId = 6; // whichever item should be selected

    var rnum = grid.getStore().indexOfId( itemId );
    grid.getSelectionModel().selectRow( rnum );
    grid.getView().ensureVisible(rnum,0,true);
    grid.getView().focusRow(rnum);

    Hope I saved someone some time.

  9. #9
    Sencha User
    Join Date
    Oct 2012
    Location
    Hyderabad,india
    Posts
    13
    Vote Rating
    1
    reddy479 is on a distinguished road

      1  

    Default


    Hi ,

    I am not able select record from Ext.data.Store.

    Code:
    STORE ::
    Ext.define('mailtrack.store.TemplateContents', {
        extend: 'Ext.data.Store',
    	model: 'mailtrack.model.TemplateContent',
    	autoLoad: true,
    	storeId: 'TemplateContentStoreId',
    	    proxy:{ 
        		type: 'ajax',
        		url:serviceUrl+'template-service/get-template-content/1',
        		reader: {
                    type: 'json',
                    root: 'Block'
        		},
        		afterRequest:function( request, success )
        		{
        			console.log( 'request here' + request );
        			console.log( 'success result here'  + success );
        		}
       }
    });
    
    MODEL ::
    Ext.define('mailtrack.model.TemplateContent', {
        extend: 'Ext.data.Model',
        fields: [
    				{name:'id',type:'long'}, 
    				{name:'content',type:'string'}, 
    				{name:'createdBy',type:'string'},
    				{name:'updatedBy',type:'string'},
    				{name:'createdOn',type:'date'},
    				{name:'updatedOn',type:'date'},
    				{name:'blockcontentId',type:'long'} 
    			]
    });
    
    var templateContentStore = Ext.create('mailtrack.store.TemplateContents') ;
    templateContentStore.load() ;
    var templateRecord = templateContentStore.findRecord('id', 1) ;
    templateRecord.get('content') ;
    Unable to execute above code to get particular record and the filed content from that.

    Can any one help me.
    Thanks in advance.

    Ranjihtreddy Abbareddy