0

I am getting Month, Target, Target1 values are getting from webservice available in store. I want to calculate the total value and insert the total field value in the same store.

I am doing this for calculation but I don't know how to insert the total value into the total field. Can anybody tell me how to do this?

chartstore.each(function (rec) {                   
    total=parseFloat(rec.get('target'))+parseFloat(rec.get('target1'));
});

Month Target Target1   Total

 Jan    25     25       50
 Mon    50     50       100
Illidanek
  • 996
  • 1
  • 18
  • 32
mohan
  • 13,035
  • 29
  • 108
  • 178

2 Answers2

2

You should use convert function in your model for total field like below

     {
        name : 'total',
        convert : function( value, record ) {
                       var totalValue = record.get('Target') + record.get('Target1');
                       return totalValue;
        }   
        type: 'number'
    },
Naresh Tank
  • 1,569
  • 10
  • 23
0

You can add a total field in model of your store which would be hidden.

chartstore.each(function (rec) {

                   total=parseFloat(rec.get('target'))+parseFloat(rec.get('target1'));
                   /* Here set the total field,like store.getAt(index).total with the above total value*/

});

I have not tested this.But I think it should work.

Dev
  • 3,922
  • 3
  • 24
  • 44