TreeTable math operation of Group values

Hi,

I have a TreeTable with the following configuration

       var dtable = webix.ui({
                               container:divid,
                               view:'treetable',
                               id:'data',
                               columns:[
                                    { id:"Tagname",width:150, sort:"string",
                                      template:function(obj, common){
                                                  if (obj.$group) return common.treetable(obj, common) + obj.Tagname;
                                                  return '';}},
                                    { id:"Dat", header:"Date", width:180, sort:"string"},
                                    { id:"Samples", header:"samples", width:100, sort:"int",css:{"text-   align":"right"},format:webix.Number.numToStr({groupDelimiter:",",groupSize:3,decimalDelimeter:".",decimalSize:0})},
                                    { id:"Defects", header:"Defects", width:100, sort:"int",css:{"text-align":"right"},format:webix.Number.numToStr({groupDelimiter:",",groupSize:3,decimalDelimeter:".",decimalSize:0})},
                                    { id:"Dpm", header:"Dpmo", width:100, sort:"int",css:{"text-align":"right"},format:webix.Number.numToStr({groupDelimiter:",",groupSize:3,decimalDelimeter:".",decimalSize:0})}
                               ],
                               autoConfig:true,
                               data: series,
                               drag:'order',
                               headerRowHeight: 24,
                               rowHeight:22,
                               resizeColumn:true,
                               'export':true,
                               scheme:{
                                        $group:{
                                                by   :"Tagname",
                                                map  :{
                                                        // open:["1", "string" ],
                                                         Tagname:["Tagname"],
                                                         Samples:["Samples","sum"],
                                                         Defects:["Defects","sum"],
                                                         Dpm: [function(obj){
                                                                return obj.Defects*1000000/obj.Samples;
                                                              }]

                                                      }
                                               }
                                      },
                               height:500,
                               width:700
                             });

I need to get a value for column Dpm which is (sum of Samples)*1000000/(sum of Defects) in that group. In the above example, the value returned is the first row values of the group instead of the sum of the group column.

You can create your own Group operator
http://docs.webix.com/desktop__custom_functor.html#addinganewfunctor

webix.GroupMethods.mysum = function(prop, data){
                var sumA = 0;
                var sumB = 0;
                for (var i = data.length - 1; i >= 0; i--) {
                    summA += data[i].Samples;
                    summB += data[i].Defects;
                };
                return summA*1000000/summB;
};

and use

Dpm: ["Dpm",  "mysum"]

Thanks. What is prop used for?

With Regds
Ashok

prop is a data getter method
Check the next code snippet

webix.GroupMethods.mysum = function(prop, data){
                var sumA = 0;
                for (var i = data.length - 1; i >= 0; i--)
                    summA += prop(data[i]);

                return summA;
};

//...

Dpm: ["Samples",  "mysum"]  //summ of Samples

Here prop(data[i]) will return data[i].Samples.
In above code snippet mysum logic can be applied to any column, based on parameter in group configuration. It forks for single parameter only. As, in you case, two parameters involved - prop can’t be used, and names of columns need to be hardcoded.

“prop” can be used for complex sum calculation

Dpm: [funtion(){
    return a.Samples * b.Count;
},  "mysum"]  //summ of Samples

with such code, prop(data[i]) will return a.Sample * b.Count, so cell will contain kind of “grand total”

ok. Thanks