2

フォーム パネル内にあるフィールド セット内にエディター グリッド パネルがあります。エディター グリッド パネルを使用して、請求書レコードに追加する必要がある複数の請求書品目を記録しています。私がする必要があるのは、エディタ グリッド パネルから (各項目ごとに) 金額を取得し、エディタ グリッド パネルの外側でフォーム パネル内のフィールドに加算 (正の数) または減算 (負の数) することです。このフィールドは未払い額と呼ばれます。これはどのように行うことができますか?助けてくれてありがとう。フォームのコードとスクリーン ショットを次に示します。旗を取れ

グリッドのコードは次のとおりです。/ ==== 請求書データ開始 ========================================== ============= /

// 
var clinRec = new Ext.data.Record.create([
{
    name: 'value'           ,
    mapping: 'name'   ,
    type: 'string'
}
,{
    name: 'display'         ,
    mapping: 'value' ,
    type: 'string'
}
,{
    name: 'stateRegion'     ,
    mapping: 'field1'  ,
    type: 'string'
}
,{
    name: 'clinDesc'        ,
    mapping: 'field2'  ,
    type: 'string'
}
,{
    name: 'fiscalYearStart' ,
    mapping: 'field3'  ,
    type: 'string'
}
,{
    name: 'declarationDate' ,
    mapping: 'field4'  ,
    type: 'string'
}
]);
var clinReader = new Ext.data.JsonReader({
    totalProperty: 'numrows',
    root:'rows',
    id: 'value'
},
clinRec
);
var clinStore =   new Ext.data.Store({
    url: 'GetPickListDataAction.do',
    reader: clinReader,
    listeners: {
        loadexception: function(proxy, store, response, e) {
            logger.trace('#####TOA:DATA: Load Exception');
        }
    }
});
clinStore.load({
    waitTitle: 'Please Wait',
    waitMsg: 'Loading...',
    params: {
        listType: 'CLIN'
    },
    callback: function (records, options, success) {
        if (success) {
            logger.trace("###>>TOA:DATA:CLIN:STORE:LOAD: Succeded");
        }
        else {
            logger.trace("###>>>>>>TOA:DATA:CLIN:STORE:LOAD: failed");
            Ext.MessageBox.show ({
                msg: 'No records are available (CLIN)',
                icon: Ext.MessageBox.WARNING,
                buttons: Ext.MessageBox.OK
            });
        }
    //Core.MessageHandler.display (dstrReader);
    }
});

var iLineItemCM = new Ext.grid.ColumnModel([
{
    id: 'i_line_item_clin',
    header: "Field",
    sortable: false,
    width: 150,
    editor: new Ext.form.ComboBox({
        triggerAction: 'all',
        valueNotFoundText: 'Select a Field...',
        //emptyText: 'Select Field...',
        editable: false,
        forceSelection: false,
        valueField: 'value',
        displayField: 'display',
        store: clinStore,
        mode: 'local'
    })
},
{
    id:'i_line_item_name',
    header: "Line Item Name",
    dataIndex: 'i_line_item_name',
    width: 315,
    resizable: true,
    align: 'left',
    editor: new Ext.form.TextArea({
        allowBlank: false
    })
}
,{
    header: "Amount",
    dataIndex: 'i_line_item_amt',
    width: 80,
    align: 'right',
    renderer: 'usMoney',
    editor: new Ext.form.NumberField({
        allowBlank: false,
        allowNegative: false,
        maxValue: 100000
    })
}
]);

var iLineItemRec =
new Ext.data.Record.create([
{
    name: 'i_line_item_name'    ,
    mapping: 'i_line_item_name'  ,
    type: 'string'
}
,{
    name: 'i_line_item_amt'     ,
    mapping: 'i_line_item_amt'   ,
    type: 'string'
}
]);

var iLineItemStore = new Ext.data.Store({
    url: '',
    reader: new Ext.data.JsonReader({
        root: 'rows'
    },
    iLineItemRec
    )
});

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
    },

    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);
        }
    },
    {
        text: 'Delete',
        tooltip:'Remove the selected line item',
        handler: function(){
            iLineItemGrid.stopEditing();
            var r = iLineItemGrid.getSelectionModel().getSelectedCell();
            iLineItemStore.removeAt(r[1]);
        }

    }

    ]
});
///////////////////
4

1 に答える 1

0

Neil が述べたように、このタイプのロジックを処理するモデルを作成し、ビュー内のロジックをできるだけ少なくする必要があります。rRally そもそもロジックがビューにある理由はありません。これはコントローラーの仕事です。

さらに、プロパティを非常に多く割り当てていることに気付きましたid。これは、アプリケーションのサイズが大きくなるにつれて、管理がかなり面倒になります。これらの割り当てを変更し、現在行っていると想像するのではなく、oritemIdを介してオブジェクトにアクセスすることをお勧めします。プロパティはグローバルであるため、アプリケーション全体で一意である必要があります。Panel.down('#itemId')Panel.queryById(itemId)Ext.getCmpid

calculateTotal指定されたグリッド内のレコードを反復処理するコントローラーでメソッドを実行する順序にアイテムを追加すると、コントローラーはビューを監視する必要があります。その後、各レコードの値を取得し、必要に応じて加算/減算できます。完了したら、更新された合計で必要に応じてフィールド/ラベルを設定します。

注文合計については、このラベルの例のようなものが値を表示するのに役立つかもしれません。ラベルはフォームで送信されないため、フォームに非表示のフィールドを作成しsetValue()、注文合計を計算するたびにその値を変更するために使用できます。

{
    xtype       : 'label',
    itemId      : 'order-total-label',
    /** This can be easily updated via me.update({value: "4.20"}); */
    data        : { value: '0.00' },
    tpl         : "Order Total: ${value}",
}
于 2013-01-28T17:00:17.600 に答える