PDA

View Full Version : Ext 3.0 and loop over columns in grid and sum??



Westside
3 Sep 2011, 9:04 PM
Hi,

I'm using a grid and I have this code:

var selectedRows = objGrid.getSelectionModel().getSelections();

This returns an array it seems and I'm trying to sum up all the values of all columns in the row except a column called "Total_Employees".

My goal is to show an alert message if the sum of all values is greater than the value in my column called "Total_Employees" so this column should be excluded from the sum.

How can I do this?

Thanks

-Westside

skirtle
3 Sep 2011, 9:29 PM
This is an ExtJS 4 forum, not ExtJS 3.

Why don't you just call record.get('fieldname') for each field of the record and add together the values?

daddie888
5 Sep 2011, 12:40 AM
Hi, here is how i do it in ExtJs3 with a total column that becomes red if greater than 100%, should get you started.
Grtz


style:
.roodTotaal .x-grid3-col-totaal {background-color:red !important;color:black;}
ColumnConfig:
cmConfig = new Ext.grid.ColumnModel({
defaults: {"sortable": true, "menuDisabled":false, "align":"right", "width": 40},
columns: [
{"id":"id", "header": "id", "hidden": true, "dataIndex": "id", "width": 40},
........
{"id":"pct_c77", "header": "c77", "dataIndex":"pct_c77", renderer : percentRenderer, editor: editorNummerMax(100)},
{"id":"totaal", "header": "totaal", "width": 40, renderer : totaalRenderer}
]
});
Renderers:
function totaalRenderer(value, metaData, record, rowIndex, colIndex, store){
//var tot = record.data.pct_dossiers+record.data.pct_5e+record.data.pct_6m+record.data.pct_7m+record.data.pct_10e+record.data.pct_11e+record.data.pct_21j+record.data.pct_pns+record.data.pct_plus6m+record.data.pct_inv+record.data.pct_zii+record.data.pct_c77;
var tot = record.data.pct_dossiers+record.data.pct_5e+record.data.pct_6m+record.data.pct_10e+record.data.pct_11e+record.data.pct_21j+record.data.pct_pns+record.data.pct_inv+record.data.pct_zii+record.data.pct_c77;
if (tot>100){
metaData.css = 'roodTotaal';
}
return tot+"%";
}
function percentRenderer(value, metaData, record, rowIndex, colIndex, store){return value + '%';}
Grid:
gridConfig = new Ext.grid.EditorGridPanel({
id : 'gridConfig',
selModel : new Ext.grid.RowSelectionModel({singleSelect:true}),
loadMask : false,
clicksToEdit : 1,
layout : 'anchor',
cm : cmConfig,
columnLines : true,
autoHeight : true,
store : storeConfig,
plugins : group,
autoExpandColumn: 'beheerder',
viewConfig: {
forceFit: true,
emptyText: "Geen data gevonden",
loadMask : {msg : 'Bezig met laden...'}
}

...........

listeners: {
'beforerender' : {fn:function(){this.store.load();}}
}
});