Report writer
ReportWriterControlPaginated, grouped reports from a Crystal-style XML definition, with a group tree, search, print and export.
Overview
ReportWriterControl renders a ReportDefinition as paginated HTML pages with Crystal-style group headers
and footers, a clickable group tree and drill-down tabs. The definition is built in code or loaded from a Crystal XML export by
CrystalXmlReportLoader, which reads the tables, joins, groups, formulas and field placement. The control has no data
access of its own: the host registers IReportDataExecutor, IReportSessionContext and
IReportPickListProvider in dependency injection, and optionally an IReportExporter. The toolbar prints,
exports, searches the report text and zooms the pages.
Examples
#Model costs by community, model, group and phase
The bundled XML defines four group levels, each with a sum in its footer. Pick a model and a community and press Run; the report loads on arrival too. This site's data executor ignores the SQL in the definition and synthesises rows from the demo data, so every choice returns a report. Open the group tree on the left to jump between groups, or search the report text from the toolbar.
No groups available.
Documentation
ReportWriterControl parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
ShowChrome | bool | true | Toolbar, group tree, tabs and the parameter dialog. False drops the bare page area into a host that has its own UI. |
UsePositionedLayout | bool | false | Renders with the Crystal band and object geometry instead of table columns, in ShowReportAsync, the parameter dialog and refresh. |
PdfViewerComponentType | Type? | null | The PDF viewer component used for .rpt output, for trimmed hosts that bring the Documents package. |
PromptOptionalParameters | bool | false | Includes optional parameters in the parameter dialog. |
OnClose | EventCallback | — | The toolbar's Close button. Unset with ShowChrome on, the button is still there and does nothing. |
OnPageTitleChanged | EventCallback<string> | — | Raised by ShowReportAsync with the report's file name without extension, for a host's title bar. |
Methods
| Method | Inputs | Returns | Description |
|---|---|---|---|
ShowXmlReport() | string xmlFilePath | Task | Loads a Crystal XML export through CrystalXmlReportLoader, runs it with the given values and renders it; positioned keeps the band geometry. What this page calls. |
ShowReportAsync() | string file | Task | The unified load for an .rpt or .xml path: prompts for required parameters the seeds do not supply, raises OnPageTitleChanged, seeds a parameter named DivisionID from the session context, and treats seeds named Filter:Table.Field as field filters. |
ShowSqlReport() | ReportDefinition definition | Task | Executes a definition built in code through IReportDataExecutor and renders it. Session parameters listed in ReportOptions are filled in when the SQL names them and the caller did not. |
ShowDataTableReport() | string title | Task | Renders a table you already have as a report. |
ShowCrystalReport() | string rptFilePath | Task | A native .rpt file: needs IReportExporter, which renders it to PDF for the viewer. Logs a warning and shows nothing without one. |
ShowDesignerReport() | ReportDesignerDocument document | Task | Runs a designer document as a snapshot, subreports included, without saving it. |
ExportCrystalReport() | string format | Task<byte[]?> | The loaded .rpt as PDF, Excel, Word, RTF or CSV bytes through IReportExporter; null when none is registered. |
Print() | — | Task | Opens the browser's print dialog for the rendered report. |
Clear() | — | void | Clears the report and its tabs. |
GoToPage() | int pageNum | void | Shows that page, 1-based, of the active tab. |
SwitchTab() | int tabIndex | void | Makes that tab active. |
CloseTab() | int tabIndex | void | Closes a drill-down tab; the main report at index 0 cannot be closed. |
OpenDrillDown() | FxGroupNode node | Task | Opens, or switches to, a tab that re-queries with the node's path as an extra filter and shows the detail columns. |
SetXmlSource() | string xmlFilePath | void | Tells the control which XML a definition came from, so drill-down tabs can re-parse it. Needed only before a direct ShowSqlReport. |
State
| Property | Type | Default | Description |
|---|---|---|---|
IsLoading | bool | false | True while a report is being loaded or run. |
ReportLoaded | bool | false | True once a report has rendered. |
StatusMessage | string | "Ready" | The text in the status area. |
ErrorMessage | string? | null | The last failure, shown in place of the pages. |
Tabs | List<ReportTab> | new() | Open tabs; index 0 is the main report, drill-downs follow. |
ActiveTabIndex | int | 0 | The tab on display. |
GroupTree | List<FxGroupNode> | — | The active tab's group tree. |
DefinitionPostProcessor | Action<ReportDefinition>? | null | Settable. Runs on every definition the control builds for a drill-down tab, so a host repeats there what it did to the main definition. |
Host services, resolved from dependency injection
| Property | Type | Default | Description |
|---|---|---|---|
IReportDataExecutor | DataTable Execute(string sql, IDictionary<string, object>? parameters) | required | Runs the SQL the loader builds and returns a DataTable. The host decides the data layer. |
IReportSessionContext | object? Get(string parameterName) | required | Turns a session parameter name into a value, for the names listed in ReportOptions.SessionAutoInjectParameters. |
IReportPickListProvider | GetPickList(ReportParameter) / GetPickList(string) / HasPickList(string) | required | Pick-list values for the parameter dialog, by ReportParameter (preferred, runs its PickListSql) or by name. EmptyReportPickListProvider ships for hosts without lists. |
IReportViewerSettings | Task<int> GetZoomLevelAsync() / Task SetZoomLevelAsync(int) | required | Per-user zoom persistence; InMemoryReportViewerSettings ships as the default. |
IReportExporter | LoadReport, SetParameters, ExportToPdf / ExportToExcel / ExportToWord / ExportToRtf / ExportToCsv | registered | A Crystal Reports engine for native .rpt files only. Blazor cannot inject a missing service, so a host without Crystal registers a no-op. |
ReportOptions | class | singleton | Singleton settings: SchemaPrefix (default dbo), SessionAutoInjectParameters, MaxRowsPerReport (100,000; 0 is unlimited), EagerGroupColumnsInMainQuery. |
The toolbar's Print / Save as PDF uses the browser's print dialog, and its HTML, CSV and Excel data exports are the control's own
(ReportNativeExport), so none of them need IReportExporter. This site registers
ReportOptions with an empty schema prefix and DivisionID and UserId as session parameters, its own data executor and
session context, the empty pick-list provider, the in-memory viewer settings and a no-op exporter.