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.
Can it be possible to set up text alignment in the rowcell? For example if i want the 2nd column to have alignment to the right which have currency value and want it all it at proper position. Also how can i make one cell wider than the other?
Thanks,
Rob
you can just write
[yourgridname].Columns.FromKey["ProjectID"].Hidden = false;
in your convert to pdf code..
and it will work...
vatt,
I am not in my programming account so I can't test my thought on your question...
However, I think you will want to hide the column in the 'InitializeLayout' event of the grid. I don't think your code is called when it is needed.
If you need to display the ID on the screen, but do not wish to do so on the report, save the grid to a Session variable and open it up in another grid (maybe hidden). I do this by saving to a Session variable then openning up another window to manage the grid and the report.
Hai.
I used the code that works fine. But I want to hide some columns in pdf(But it is in grid) so I used the following code. But dint work. I want to hide projectid column. How can I Do this? Thanks in advance.
foreach (UltraGridColumn c in theGrid.Columns) { if (c.Key == "ProjectID") c.Hidden = true; theHeaderCell = theTable.Header.AddCell(); theHeaderText = theHeaderCell.AddText(); theHeaderText.Style.Brush = new Infragistics.Documents.Graphics.SolidColorBrush(Infragistics.Documents.Graphics.Colors.White); theHeaderText.AddContent(c.Header.Caption);
Thanks. It works fine.
How can I hide the columns by using this code? I used as shown below but dint worked in pdf. How can I hide the columns?
foreach (UltraGridColumn c in theGrid.Columns) {
//I want to hide projectid column if (c.Key == "ProjectID") c.Hidden = true; theHeaderCell = theTable.Header.AddCell(); theHeaderText = theHeaderCell.AddText(); theHeaderText.Style.Brush = new Infragistics.Documents.Graphics.SolidColorBrush(Infragistics.Documents.Graphics.Colors.White); theHeaderText.AddContent(c.Header.Caption);