This project is read-only.

aggregation function

Jan 17, 2014 at 7:26 AM
Hi2all,
For the first Big thanks for awesome tool.
How can i use aggregation function like a sum, avg, count in the grid?
I have field with Sum field value in multipage grid. I wanted to calculate sum of Sum field in all pages and with appled filters. At now i "hacked" some sources and added two function to GridBase and use it in PrepareItemsToDisplay() function.
Then i ise it in
@Html.Grid(Model).GetSumForItems(item => (filteredsum += item.invoice_sum.Value)).GetCountForItems(item => (filteredcount++))
But how can i do this without hacking any functions?
Jan 18, 2014 at 2:33 PM
Hi
You can create own class that will represent grid row like:
public class MyGridRow
{
       public int Sum {get; set;}
}
Then create an collection of this items and pass to the grid:
return View( myItems.Select(item => new MyGridRow { Sum= /* expression to get sum for each row */ }) );
View:
@Html.Grid(Model).Columns( columns=> { 
      columns.add(row => row.Sum);
      //other columns
})