Extjs 4.2:获取列的值之和
我有一个网格,我想得到一列的所有值,然后求和。我试过网格摘要,但无法使其工作 这是我的网格代码:Extjs 4.2:获取列的值之和,extjs,grid,Extjs,Grid,我有一个网格,我想得到一列的所有值,然后求和。我试过网格摘要,但无法使其工作 这是我的网格代码: Ext.ns('dlti.view.widget'); Ext.define('dlti.view.widget.PlaylistDetailsGrid' ,{ extend: 'Ext.grid.Panel', id: 'playlist-details', alias: 'widget.PlaylistDetailsGrid', forceFit: true, stripeRows: tru
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('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'));
});
文档链接:为您的店铺尝试此新代码
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'
}
}
}
});
梅西,如果有帮助的话,试试这个:
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);
我假设您的网格有一个名为“yourgrid”的ID 您有一个3列的网格,名为“货物|数量|价格”
如果您不熟悉console.log,可以使用alert显示总价您能给我一个更清晰的版本吗?对不起,从我尝试过的所有事情来看,我都不太明白,它分散在我的脑海中。这是最简单的。我不明白你怎么能说得更清楚,去你的商店。将sum方法调用它。传递要求和的字段;但显然这是错误的\因为商店已经有了一个功能。我只是想知道我该怎么称呼我的商店?我正在使用Extjs 4.2.AddStoreId配置到你的商店,并将其作为Ext.getStore('storeId')使用。它将返回你商店的对象。我试图用它获取特定的值。var sample=Ext.getStore('playlist-details');console.log(sample.data.items);-但是它不起作用了还是什么都没有,我得到的结果是[]。请编辑更多信息。不鼓励只编写代码和“试试这个”答案,因为它们不包含可搜索的内容,也不解释为什么有人应该“试试这个”。我们努力成为知识的源泉。
var grid = Ext.getCmp('YourGridID'),
store = grid.getStore();
var totalPrice = store.sum('price');
console.log(totalPrice);
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;
}
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;
}