I have an UltraWebGrid that I am exporting to a PDF using the UltraWebGridDocumentExporter. This grid contains hundreds of rows of data that will span multiple pages in the PDF. Is there a way to print the column headers on every page?
Hi,
I have been thinking about this problem as well.
It would seem that there is a simple solution that could be implemented in a future update to the UltraWebGridDocumentExporter. This would be to store the header information when outputing the header the first time, then to provide a method to the UltraWebGridDocumentExporter to output the header on request (i.e. insertHeader()).
From checking you can get the row number for the row being processed, so it should be possible to work out how many rows you are getting per page and then call insertHeader() to insert the header into the output.
Hey Guys,
I hope this can help you all out. I have a method that you can use to manually create a Report object by walking the WebGrid. Unfortunately, having the Column Headers repeating on each page is not possible through interacting directly with the WebGridDocumentExporter or through the way it exposes the Report objects from its various events (because it is too late in the cycle).
In order to obtain this higher level of granular control, you can always create the Report from scratch. You can also have alot of fun working with the classes to completely customize your Reports.
Try this code out in your applications and feel free to modify it as needed.
This method will take your WebGrid and create a Report that uses ITable to represent your Columns and Rows. Column headers will be repeated on every page thanks to the Header.Repeat = true; property setting (see code below).
Feel free to use and hack this code as you see fit. Enjoy!
/// <summary>
/// Creates a PDF Document by walking a flat WebGrid
/// </summary>
/// <param name="theGrid">This is the Grid that will be walked</param>
/// <param name="theResponse"> This is the current HTTP Response object that will receive the PDF</param>
/// <param name="openInline">Option to show the PDF within the Browser itself OR to present it as a download prompt. </param>
UltraWebGrid theGrid,
{
Report theReport = new Report();
//Table Pattern (think of this as a kind of "Style Sheet" for ITable
theTablePattern.Header.Repeat = true;
theTablePattern.Row.Cell.Background = new Background(Infragistics.Documents.Graphics.Brushes.LemonChiffon);
theTable.ApplyPattern(theTablePattern);
ITableCell theHeaderCell = null;
//Iterate through the Grid Cols and create corresponding headers in the ITable
theHeaderCell = theTable.Header.AddCell();
theHeaderText = theHeaderCell.AddText();
theHeaderText.AddContent(c.Header.Caption);
}
ITableCell theRowCell = null;
//Now create your rows:
theRow = theTable.AddRow();
theRowCell = theRow.AddCell();
theRowText = theRowCell.AddText();
theRowText.AddContent(r.Cells.FromKey(c.Key).Value.ToString());
//Set up the response for publishing the Report:
//Opens in Browser Itself.
else
//Prompts user for a file download.
//Write out to the response.Output Stream and you are done.