PDA

View Full Version : Adding a total to a grid


ABC123

Bill Griffin
10-01-2009, 10:27 AM
Just wanted to share something I discussed with Selwyn yesterday. I wanted to add a total to a colum on my grid. Nothing fancy (although it could be), but fairly easy to do.

In the OnBeforeExistingRowsRender grid event set the summary value to zero:
e.rtc.mysummaryvalue = 0

In the OnExistingRowRender grid event place your calculation:
e.rtc.mysummaryvalue = e.rtc.mysummaryvalue + e.rowData.data("Total") "Total" is the grid fieldname

In the OnAfterExistingRowsRender grid event is where you would set the e.html property

htmltxt = "<tr><td colspan=\"5\">&nbsp;</td><td>" +"Page summary value is: " + e.rtc.mysummaryvalue + "</td></tr>"
e.html = htmltxt

Hopefully this will prevent some head scatching when trying to figure out how to do this.

rleunis
10-01-2009, 02:54 PM
This is already possible without coding:

use the summary values at fieldlevel in your grid. See PICS.

But maybe I did not understand your entry. regards,Ron

Bill Griffin
10-01-2009, 03:14 PM
As far as I no, the summary total is for the whole grid, no? I needed a total of each page...

rleunis
10-01-2009, 03:25 PM
1) Not sure what you mean with "total of each page"...

2) Problem is I cannot test because on this PC I use only SQL Databases. The example i showed earlier only has 1 record in a DBF table. And I just discovered that with SQL DB's the summary values do not seem to work..

If you are using DBF maybe you could try it yourself and let us know if it works. I recall the total is given only for the records showed in the grid displayed (on a page), not all totals of all records in your DBF table. But am not sure now.

I am a bit worried why ad 2) does not seem to work with SQL DB's, though..I will test some more with this.

regards, Ron

rleunis
10-01-2009, 03:38 PM
Ok tested it.

Good thing it also works with SQL DB's.

Bad news is that it only TOTALS ALL entries in the grid. Thats why the total will only display at the last records of the grid.

So your entry is added value (;-] get it?) for when you want a total of only those records which are displayed in the grid at currrent page.

thanks and sorry for polluting this entry, Ron

Bill Griffin
10-01-2009, 07:59 PM
Ok tested it.

Good thing it also works with SQL DB's.

Bad news is that it only TOTALS ALL entries in the grid. Thats why the total will only display at the last records of the grid.

So your entry is added value (;-] get it?) for when you want a total of only those records which are displayed in the grid at currrent page.

thanks and sorry for polluting this entry, Ron

No problem. That is why I posted it. I guess I should have been a little more clear as to the PAGE total vs the TOTAL total.

Marlon
12-28-2009, 07:59 PM
I tried the above solution and it does work in SQL DB but.... im having problem with computed columns..

hope you can try and let us know if there is a solution at present

Bill Griffin
12-29-2009, 07:38 AM
It works fine using a calc field, although I am using dbf's. So maybe someone else using SQL can jump in.

Bill Griffin
12-29-2009, 07:59 AM
I just checked using a SQL calc field and the above works fine. Not sure what to tell you other than check your code again..

Perhaps you could post the code and the sql select statment you are using to define your calc?

Marlon
12-29-2009, 09:05 PM
I really didnt put any code, just the GUI.
the columns quantity,Less and Subtotal have summary option of Total, it works on quantity but not in Less and Subtotal, the difference is quantity is not computed field.

I have attached the screen:

Thanks

Marlon

Bill Griffin
12-30-2009, 07:27 AM
Oh, You are talking about using the summary values for grid totals (not what this thread was about - see 1st post). I tried that as well and seems to work fine on a calclated field. See the attached, there are 3 column totals Ext is a calc field, and as you can see it looks fine.

It is unclear from your screen shot what field you have selected and what you are showing on the grid.

Charles Hoens
01-05-2010, 01:12 PM
Could I join this post with an issue? I have a radio button (logical field) in a dbf. I'd like to have a total at the top (or bottom) of the grid telling me how many are true (or false).

I'm thinking that there may be more items like this i.e. counts of records, etc. not just summaries of numeric fields.

Charlie

Bill Griffin
01-05-2010, 03:30 PM
read post 1 above and in the OnExistingRowRender event put something like this

if e.rowData.Data("Tf") = .f.
e.rtc.mysummaryvalue = e.rtc.mysummaryvalue + 1
end if

The "Tf" would be your fieldname and test for the trues or false

You will also have to play around with the formatting in the OnAfterExistingRowsRender event as well

This will put a total on every page.

Hope that sparks your imagination.