Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
375
custom column summary based on other column summaries.
posted

Hello,

I am using the MVC wrapper for the iggrid in my razor view and I am wondering if it is possible to create a custom column summary based on other column summaries. For example, say I have 3 columns: Price, Cost, and an unbound column called Margin. The Margin is just the Price minus the Cost all divided by the Price. I can get the individual row margins to calculate correctly simply with a formula in the unbound column but I can't figure out how to get the total margin for the entire dataset. All the examples of custom summaries I have seen only use the data from the column the custom summary is for. I need to get the totals from the Price and Cost columns in order to calculate my total Margin which I can't figure out if I can do.

thanks,

Andrew

 

Here is my relevant code:   

<script type="text/javascript">

function CalcMargin(data) {

var i, l = length, margin= 0; 

for (i = 0; i < l; i++) {

--Don't really know how to access other columns--       

}

return margin;}

</script>

             

//summaries

features.Summaries().Type(OpType.Local).ColumnSettings(settings =>

{settings.ColumnSetting().ColumnKey("Price").SummaryOperands(builder =>

{builder.SummaryOperand().Active(true).Type(SummaryFunction.Sum).RowDisplayLabel("Total");});

settings.ColumnSetting().ColumnKey("Cost").SummaryOperands(builder =>

{builder.SummaryOperand().Active(true).Type(SummaryFunction.Sum).RowDisplayLabel("Total");});

settings.ColumnSetting().ColumnKey("Margin").SummaryOperands(builder =>

{builder.SummaryOperand().Active(true).Type(SummaryFunction.Custom).RowDisplayLabel("Total").SummaryCalculator("$.proxy(CalcMargin, this)"); });

});

Parents Reply Children