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

[Solved] Getting Total in Footer with Filtering

3 Answers 144 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.
Josh Pollard
Top achievements
Rank 1
Josh Pollard asked on 09 Dec 2010, 06:41 PM
I looked at your example that shows how to put a total in a grid footer, located here http://demos.telerik.com/aspnet-mvc/grid/headerfootertemplates

The problem is that your example doesn't support filtering. I want to be able to use the built-in filtering, but to also be able to display a total column at the bottom of the grid for whatever data is actually being displayed. Do you have any ideas on how I could do this?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 10 Dec 2010, 10:42 AM
Hello Josh,

In order to achieve the requested functionality you should manually filter the data used to calculate the total value. I have attached a small sample which demonstrates possible  implementation.

Regards,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Josh Pollard
Top achievements
Rank 1
answered on 10 Dec 2010, 07:33 PM
Thank you! That did indeed solve it for me. 
0
Greg
Top achievements
Rank 1
answered on 15 May 2012, 11:46 PM
This question is a little old, but there is a jQuery solution to this for anyone interested ...

Add a label to a column footer that will contain the filtered value ... we'll call it "subTotal"

.FooterTemplate("<label id='subTotal'></label>")

Add a clientEvent OnDataBound to the grid

.ClientEvents(events => events.OnDataBound("onDataBound"))

You'll need to set a variable 'hr' with a default value.  This worked for me ... the $(document).ready() makes sure its set to the default value on page load

var hr = 0.00;
  $(document).ready(function () {
    hr = 0.00;
 });

In the OnDataBound  function, you grab the cells value using the jQuery.each(). The hr = 0.00; will reset for each bind.  We then set the text value of the label to the variable hr.

Now when you filter the grid, the function will iterate through the available cell values, add them up and show the filtered results

function onDataBound(e) {
    hr = 0.00;
    $("#AddClassStudentHours tbody > tr").each(function () {
         var tr = this;
         var dcells = tr.cells;
         hr = parseFloat(hr) + parseFloat(dcells[3].innerHTML);
});
 
$("#subTotal").text(parseFloat(hr).toFixed(1));
Tags
Grid
Asked by
Josh Pollard
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Josh Pollard
Top achievements
Rank 1
Greg
Top achievements
Rank 1
Share this question
or