Results 1 to 4 of 4

Thread: Data.store load delay

  1. #1
    Sencha User
    Join Date
    Aug 2009
    Posts
    20

    Default Data.store load delay

    I have a problem whith this simple code :

    Code:
    Ext.onReady(function(){
    
    var MyStore=new Ext.data.Store({
      proxy:new Ext.data.HttpProxy({url:'query.php',method:'POST'}),
      reader:new Ext.data.JsonReader(
      {root:'results'},[
        {name:'parameter',type:'string',mapping:'parameter'},
        {name:'value',type:'string',mapping:'value'},
      ])
    });
    
    var MyColModel=new Ext.grid.ColumnModel([
    {header:'parameter',dataIndex:'parameter',width:100},
      {header:'value',dataIndex:'value',width:100}
    ]);
    
    var MyGrid=new Ext.grid.GridPanel({
      el:'MyGrid',
      store:MyStore,
      cm:MyColModel,
      autoHeight:true,
      width:200
    });
    
    MyStore.load();
    MyGrid.render();
    
    alert(MyStore.getCount());
    
    });
    query.php return :
    PHP Code:
    ({"results":[
      {
    "parameter":"param1","value":"1"},
      {
    "parameter":"param2","value":"2"},
      {
    "parameter":"param3","value":"3"}
    ]}) 
    I wish to know the number of rows returned by php (getCount on the data.store).
    But I obtain always 0, pehpas because getCount is launched before data is loaded.
    How I can add any wait method to obtain the correct count ?

    Thanks for your help

  2. #2
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    You need to learn about asynchronous programming and events.

    myStore.on('load', funciton() {
    alert(MyStore.getCount());
    });

  3. #3

    Default

    Welcome to "AJAX = Asynchronous JavaScript."

    Categorically speaking, whenever you ask anything, anywhere, to do something, your code does not wait for the completion of that request! Instead, you specify a callback that is to be invoked when (and if...) the expected completion occurs.

    You do not know when that will be. You do not know if that will be. All that you know is that, if-and-when something happens, the appropriate callback will be invoked.

    So... when you ask a store to "load," the wheels are put in motion, and from that point forward you're just like the hopeful job-applicant ... "we'll call you ..."

  4. #4
    Sencha User
    Join Date
    Aug 2009
    Posts
    20

    Default

    OK, I have the solution.
    Thanls for your help...

Posting Permissions

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