View Poll Results: Was this helpful?
- Voters
- 320. You may not vote on this poll
-
Yes - Very Much
247 77.19% -
Yes - Had to tweak it
43 13.44% -
No - Maybe
14 4.38% -
Not at All!!!
16 5.00%
-
16 Nov 2011 9:09 AM #461
How to exclude a row from the total?
How to exclude a row from the total?
Hi Everyone,
I can't for the life of me figure out how to exclude a row from being totaled in the summary row (I'm using summaryType: 'sum').
My setup is this: a 4 column editor grid with 8 rows (happens to be fixed number of rows). 3 of the 4 columns are summaryType: 'sum'. I want to exclude 1 specific row from the sum. My grid currently looks like this:
Row1: 5 10 12
Row2: 0 0 5
Row3: 2 13 0
Total: 7 23 17
I want it to look like this (exclude a row, say Row3):
Row1: 5 10 12
Row2: 0 0 5
Row3: 2 13 0
Total: 5 10 17
If someone can point me in the right direction, I think I can figure it out. What should I be doing and where should the code go? I've been trying to modify my column's summaryRenderer...
summaryRenderer: function(value, meta, record, rowIndex, colIndex, store) {
console.log('new renderer>record...', value, meta, record, rowIndex, colIndex, store);
}
rowIndex, colIndex, store are all undefined! I was going to use rowIndex to get the row then subtract its values from value.
I'm using Ext 3.3.1 and here's some of my code:
function InterventionAreaGroupLandUse() {
return this;
}
InterventionAreaGroupLandUse.dataGrid = null;
InterventionAreaGroupLandUse.save = function() {
InterventionAreaGroupLandUse.dataGrid.commitChanges();
};
InterventionAreaGroupLandUse.init = function() {
function areaRendererTest(value, meta, record, rowIndex, colIndex, store) {
console.log('new renderer>record...', value, meta, record, rowIndex, colIndex, store);
}
function areaRenderer(data, params, v) {
if (v != null) {
if (v == 0) {
return '<span style="color: red">' + v + '</span>';
}
else {
return (v <= Ext.num(InterventionAreaGroupList.getSelectedGroupArea(), 1)) ? ('<span style="color: green">' + v + '</span>') : ('<span style="color: red">' + v + '</span>');
}
}
else {
return '';
}
}
var cm = new Ext.grid.ColumnModel({
defaults: {
sortable: true,
menuDisabled: true
},
columns: [
{
header: 'Land Use Category',
dataIndex: 'LandUseCategory',
width: 150,
editable: false,
renderer: function(value) {
return value.Name;
},
summaryRenderer: function(v, params, data) {
return 'Total Area (ha)*';
}
},
new Ext.grid.NumberColumn({
header: 'Initial Land Use',
dataIndex: 'InitialArea',
format: '0',
width: 150,
editor: new Ext.form.NumberField({
allowBlank: false,
allowDecimals: false
}),
summaryType: 'sum',
summaryRenderer: areaRenderer
}),
new Ext.grid.NumberColumn({
header: 'Baseline Scenario',
dataIndex: 'BaselineArea',
format: '0',
width: 150,
editor: new Ext.form.NumberField({
allowBlank: false,
allowDecimals: false
}),
summaryType: 'sum',
summaryRenderer: function(value, meta, record, rowIndex, colIndex, store) {
console.log('new renderer>record...', value, meta, record, rowIndex, colIndex, store);
}
}),
new Ext.grid.NumberColumn({
header: 'Project Scenario',
dataIndex: 'ProjectArea',
format: '0',
width: 150,
editor: new Ext.form.NumberField({
allowBlank: false,
allowDecimals: false
}),
summaryType: 'sum',
summaryRenderer: areaRenderer
})
]
});
InterventionAreaGroupLandUse.dataGrid = new CbpGrid();
var summaryPlugin = new Ext.ux.grid.GridSummary();
InterventionAreaGroupLandUse.dataGrid.deletable = false;
InterventionAreaGroupLandUse.dataGrid.updateStatus = false;
InterventionAreaGroupLandUse.dataGrid.listUrl = Cbp.baseUrl + 'InterventionAreaGroupLandUse/List?groupId=' + InterventionAreaGroupList.getSelectedValue();
InterventionAreaGroupLandUse.dataGrid.updateUrl = Cbp.baseUrl + 'InterventionAreaGroupLandUse/Update?groupId=' + InterventionAreaGroupList.getSelectedValue();
InterventionAreaGroupLandUse.dataGrid.height = 250;
InterventionAreaGroupLandUse.dataGrid.columnPlugins = [summaryPlugin];
InterventionAreaGroupLandUse.dataGrid.columnModel = cm;
InterventionAreaGroupLandUse.dataGrid.dataFields = [
{ name: 'Id' },
{ name: 'LandUseCategory', mapping: 'LandUseCategory' },
{ name: 'InitialArea', type: 'int' },
{ name: 'BaselineArea', type: 'int' },
{ name: 'ProjectArea', type: 'int' },
{ name: 'LandUseCategoryId', mapping: 'LandUseCategory.Id', type: 'int'}];
InterventionAreaGroupLandUse.dataGrid.renderTo = 'editorGrid';
InterventionAreaGroupLandUse.dataGrid.init();
};
Let me know if more information is needed! Thanks a lot for any help.
-
16 Nov 2011 12:00 PM #462
I fixed it!
I fixed it!
Never mind, I figured it out!
I added a new calculation to Ext.ux.grid.GridSummary.Calculations:
Ext.ux.grid.GridSummary.Calculations['sumExcludeLivestock'] = function(v, record, colName, data, rowIdx) {
if (record.data.LandUseCategory.Id === 8) {
return (data[colName] + Ext.num(v, 0)) - Ext.num(v, 0);
}
else {
return data[colName] + Ext.num(v, 0);
}
};
then I changed the summaryType of the columns from 'sum' to this new calculation, 'sumExcludeLivestock'.
-
1 Dec 2011 11:06 AM #463
Big thanks to MaxT for showing me how to enable a different scope within the summary renderer handlers.
http://www.sencha.com/forum/showthre...l=1#post254649.
Standard cell renderers are affected by "scope: this", but summaryRenderer is not unfortunately. MaxT's fix showed me how to get a reference to something beyond the event itself.
-
22 Dec 2011 4:02 AM #464
Hi! What is your progress in such significant work for Ext 4?
I suppose, this feature should be configurable - showing summary either in top or at bottom of grid.
I'll be very lickely if there is a solution, as I've dissapointed in standart feature, which is very-very useless.
-
4 Jan 2012 6:09 PM #465
-
27 Apr 2012 10:22 PM #466
Grouping Summary with Total Row for Ext 4.0.7
Grouping Summary with Total Row for Ext 4.0.7
Dear friends!
I did extension to the 4 version of the Ext for the Grouping Summary. Look here http://www.sencha.com/forum/showthre...478#post790478
I would be very grateful for your comments and additions


Reply With Quote
