簡體   English   中英

從網格總計金額並在sencha的文本框中顯示

[英]Total the amount from Grid and display in textbox in sencha

我有一個視圖名稱PurchaseReport.js

Ext.define("App.view.tabs.PurchaseReport", {
extend: "Ext.panel.Panel",
alias: "widget.PurchaseReportTab",
requires: [
        "App.model.PurchaseReport", "Ext.toolbar.Toolbar"
],
border: false,
layout: "fit",
items: [
    App.Util.buildBrowseConfig({}, {
        controller: "PurchaseReport",
        primaryKeyField: "PurchaseReportId",
        stateful: true,
        stateId: "App.view.windows.PurchaseReport-grid",

        columns: [
          { dataIndex: "PurchaseCost", filter: true, header: "Purchase Cost", width: 150 }
        ],
        features: [{ ftype: "filters", autoReload: false, local: true }],
        store: { model: "App.model.PurchaseReport", sorters: [{ property: "Name", direction: "asc" }],
        height: 200,
        width: 400,
        bbar: [
        {
            dataIndex: "PurchaseCost",
            reference: 'purchaseCostField',
            xtype: 'textfield',
            name: 'Total',
            fieldLabel: 'Total',
            allowBlank: false
        }
        ],
        renderTo: Ext.getBody()

       }
    })
 ]
});

這是我的控制器部分,網格被綁定為PurchaseReport.js,

Ext.define("App.controller.tabs.PurchaseReport", {
extend: "Ext.ux.app.BrowseController",
views: ["tabs.PurchaseReport"],
refs: [
    {
        ref: "myPurchaseReportGrid",
        selector: "PurchaseReportTab > gridpanel"
    }
],

init: function () {
    this.control({
        PurchaseReportTab: {
            bind: function (a, c) {
             **//Grid bind start**
                var b = this.getMyPurchaseReportGrid();
                b.getSelectionModel().deselectAll();
                b.store.removeAll();
                b.fireEvent("bind", b, c)
                **//Grid bind End**

             **//Combobox Bind start**
                var combo = this.getCoachCombo(),
                      store = combo.store,
                      options = store.lastOptions || {};
                options = Ext.apply({
                    callback: function () {
                        combo.select(App.coach.CoachId)
                        //console.log("called rajesh");
                    }
                }, options);
                store.load(options);
                if (App.coach.IsAdmin) {
                    combo.show()
                }
                **//Combobox Bind end**


                var abilities = App.coach.Abilities,
                      toolbar = this.getToolbar();
                for (var x = 0; x < abilities.length; x++) {

                    var ability = abilities[x],
                        button = toolbar.query("button[tooltip=" + ability.Name + "]");
                    if (button.length) {
                        button[0].setVisible(true)
                    }
                }
              store.load(options);
                var purchaseCostField = this.getReferences().purchaseCostField;
                purchaseCostField.setValue(store.sum('PurchaseCost'));
            }
        },

        "PurchaseReportTab > gridpanel": {
            bind: this.bind,
            itemdblclick: this.handleRecord,
            selectionchange: this.selectionChange
        }


    })
}

});

這是我的模型零件名稱,為PurchaseReport.js

 Ext.define("App.model.PurchaseReport", {
extend: "Ext.data.Model",
fields: [
    {
        name: "PurchaseCost",
        type: "date"
    }
],

proxy: {
    type: "ajax",
    url: "ControllerFactory.aspx",
    extraParams: {
        controller: "PurchaseReport",
        operation: "GetPurchaseReportsByCoachIdAndDates"
    },
    reader: {
        type: "json",
        root: "data",
        successProperty: "success"
    }
}

});

該頁面看起來像這樣,我想在文本框中顯示PurchaseCost的總數,如下圖所示,大約是1195左右的PurchaseCost總數

在此處輸入圖片說明

一種快速的方法

添加對您的文本字段的引用:

        {
            dataIndex:"PurchaseCost",
            reference: 'purchaseCostField',
            xtype: 'textfield',
            name: 'Total',
            fieldLabel: 'Total',
            allowBlank: false
        }

在商店加載后,在控制器中將值添加到文本字段:

store.load(options);
var purchaseCostField = this.getReferences().purchaseCostField;
purchaseCostField.setValue(store.sum('PurchaseCost'));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM