2

I'm trying to read grid values from within a load event of my form. The ordersStore.load() loads my grid with data, but I don't get a record returned using getAt. Is there a better way to do this? Thanks.

client_form.on({
   actioncomplete: function(form, action){
      if(action.type === 'load'){
      var suite_no = action.result.data.suite_no;
      ordersStore.baseParams.suite_no = suite_no;
      ordersStore.load();
      var orderRec = Ext.data.Record.create(['order_id', 'suite_no', 'merchant', 'track_no', 'invoice_no', {name:'total',type: 'float'},  {name:'weight',type: 'float'}, 'status']);
      var orderRec = ordersStore.getAt(0);
      Ext.Msg.alert('rec=', orderRec);
         }
    }
});                                                 
hadenp
  • 445
  • 3
  • 9

1 Answers1

2

The problem is that ordersStore.load() is asynchronous (the docs say-so). The data will arrive at a later point, and is not available immediately after (where you're looking for it).

You need to add a 'load' event handler. In that function, you can examine your data since it will be loaded at that time.

Gerrat
  • 28,863
  • 9
  • 73
  • 101
  • Thanks for your reply. I'm really just trying to get a value from the first row of my grid. Given a myGrid object would you know the syntax to get a cell value - something like var my_order_id = ordersGrid.get('order_id'); – hadenp Jun 21 '11 at 20:26
  • @hadenp: As I said, you can't get a value at this point in your code. The grid is not loaded here. The code after "ordersStore.load()" will run before the store is loaded. Having said that, myGrid.getStore().getAt(0).get("order_id") should get the order_id field from the first row of the grid's store. – Gerrat Jun 21 '11 at 20:39
  • OK. Thanks much for taking the time to clarify for a newbie! – hadenp Jun 21 '11 at 21:07
  • @hadenp: ...you should accept an answer if it answers your question (click the checkmark next to the answer you would like to accept)...if someone has answered any of your other questions to your satisfaction, you should accept those too. – Gerrat Jun 21 '11 at 21:12