PDA

View Full Version : Model calculate field based on grids summary



Misiu
13 Jan 2014, 1:39 PM
I have a grid with 3 columns: "Name", "Tasks done", "% of student group".
First one is name of student, second shows how many tasks he has completed, and third percentage value, formula is like this:
student tasks done/ sum of all students tasks.

First 2 columns come from server request, but third field must be calculated.
I read similar question: http://www.sencha.com/forum/showthread.php?241077-Calculated-field-in-model
b (http://www.sencha.com/forum/showthread.php?241077-Calculated-field-in-model)ut i must be able to remove row from that grid and recalculate that column for all rows.

How can I create that field in my model?
From similar question I found out I could do converter field:



{
name: 'total', type: 'int',
convert: function(val,row) {
return row.data.month1 + row.data.month2;
}
}
but this way I can access fields of model, not whole store.

How can I create this kind of grid?

slemmon
15 Jan 2014, 11:02 PM
While the convert method doesn't pass the store as a param it does pass the record being evaluated and the record has a store property I suspect you can use to your advantage:
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Model-property-store