This is a migrated thread and some comments may be shown as answers.

[Solved] Subtract Aggregate Result from Model Field

3 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ezequiel
Top achievements
Rank 2
Ezequiel asked on 11 Sep 2012, 12:11 PM
Hello.

I have a page with a Model with some data and then a editable grid with some items of this Model. The Grid data is Ajax binded.

columns.Bound(c => c.Price) .Width(85)
.Aggregate(aggregates => aggregates.Sum())
.ClientFooterTemplate("<#= $.telerik.formatString('{0:0,0.0}', Sum)#>")
 .HtmlAttributes(new { style = "text-align:right" });

I have an aggregate footer which sums one of the columns, but I need to subtract this total from a field in the Model.

it would be something like  (the above sum - Model.Cost).
columns.Bound(p => p.Description).FooterTemplate(() =>
{%>
            Total:<%= string.Format("{0:c}", (###Aggregate Sum###  -  Model.TotalCost)%>
 <%}); 
when I change some price, I would need to reload the value of this last calculation.
How I put the Aggregate Sum in that calculation?

Thanks,
Ezequiel

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 14 Sep 2012, 11:49 AM
Hello Ezequiel,

When using Ajax binding you should use ClientFooterTemplate instead of Template since the aggregate will not be available on the server. To subtract a value passed to the view, you could use the following approach:

ClientFooterTemplate("Total: <#= $.telerik.formatString('{0:c}',Sum - " + Model.TotalCost + ")#>"
Regards,
Daniel
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Ezequiel
Top achievements
Rank 2
answered on 14 Sep 2012, 02:12 PM
Thanks, that worked fine.

And what about if the Grid is BatchEditing, how can I update the total before submitting the changes?

thanks again.

Ezequiel
0
Daniel
Telerik team
answered on 19 Sep 2012, 11:49 AM
Hello again Ezequiel,

I am afraid that this is not supported. The data needs to saved and the Grid to be rebound in order to show the updated total.

Regards,
Daniel
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
Grid
Asked by
Ezequiel
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Ezequiel
Top achievements
Rank 2
Share this question
or