0

我有一个编辑器网格,当我按下提交按钮时,它会将总数添加到应付金额字段中,然后被禁用(这是一件好事)。我的问题是每次按下添加按钮以创建新记录时,我都无法重新激活提交按钮。

我的问题是网格的监听器。这是正确的方法吗?如果您知道更好的方法来做到这一点,请告诉我。这是我的代码:

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
           }

          ]

});
4

2 回答 2

0

小心身份证。如果您打开两个具有相同 ID 的表单,您将遇到问题。我会为按钮或操作设置一个名称:

提交按钮:

 {
        text: 'Submit',
        tooltip:'Submit the line item',
        action: 'submit',
        // Your other stuff...
 }

添加按钮:

{
        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);
            iLineItemGrid.down('button[action=submit]').setDisabled(false);
        },
        //The scope here depends on what you want the 'this' variable to be in your handler. 
        //If you want it to be the grid then give iLineItemsGrid, if you want it to be the button you don't have to give a scope. 
        //But scope: this is dangerous because the this in your case is not the grid
        scope:iLineItemsGrid
}
于 2012-08-09T07:40:17.483 回答
0

首先,您需要为提交按钮分配一个唯一的 ID。您可以使用id属性。

然后在添加按钮的处理程序中,添加以下行以重新激活提交按钮。

Ext.getCmp('submit_button_id_goes_here').setDisabled(false);
于 2012-08-09T04:29:42.683 回答