首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >编辑器网格面板的按钮(侦听器)问题

编辑器网格面板的按钮(侦听器)问题
EN

Stack Overflow用户
提问于 2012-08-09 01:41:37
回答 2查看 940关注 0票数 0

我有一个编辑器网格,当我按下提交按钮时,它将合计添加到金额到期字段,然后被禁用(这是一件好事)。我的问题是,我不能在每次按下add按钮来创建新记录时重新激活submit按钮。

我的问题是网格的监听器。这是正确的方法吗?如果你知道更好的方法,请让我知道。下面是我的代码:

代码语言:javascript
运行
复制
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
           }

          ]

});
EN

回答 2

Stack Overflow用户

发布于 2012-08-09 12:29:43

首先,您需要为Submit按钮分配一个惟一的id。您可以使用id属性。

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

代码语言:javascript
运行
复制
Ext.getCmp('submit_button_id_goes_here').setDisabled(false);
票数 0
EN

Stack Overflow用户

发布于 2012-08-09 15:40:17

注意id,如果你打开的两个表单都有相同的id,你就会有问题。我会为按钮或操作设置一个名称:

提交按钮:

代码语言:javascript
运行
复制
 {
        text: 'Submit',
        tooltip:'Submit the line item',
        action: 'submit',
        // Your other stuff...
 }

add按钮:

代码语言:javascript
运行
复制
{
        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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11870118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档