我有一个有两个汇总位置的网格。我在网格的末尾有一个摘要。这很有效。但我想要的是计算每行的总价格。我有4个专栏叫做'Aantal,Stukprijs,korting和Totaal'。我需要的是在'Totaal'栏中这个总和:(Aantal X Stukprijs) - %korting(意味着折扣)。
这是该网格的代码:
xtype: 'gridpanel',
id: 'materiaalGrid',
autoScroll: true,
forceFit: true,
store: 'MyArrayStore8',
columns: [
{
xtype: 'rownumberer'
},
{
xtype: 'gridcolumn',
dataIndex: 'naam',
text: 'Naam',
editor: {
xtype: 'combobox'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'type',
text: 'Type'
},
{
xtype: 'numbercolumn',
summaryType: 'sum',
dataIndex: 'gewicht',
text: 'Gewicht'
},
{
xtype: 'numbercolumn',
summaryType: 'sum',
dataIndex: 'aantal',
text: 'Aantal',
editor: {
xtype: 'numberfield'
}
},
{
xtype: 'numbercolumn',
dataIndex: 'stuks',
text: 'Stukprijs'
},
{
xtype: 'numbercolumn',
dataIndex: 'korting',
text: 'Korting',
editor: {
xtype: 'numberfield',
maxValue: 100
}
},
{
xtype: 'numbercolumn',
summaryType: 'sum',
dataIndex: 'stuks',
text: 'Totaal'
},
{
xtype: 'booleancolumn',
dataIndex: 'verkoop',
text: 'Verkoop'
},
{
xtype: 'actioncolumn',
maxWidth: 50,
minWidth: 50,
width: 50,
defaultWidth: 50,
emptyCellText: 'Delete',
menuDisabled: true,
items: [
{
handler: function(view, rowIndex, colIndex, item, e, record, row) {
var selection = me.getView().getSelectionModel().getSelection()[0];
if (selection) {
store.remove(selection);
}
},
altText: 'Delete'
}
]
}
],
viewConfig: {
enableTextSelection: false
},
features: [
{
ftype: 'summary'
}
],
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
})
],
我只能在底行获得aantal和gewicht的总和。
答案 0 :(得分:2)
要解决此特定情况,您可以尝试这样做:
{ name: 'total', type: 'number', convert: function(value, record) { if(!value) { // Only calculate the value if no value set since the // Calculated total column will fill this field with a real // value we don't want to mess value = record.get('price') * record.get('units'); } return value; } }
grid.on('edit', function(editor, e) { // commit the changes right after editing finished e.record.set('total'); // force total re-calculation e.record.commit(); });
你看到complete example here,希望它有所帮助。