Hello,
I have an Editor Grid and when I press the submit button it adds the total to the Amount Due field and then is disabled(This is a good thing). My problem is that I cannot re-activate the submit button each time the add button is pressed to create a new record. My problem is with the listener for the grid. Is this the correct way to do this? If you know of a better way to do this please let me know. Thanks for your help. Here is my code.
Code:
var iLineItemGrid = new Ext.grid.EditorGridPanel({
id: 'iLineItemStore',
store: iLineItemStore,
cm: iLineItemCM,
cls: 'iLineItemGrid',
width: 'auto',
height: 'auto',
frame: true,
//title:'Edit Plants?',
//plugins:checkColumn,
clicksToEdit:1,
viewConfig: {
//forceFit: true
autoFit:true
},
//new
listeners: {
edit: function(editor, edit) {
var form = edit.grid.up('form'),
button = form.down('button[text=Submit]');
// enable the button after the grid is edited
button.setDisabled(false);
}
},
tbar: [{
text: 'Add',
tooltip:'Add the line item',
handler : function(){
var r = new iLineItemRec({
i_line_item_name: '',
i_line_item_amt: ''
});
iLineItemGrid.stopEditing();
iLineItemStore.insert(0, r);
iLineItemGrid.startEditing(0, 0);
},
//Should this be scope:this or scope:iLineItemGrid?
scope:this
},
{
text: 'Delete',
tooltip:'Remove the selected line item',
handler: function(){
iLineItemGrid.stopEditing();
var r = iLineItemGrid.getSelectionModel().getSelectedCell();
iLineItemStore.removeAt(r[1]);
},
// handler: function(){
// iLineItemGrid.stopEditing();
// var r = iLineItemGrid.getSelectionModel().getSelected();
// iLineItemStore.removeAt(r[0]); }
// },
//Should this be scope:this or scope:iLineItemGrid?
scope:this
},
{
xtype: 'tbfill'
},
{
text: 'Submit',
tooltip:'Submit the line item',
//new
//disabled: true,
handler: function(){
iLineItemGrid.stopEditing();
// Will this code save changes to the database?
//iLineItemGrid.getStore().commitChanges();
iLineItemStore.commitChanges();
var iAmountTotalForLineItems = 0;
var iAmountInDueField = Ext.getCmp('iAmountDue').value;
var tempTotal = 0;
var result = 0;
iLineItemStore.each(function(addAmount){
iAmountTotalForLineItems += addAmount.get('i_line_item_amt');
});
alert('1 iAmountInDueField: ' + iAmountInDueField +' iLineItemTotalHold: '+iLineItemTotalHold + ' iAmountTotalForLineItems: '+ iAmountTotalForLineItems);
if (iLineItemTotalHold > iAmountTotalForLineItems ){
alert ('if');
tempTotal = iLineItemTotalHold - iAmountTotalForLineItems;
result = iAmountInDueField - tempTotal;
alert('two: '+result+' = '+iAmountInDueField+' + '+tempTotal );
}
else if (iLineItemTotalHold < iAmountTotalForLineItems ){
alert ('if2');
tempTotal = iAmountTotalForLineItems - iLineItemTotalHold;
result = iAmountInDueField + tempTotal;
alert('3: '+result+' = '+iAmountInDueField+' - '+tempTotal );
}
iLineItemTotalHold = iAmountTotalForLineItems;
Ext.getCmp('iAmountDue').setValue(result);
this.setDisabled(true);
}
//scope:this
}
]
});