Building a Scorecard Report:
Tables are formatted by passing a StringBuilder through several formatting functions for the various steps. You can override the formatting at any of these steps:
BeginTableRow
FormatReportTableHeader
FormatReportTableRow
FormatReportTableFooter
EndTableRow
Most of the time you can accomplish whatever table manipulation you need to by just using FormatReportTableHeader and FormatReportTableRow. To create a scorecard report, you will need to override FormatReportTableRow. For each row returned in the data table for this report, Harvest will call this method to apply any formatting changes to it.
In the case of scorecard reports like the one you mentioned, it is accomplished by writing the SQL query to return EXACTLY 1 ROW, then applying html formatting inside the table row with FormatReportTableRow.
Here's the formatting for the BlogPostSummary report you mentioned. Notice that the FormatReportTableHeader is overridden to return nothing, so that the table can be declared and styled inside the FormatReportTableRow:
public override void FormatReportTableHeader(object dataSource, StringBuilder sb)
{
}
public override void FormatReportTableRow(DataRow currentRow, bool isAlternateItem, int counter, StringBuilder sb)
{
int commentCount = Int32.Parse(currentRow["Comments"].ToString());
int views = Int32.Parse(currentRow["Views"].ToString());
int RSSviews = Int32.Parse(currentRow["RSS Views"].ToString());
int totalViews = views + RSSviews;
int trackbacks = Int32.Parse(currentRow["Trackbacks"].ToString());
sb.AppendFormat(
@"
<table class=""ReportingGrid"" border=""1"" cellpadding=""3"" cellspacing=""0"" rules=""all"">
<tr>
<td>
<div style=""width: 48%; float: left; padding:3px 5px 3px;"">
<b class=""formatted"">{8}</b><br />
<b class=""formatted"">{6}</b><br />
<b class=""formatted"">{1}</b> web views <br />
<b class=""formatted"">{2}</b> RSS views<br />
<b class=""formatted"">{5}</b> total views<br />
</div>
<div style=""width: 48%; float: right; padding:3px 5px 3px;"">
Posted by <b class=""formatted"">{9}</b><br />
Posted on <b class=""formatted"">{7}</b><br />
<b class=""formatted"">{0}</b> comment(s)<br />
<b class=""formatted"">{3}</b> trackbacks <br />
<span style=""line-height: 2.5em;"">Rating: </span><b class=""formatted"">{4}</b>
</div>
</td>
</tr>
</table>"
, Library.Helper.FormatObject(commentCount)
, Library.Helper.FormatObject(views)
, Library.Helper.FormatObject(RSSviews)
, Library.Helper.FormatObject(trackbacks)
, Library.Helper.FormatObject(currentRow["Rating"])
, Library.Helper.FormatObject(totalViews)
, currentRow["Post Title"]
, Library.Helper.FormatObject(currentRow["Publish Date"])
, currentRow["Blog Title"]
, currentRow["User"]);
return;
}
...there are a number of style classes you can make use of, or you can add your own to screen.css. You might want to poke around with view source on some of the formatted reports to see the specific styles they are using.
- Andrew