Andrew
Andrew

Reputation: 1120

Kendo UI MVC Grid show aggregate data in footer based on column values

I have a grid with two columns of interest: Dollar Amount, and Status. The status can be either Accepted, Pending, or Rejected for that row's dollar amount

I would like to implement the the aggregate feature to display the total dollars Pending, and the total dollars Accepted.

This is my grid

 @(Html.Kendo().Grid(Model)
          .Name("Grid")
          .DataSource(dataSource => dataSource
              .Ajax()
              .Aggregates(aggregates =>
              {
                  aggregates.Add(p => p.AmountRequested).Sum();
              })
              .Read(read => read.Action("Applications_Read", "MyGrid"))
          )
          .Columns(columns =>
          {
              columns.Bound(c => c.RequestingOrg).Width(150);
              columns.Bound(c => c.Telephone).Width(150);
              columns.Bound(c => c.Email).Width(150);
              columns.Bound(c => c.ContactName).Width(150);
              columns.Bound(c => c.ContactTel).Width(150);
              columns.Bound(c => c.AmountRequested).Width(150)
                  .Format("{0:C}")
                  .ClientFooterTemplate("<div> Pending: #= sum#</div><div>Approved: #= sum#</div>");
              columns.Bound(c => c.TotalGoal).Width(150)
                  .Format("{0:C}");
              columns.Bound(c => c.Sponsor).Width(150);
              columns.Bound(c => c.Status)
                  .Filterable((filterable => filterable.UI("statusFilter")))
                  .Width(150);
          })
          //.Scrollable(s => s.Enabled(true).Height("auto"))
          .Pageable()
          .Sortable()              
          .Resizable(resize => resize.Columns(true))
          .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
          .HtmlAttributes(new {style = "height: 100%;"})
          .Events(events => events.Change("GetSelectedRow"))
          .Filterable(filterable => filterable
            .Extra(false)
            .Operators(operators => operators
                .ForString(str => str.Clear()
                    .IsEqualTo("Is equal to")
                ))
          )
    )

How can I specify in my ClientFooterTemplate to calculate the sum based on the value of another column?

Upvotes: 1

Views: 3868

Answers (1)

Amal Dev
Amal Dev

Reputation: 1978

You can call JS functions inside the template and do processing inside that.

.ClientFooterTemplate("<div> Pending: #= computeSumPending() #</div><div>Approved: #= computeSumApproved()#</div>");

Refer solution for similar question in SO here - Kendo - Grid - Custom Aggregate in FooterTemplate

Upvotes: 1

Related Questions