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

GridGroupFooterItems and javascript

4 Answers 288 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 27 Jun 2008, 09:26 PM
I'm using the RadGrid as a worksheet.  On each row item, I have a series of textboxes in GridTemplateColumns and at the end a GridBoundColumn that has Aggregate="sum" so that I can have a grid group footer of the subtotal of total of each row.

The client wants the totals to update whenever the value of a textbox changes without submitting the page.  I've figured out the javascript to change the total column, but I'm stumped as to how to change the values of the grid group footer item and the footer item.

I can get the ClientID of the GridTableCell that contains the totals at the ItemDataBound event, but I won't have the complete list of ClientIDs until after it's finished.  I thought I'd be able to loop through the grid items in the PreRender event, but the GridGroupFooterItems don't show up there.   

Does anyone have an idea on how to accomplish this?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jun 2008, 05:03 AM
Hello Steve,

Check out the CodeLibrary sample provided in the link below, which explains a similar scenario using RadNumericTextBox.
Refresh footer values in RadGrid client-side using RadNumericTextBox

You can also go through the following online demo.
RadNumericTextBox for RadGrid Footer Totals

Thanks
Shinu.
0
Steve
Top achievements
Rank 1
answered on 08 Jul 2008, 10:15 PM
Unfortunately, your provided solution doesn't work with my scenario.  The good news is that I've pretty much have it figured out with only one small problem.  I can't access the label that holds the grand total.

I'll recap here as briefly as possible. 
Each grid row has 4 template columns with radtextboxes  in each and it has a 5th templated column that contains a label in the item template and a label in the footer template.

The last column is a GridBoundColumn whose visible property is set to false and it's only purpose is to provide aggregate group and footer totals.

The reason for the two "Total" columns is that the bound column doesn't have IDs for its cells, so at ItemDatabound, I have to loop the GridGroupFooterItem and the GridFooterItem looking for the text "sum" in the tablecell collection and copy the text to the previous tablecell (column 5) as well as add an event attribute "onDblClick" to it.  Now this tablecell has a clientID that I can access and fire it's event when the onBlur event is fired from the radtextboxes.

For the GridFooterItem I do a similar bit of code, but I have to add a label control to the tablecell instead of just the text because otherwise the TD won't have a a clientID.  I think the clientID is only assigned if it has an event bound to it?

This is some Rube Goldburg coding at its finest, but it works and my javascript will total up the text boxes on each row when one of them is changed and it will fire the onDblClick event for the (visible) Total label that passes the clientIDs of all the GridGroupFooter Total label controls to a js function to loop through and total the values. 

So I got everything working except that I can't pass the Grand Total to the label in the tablecell in the footer template.  I view the source and the label is there, but I can't access it.  I don't know if this is because the control is dynamically added or not.

I'd use a static label control in the footer template of column 5, but while I can find it in the codebehind and assign it a value...it doesn't show up on the rendered grid.  My suspicicion is that this is because of the GridBoundColumn and the use of aggregate functions with it.

Sorry, but that was as brief as I could get with this screwy situation.

So what's up with the grid footer, footer templates and grouping?  Can I only use GridBoundColumns when using Grouping?  This would be a lot simpler if the GridBoundColumn used labels/spans with clientIDs that would make it javascript friendly.

Does anyone have any suggestions?


0
Bodevain Svensson
Top achievements
Rank 1
answered on 09 Jul 2008, 06:57 AM
I hope that I followed your idea here. How about passing the client id of the label inside the column footer from the server and then designating the control on the client to change its value with javascript? This seems like a doable solution for me as I did something similar in one of my previous projects. I used the project from this thread for reference.

Bodevain
0
Steve
Top achievements
Rank 1
answered on 09 Jul 2008, 06:18 PM
Hey, Thanks!!!  That put me on the path.  At first I only glanced at the code and saw that it looked a lot like the code I was using.  One major difference as I soon found out.....span tags don't show up when you loop through document.forms[0].elements which is what my javascript was doing.

Using document.getElementsByTagName was a Godsend.  Thank you!
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Bodevain Svensson
Top achievements
Rank 1
Share this question
or