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

Total for Rows and Columns

3 Answers 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 19 Apr 2009, 06:20 AM
Hi, I have seen examples for totaling a column and having it display in the footer, but I would also like to be able to add an extra column to the grid that displays a total for the row. Is this possible?

I have 2 different scenarios. The first scenario is that I will autogenerate the columns for the grid and I would like to be able to add an extra column to the grid for which I will total the row across (maybe skipping the first or second column). In the second scenario I would build a dynamic grid and would add the extra column myself.

I am binding the grid to data coming from sql server but I can't add the extra computation on the sql server side.

Are there any examples for this and can it be done? Thanks in advance.



3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Apr 2009, 04:01 AM
Hello Darren,

I guess, using GridCalculatedColumn is best suitable for you in achieving this. GridCalculatedColumn displays a value that is calculated based on one or more fields and an expression that indicates how to calculate the display value. Use the DataFields property to list all the fields that are used to calculate the column value.

[ASPX]
 
<telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double" 
                DataFields="UnitPrice, UnitsInStock" Expression="{0}*{1}" > 
</telerik:GridCalculatedColumn> 

Checkout the following link for demo which demonstrates the usage of GridCalculatedColumn in Telerik RadGrid.
Grid / Calculated Columns

Thanks,
Shinu.
0
kachy
Top achievements
Rank 1
answered on 03 Aug 2009, 02:44 PM
I am trying to do the exact same thing. For an autogenerated radgrid, add a Gridcalculatedcolumn for rows total. My grid works for the initial pageload but I am having following issues:

1. Filter for DateTime and Row Total Gridcalculated column are not working properly. I read in some community article to make the EnableLinqexpressions False for Datetime filter to work properly. If I make EnableLinqexpressions false, radgrid bind does not work.

2. I also want to have some additional functionality in the page: there is a dropdown in the page, if that value changes, get the new strored proc from the database and create a new grid depending on this new stored proc and add the  gridcalculated row total column. On initial pageload, the total column is addtion of all week days, when the dropdown changes, it might be the total of all months.

Darren , did autogenerating column and then adding the calculatedcolumn work properly with filter, sorting etc...

Can anybody please suggest where should I add - which event ( I am adding initially on pageload when its not a postback and then in radgrid_needdatasource event itself, if the mode changes from week to Year) the dynamic column for the radgrid when the dropdown selected index changes and also some suggestions to implement the filter properly?

Thanks.
0
kachy
Top achievements
Rank 1
answered on 04 Aug 2009, 08:22 PM
Everything working fine.

Thanks.
Tags
Grid
Asked by
Darren
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
kachy
Top achievements
Rank 1
Share this question
or