Extjs 4.2:获取列值的总和

pn9klfpd  于 2022-11-04  发布在  其他
关注(0)|答案(5)|浏览(199)

我有一个网格,我想获取一列的所有值并得到总和。我尝试过网格汇总,但无法使其工作。
这是我的网格代码:

Ext.ns('dlti.view.widget');

Ext.define('dlti.view.widget.PlaylistDetailsGrid' ,{
extend: 'Ext.grid.Panel',
id: 'playlist-details',
alias: 'widget.PlaylistDetailsGrid',
forceFit: true,
stripeRows: true,
selType: 'rowmodel',
autosync: true,
height: 150,
width: 950,

store: new dlti.store.PlaylistDetailsStore(),

columns: [

    {
        text: 'Filename',
        dataIndex: 'filename',
        renderer:   function renderDescTarget(val, p, record) {
            var desc = '';
            desc = '<p style="color:#000;font-size:12px;">' + val + '</p>';
            return desc;
        }
    },
    {
        text: 'Transition',
        dataIndex: 'transition',
        renderer:   function renderDescTarget(val, p, record) {
            var desc = '';
            desc = '<p style="color:#000;font-size:12px;">' + val + '</p>';
            return desc;
        }
    },
    {
        text: 'Stay Time',
        dataIndex: 'timeframe',
        renderer:   function renderDescTarget(val, p, record) {
            var desc = '';
            desc = '<p style="color:#000;font-size:12px;">' + val + '</p>';
            return desc;
        }
    }

]
 });

请帮帮我。我真的需要完成我的项目。

编辑

Ext.define('dlti.store.PlaylistDetailsStore', {
extend: 'Ext.data.Store',
model: 'dlti.model.PlaylistDetailsModel',
storeId: 'playlist-details',
proxy: {
            type: 'memory',
            autosync: true,
            reader: {
                type: 'json',
                root: 'result'
            }
        }
});
3duebb1j

3duebb1j1#

Maecy,如果有帮助的话试试这个:

myStore.on('load', function(store, records){
        console.log(records);  //see if store has any records
        console.log(store.sum('fieldName')); //if store has any records, it would print sum of all values of fieldName column.
    }, this);
cpjpxq1n

cpjpxq1n2#

该商店已经具有此功能:

Ext.define('MyModel', {
    extend: 'Ext.data.Model',
    fields: ['visits']
});

Ext.require('*');

Ext.onReady(function() {
    var s = new Ext.data.Store({
        model: MyModel,
        data: [{
            visits: 1
        }, {
            visits: 2
        }, {
            visits: 3
        }]
    });
    console.log(s.sum('visits'));
});

文档链接:

5anewei6

5anewei63#

请为您的商店试用此新代码。

Ext.define('dlti.store.PlaylistDetailsStore', {
extend: 'Ext.data.Store',
config: {
  model: 'dlti.model.PlaylistDetailsModel',
  storeId: 'playlist-details',
  proxy: {
            type: 'memory',
            autosync: true,
            reader: {
                type: 'json',
                root: 'result'
            }
        }
 }
});
jhiyze9q

jhiyze9q4#

我假设您网格有一个名为“YourGridID”的ID,且有一个包含3列的网格,名为“goods|数量|价格

var grid = Ext.getCmp('YourGridID'),
    store = grid.getStore();

var totalPrice = store.sum('price');

console.log(totalPrice);

如果您不熟悉 * console.log *,您可以使用 alert 显示totalPrice

u0sqgete

u0sqgete5#

summaryRenderer: function(value, summaryData, field) {
        // TODO: assign value to an in-scope variable
        // or pass value to another function
        console.log(value.toString());
        return value;
    }

相关问题