Skip to main content
April 30, 2007
Answered

How to page break at each department and calculate department totals

  • April 30, 2007
  • 3 replies
  • 520 views
I have a stored procedure that queries our sql db and returns Employee name, their Department, and a few other calculations. I use CFDocument to create a table and display the results. Here's the code that does that (see below) What I need to do is figure out how to create a page break after I display a total for each column for each department. So my questions are

1. How do I insert a page break after the end of each department
2. Just above the page break, how do I calculate the totals for that the department and display them?

<cfdocument format="pdf">
<table width="650" border="1">
<cfoutput query="getResults">
<tr>
<td>#EmpName#</td>
<td>#Dept#</td>
<td>#JobType#</td>
<td>#NonBill#</td>
<td>#NonBillMeter#</td>
<td>#NumberFormat((NonBillPercent*100),.00)#</td>
<td>#Bill#</td>
<td>#BillMeter#</td>
<td>#NumberFormat((BillPercent*100),.00)#</td>
</tr>
</cfoutput>
</table>
</cfdocument>
    This topic has been closed for replies.
    Correct answer Dan_Bracuk
    If I remember correctly, the tag you want is cfdocumentitem. You also want to check out the group attribute of cfoutput.

    Details are in the cfml reference manual. If you don't have one, the internet does.

    3 replies

    April 30, 2007
    I'm not sure I follow you. Can you post a sample of your output?
    April 30, 2007
    April 30, 2007
    If you will notice, in my original post I output the last department's total right before the </table> tag
    April 30, 2007
    Yes, I noticed that and tried the code, but I'm not sure why, but it just adds a row at the every end of the page, instead of throughout at the end of each department. Any Advice?
    Dan_BracukCorrect answer
    Inspiring
    April 30, 2007
    If I remember correctly, the tag you want is cfdocumentitem. You also want to check out the group attribute of cfoutput.

    Details are in the cfml reference manual. If you don't have one, the internet does.
    April 30, 2007
    You're going to need a variable to store your running total in, and a variable that contains the current department. I assume your query does an ORDER BY dept. The code below shows how to do the department totals.
    April 30, 2007
    I'm close. I've got it calculating the department sub total, but I can't seem to display it below the last row for the department. Right now, I have a"running total" that shows the subtotal on each line as it increments. How do I just display the subtotal as the last row of the table, or even just below the table.