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
  • 3595
    posted

    Hello Andrew,

    Thank you for your patience!

    A possible approach regarding your scenario is calculating margin in the controller and passing the result to the view. I have created and attached a sample implementing this solution.

    To achieve the desired behavior I have added a margin property to the model and a method implementing its calculation:

        public class Product

        {

            public int ProductId { get; set; }

            public string Name { get; set; }

            public double Cost { get; set; }

            public double Price { get; set; }

            public double Margin { get; set; }

     

            public Product(string name)

            {

                this.Name = name;    

            }

            public Product() {}

     

            public void SetMargin()

            {

                this.Margin = (this.Price + this.Cost) / this.Price;

            }

     

     

    Then I have used a bound column for the margin in the view grid:

     

    @(Html.Infragistics().Grid(Model).ID("grid1").Width("99%")

    .AutoGenerateColumns(false)

    .Columns(column =>

        {

            column.For(x => x.Name).Width("200px").HeaderText("Name");

            column.For(x => x.ProductId).Width("260px").HeaderText("Id");

            column.For( x=> x.Cost).Width("280px").HeaderText("Cost").DataType("number");       

            column.For(x => x.Price).Width("350px").DataType("number").HeaderText("Price");

            column.For(x => x.Margin).Width("300px").HeaderText("Margin");      

        })

     

    The whole working sample is attached for your reference.

     

    There is also another possible approach for this by using unbound columns, however there currently seems to be an issue with the summary calculations for unbound numeric columns when the grid is defined through the MVC wrapper. I have investigated this issue, and I have asked our engineering stuff to examine this further. Its Development ID number is 150317. The next step will be for a developer to review my investigation and confirm my findings or to offer a fix, or other resolution.

     

    You can also continue to send updates to this case at any time.

    You can view the status of the development issue connected to this case by selecting the "Development Issues" tab when viewing this case on the web site. 

    It is possible however to have a calculated unbound numeric column at the moment by defining the grid in javascript. An html sample illustrating that is attached for your consideration.

    If you have any further questions don’t hesitate to contact me again.

     

     

    igGridSummariesJS.zip
Reply Children