Grid column aggregate when datasource passed into Grid declaration? No Ajax

1 Answer 38 Views
Grid
Mark
Top achievements
Rank 1
Mark asked on 30 Oct 2024, 05:27 PM

Is it possible to sum a column without using Ajax in the datasource?

@(Html.Kendo().Grid<myModel>(myEnumerableViewModel )
.Name("myGrid")
.Columns(c =>
{
c.Bound(x => x.myColumn);
})
)
Mark
Top achievements
Rank 1
commented on 31 Oct 2024, 01:28 PM

Nevermind. I figured it out.

1 Answer, 1 is accepted

Sort by
1
Accepted
Mihaela
Telerik team
answered on 31 Oct 2024, 04:13 PM

Hello Mark,

You you bind the Grid to local data and still configure the aggregates. For example:

@(Html.Kendo().Grid(Model)
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.myColumn).ClientFooterTemplate("Total: #=sum#");
    })
    .DataSource(dataSource => dataSource        
        .Ajax()
        .ServerOperation(false)       
        .Aggregates(aggregates =>
        {
            aggregates.Add(p => p.myColumn).Sum();
        })
     )
)

Here is a REPL sample for your reference: 

https://netcorerepl.telerik.com/QolOxFbq10rcSB3833

I hope that helps.

Regards,
Mihaela
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Mark
Top achievements
Rank 1
commented on 01 Nov 2024, 03:12 PM

Thank you. I had tried that but I did not include ServerOperation(false) so the sum was always zero.
Mihaela
Telerik team
commented on 01 Nov 2024, 03:23 PM

Thank you for your update! It is great that you managed to achieve the desired result :)
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Mihaela
Telerik team
Share this question
or