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

[Solved] Sum Aggregate on Dynamic DataTable

0 Answers 32 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.
Stuart Forman
Top achievements
Rank 1
Stuart Forman asked on 17 Oct 2012, 11:08 PM
I have a grid which is loaded from a dynamically built data table with Ajax binding.  The Count(), Min() or Max() aggregate functions work ok with this and I see the aggregate data.  If I try to use the Sum() or Average() aggregate, then I get an error "No method Sum on type System.Linq.Enumerable is compatible with the supplied arguments."

A simplified code code snippet is shown below. This does not work.  However, if I replace Sum with Count, it works perfectly.  Also, if I pass a strongly typed model to the grid instead of System.Data.DataRow it works perfectly.  The column.DataType concerned is type Decimal.

Any thoughts gratefully accepted...

<%=
    Html.Telerik().Grid<System.Data.DataRow>()
            .Name(Model.View + "Grid")
            .Columns(columns =>
            {
                foreach (System.Data.DataColumn column in Model.DataSets[0].Data.Columns)
                {
                    if (column.ColumnName == "Total")
                        columns.Bound(column.DataType, column.ColumnName)
                               .Aggregate(aggregates => aggregates.Sum())
                               .ClientFooterTemplate("Sum: <#= Sum #>");
                    else
                        columns.Bound(column.DataType, column.ColumnName);
                }
            })
            .DataBinding(dataBinding => dataBinding.Ajax()
                    .Select("GetGridData", "AFReport")
             )
%>
Tags
Grid
Asked by
Stuart Forman
Top achievements
Rank 1
Share this question
or