Pages

Showing posts with label extjs store single record id. Show all posts
Showing posts with label extjs store single record id. Show all posts

Thursday, January 12, 2012

How to load a single record into a store

Usually a store loads a list of records, but if you need to load a single record, do this:
var id = 9; //an example record id

var contactsStore = Ext.StoreManager.get('contacts');

contactsStore.load({
  id: id, //set the id here
  scope:this,
  callback: function(records, operation, success){
    if(success){
      var contact = records[0];
      //do something with the contact record
    }
  }
});
this will send an async request to your server, using the store or its model's proxy, with the read api or its url, something like

/api/contacts/read?id=9