|
1 |
| -using System; |
| 1 | +using Griddly.Mvc.Linq.Dynamic; |
| 2 | +using System; |
2 | 3 | using System.Collections;
|
3 | 4 | using System.Collections.Generic;
|
4 | 5 | using System.Linq;
|
@@ -52,9 +53,31 @@ public static MvcHtmlString Griddly(this HtmlHelper htmlHelper, GriddlySettings
|
52 | 53 |
|
53 | 54 | public static MvcHtmlString SimpleGriddly<T>(this HtmlHelper htmlHelper, GriddlySettings<T> settings, IEnumerable<T> data)
|
54 | 55 | {
|
| 56 | + // TODO: figure out how to get this in one query |
| 57 | + foreach (GriddlyColumn c in settings.Columns.Where(x => x.SummaryFunction != null)) |
| 58 | + PopulateSummaryValue(data, c); |
| 59 | + |
55 | 60 | return htmlHelper.Griddly(new GriddlyResultPage<T>(data), settings, true);
|
56 | 61 | }
|
57 | 62 |
|
| 63 | + static void PopulateSummaryValue<T>(IEnumerable<T> data, GriddlyColumn c) |
| 64 | + { |
| 65 | + // NOTE: Also in QueryableResult.PopulateSummaryValue |
| 66 | + switch (c.SummaryFunction.Value) |
| 67 | + { |
| 68 | + case SummaryAggregateFunction.Sum: |
| 69 | + case SummaryAggregateFunction.Average: |
| 70 | + case SummaryAggregateFunction.Min: |
| 71 | + case SummaryAggregateFunction.Max: |
| 72 | + c.SummaryValue = data.AsQueryable().Aggregate(c.SummaryFunction.Value.ToString(), c.ExpressionString); |
| 73 | + |
| 74 | + break; |
| 75 | + |
| 76 | + default: |
| 77 | + throw new InvalidOperationException(string.Format("Unknown summary function {0} for column {1}.", c.SummaryFunction, c.ExpressionString)); |
| 78 | + } |
| 79 | + } |
| 80 | + |
58 | 81 | public static MvcHtmlString Griddly(this HtmlHelper htmlHelper, GriddlyResultPage model, GriddlySettings settings, bool isSimpleGriddly = false)
|
59 | 82 | {
|
60 | 83 | if (htmlHelper.ViewData["_isGriddlySettingsRequest"] as bool? != true)
|
|
0 commit comments