PDA

View Full Version : Store data within handler of gridcolumn undefined



stoertebeker
4 Jul 2012, 1:35 PM
Hi,
it looks like I run into an issue that I do not really understand and hope that I get some hints. Since the overall structure of the app is a bit complicated I try to minimize it to what is necessary to understand the issue. Here is the situation:
1. i have a store (which is fed from a database) -> istore (table of items that can be bought)
2. the store is shown in a gridpanel -> the panel shows some columns from the istore; one column (the qty) is editable (set the number of items one wants to purchase)
3. the gridpanel has an actioncolumn with an icon (clicking this icon adds the selected column to a shopping cart=another store->the cart store); the cart store is then shown in a cart window;

So far so good most things work, but the following:
4. based on the entered quantity and the price pulled from the database I want to calculate the linetotal and show it in the cart (the linetotal is a field of the underlying model)
5. the cart store which is shown in the cart window is fed by the store record from the istore
6. the gridpanel in the cart does not reflect all the values that were handed over from the istore
7. the qty (which was entered in the istore) show correctly in the cart window
8. the linetotal that I calculated is empty

So, I started to debug into this part of the application which mainly evolves around the handler of the actioncolumn:



handler: function(grid, rowIndex, colIndex) {
var istore = Ext.data.StoreManager.lookup('Inventory');//this comes from the database
var rec = istore.getAt(rowIndex);//this picks up the selected record
var cstore = Ext.data.StoreManager.lookup('Cart');//this is the target
rec.set('ename',Ext.getCmp('mainview').sel1);//set a field in the record
rec.set('name',Ext.getCmp('mainview').sel2);//set another field in the record
console.log(rec.getData().qty);//show the qty, this is the field that was edited in the gridpanel
console.log(rec.getData().price);//this is the price per item from the database
rec.set('linetotal',(rec.getData().qty*rec.getData().price));//this supposed to calculate the linetotal and store in the cart
console.log(rec);//this shows the record before added to the cart
console.log(cstore.add(rec));//add the record to the cart
console.log(rec.getData().qty);//show the edited field
console.log(rec.getData().linetotal);//show the calculated field


Now the results:
9. as said earlier the new qty is shown in the cart window and it is also contained in the rec when I look at it in the debugger (so everything looks fine, but....)
10. when i send the qty (rec.getData().qty) to the console, it says undefined
11. based on the 'undefined' obviously the calculation of the linetotal fails as well and shows undefined for the linetotal

So, what I really do not get is the discrepancy between 9. and 10.

Thanks for reading this far.

stoertebeker
5 Jul 2012, 6:18 AM
Picnic - Problem in chair not in computer.