1

我有一个网格,我想获取一列的所有值并得到总和。我已经尝试过网格摘要,但无法正常工作。

这是我的网格代码:

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'
            }
        }
});
4

5 回答 5

1

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);
于 2013-10-23T11:42:14.180 回答
0

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

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'
            }
        }
 }
});
于 2013-10-22T06:46:06.320 回答
0

商店已经有这个功能:

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'));
});

文档链接:http ://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-method-sum

于 2013-10-22T05:45:14.753 回答
0

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

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

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

console.log(totalPrice);

如果你不熟悉console.log你可以使用alert来显示totalPrice

于 2013-12-27T09:01:51.907 回答
0
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;
    }
于 2016-07-06T08:06:18.793 回答