我有一个网格,我想得到一列的所有值并得到总和。我已经尝试了网格摘要,但我无法使其正常工作。
这是我的网格代码:
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'
}
}
});
答案 0 :(得分: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
答案 1 :(得分: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'
}
}
}
});
答案 2 :(得分:0)
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);
答案 3 :(得分:0)
我假设你的网格有一个名为“ YourGridID ”的ID 你有一个3列的网格,名为“ goods | qty | price ”
var grid = Ext.getCmp('YourGridID'),
store = grid.getStore();
var totalPrice = store.sum('price');
console.log(totalPrice);
如果您不熟悉 console.log ,可以使用提示来显示 totalPrice
答案 4 :(得分: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;
}