GridX Export Engine
Pluggable export — CSV/JSON/HTML built-in, Excel/PDF plugins via assembly scanning, IGridExporter contract, file/stream/string output
Table of Contents
Overview
The GridX Export Engine provides a pluggable, extensible export architecture that supports multiple output formats from any BeepGridPro instance. Three formats are built-in (CSV, JSON, HTML), while Excel and PDF are provided as stubs that can be replaced by external plugins discovered at runtime via assembly scanning.
The engine is accessible via grid.ExportEngine (an instance of GridExportEngine). It supports output to file, Stream, or string, and respects grouping, filtering, column visibility, and selection state.
GridExportEngine
The GridExportEngine class manages the registry of exporters and coordinates the export pipeline. It provides methods for registration, querying available formats, and performing exports.
| Member | Signature / Type | Description |
|---|---|---|
RegisteredFormats | Property: IReadOnlyList<string> | List of currently registered format names (e.g., "Csv", "Json") |
RegisteredExporters | Property: IReadOnlyDictionary<string, IGridExporter> | Format name to exporter instance mapping |
Register | void Register(string format, IGridExporter exporter) | Registers a new exporter; overrides any existing exporter for the same format |
Unregister | void Unregister(string format) | Removes an exporter by format name |
IsRegistered | bool IsRegistered(string format) | Checks if an exporter is registered for the given format |
IsAvailable | bool IsAvailable(string format) | Returns true if registered AND the exporter's IsAvailable property is true |
GetExporter | IGridExporter GetExporter(string format) | Retrieves the exporter instance for a format; returns null if not registered |
ExportToFile | void ExportToFile(string format, string filePath, ExportOptions options = null) | Exports grid data to a file on disk |
ExportToStream | void ExportToStream(string format, Stream stream, ExportOptions options = null) | Exports grid data to a writable Stream |
ExportToString | string ExportToString(string format, ExportOptions options = null) | Exports grid data and returns it as a string |
DiscoverPlugins | void DiscoverPlugins() | Scans all loaded assemblies for IGridExporter implementations and replaces stubs |
Export Formats
| Format | Extension | Type | Exporter Class | Description |
|---|---|---|---|---|
| CSV | .csv | Built-in | GridCsvExporter | Comma-separated values with configurable delimiter and quoting |
| Json | .json | Built-in | GridJsonExporter | Indented JSON array of objects with property-name keys |
| Html | .html | Built-in | GridHtmlExporter | Full HTML document with styled table and embedded CSS |
| Excel | .xlsx | Stub / Plugin | GridExcelStubExporter | Stub throws NotSupportedException; replace with plugin (e.g., EPPlus/ClosedXML) |
.pdf | Stub / Plugin | GridPdfStubExporter | Stub throws NotSupportedException; replace with plugin (e.g., iTextSharp/QuestPDF) |
IGridExporter Interface
All exporters implement IGridExporter. Custom exporters can be created by implementing this contract and registering via Register().
public interface IGridExporter
{
string Format { get; }
string Description { get; }
string FileExtension { get; }
bool IsAvailable { get; }
void Export(BeepGridPro grid, Stream stream, ExportOptions options);
}| Member | Type | Description |
|---|---|---|
Format | string | Unique format name (e.g., "Csv", "Json", "Excel") |
Description | string | Human-readable description shown in UI dialogs |
FileExtension | string | Default file extension including dot (e.g., ".csv") |
IsAvailable | bool | True if the exporter is ready; stub exporters return false |
Export | Method | Core export logic: reads grid data and writes formatted output to the stream |
Built-in Exporters
GridCsvExporter
Produces RFC 4180-compliant CSV. Honors ExportOptions.Delimiter (default comma), ExportOptions.IncludeHeaders (first row = column names), and ExportOptions.QuoteAllStrings. Uses double-quote escaping for values containing the delimiter, quotes, or newlines.
GridJsonExporter
Produces a valid JSON array of objects. Uses Newtonsoft.Json internally. Each row becomes a JSON object with column names as property names. Honors ExportOptions.IndentSpaces for pretty-printing (default 2). Supports ExportOptions.IncludeHiddenColumns and ExportOptions.NullValueRepresentation.
GridHtmlExporter
Produces a complete self-contained HTML document with embedded CSS styling. The table inherits the grid's visual theme colors. Includes a <thead> section, striped rows, and responsive styling. Honors ExportOptions.IncludeGroupHeaders to render group header rows as <tr class="group-header">.
Plugin Discovery
DiscoverPlugins() scans all assemblies loaded in the current AppDomain for types implementing IGridExporter. When a matching exporter is found, it replaces the corresponding stub in the registry. This enables drop-in Excel/PDF support:
grid.ExportEngine.DiscoverPlugins();
bool excelReady = grid.ExportEngine.IsAvailable("Excel");
if (excelReady)
{
grid.ExportEngine.ExportToFile("Excel", @"C:\reports\data.xlsx");
}The discovery method uses Assembly.GetTypes() wrapped in try/catch to handle ReflectionTypeLoadException — if an assembly fails to load its types (e.g., missing dependencies), it is silently skipped. This ensures that plugin discovery never crashes the host application.
ExportOptions
ExportOptions provides fine-grained control over export output. An instance is passed to each Export* method; if null, sensible defaults are used.
| Property | Type | Default | Description |
|---|---|---|---|
Delimiter | string | "," | Field separator for CSV (e.g., ";" for semicolon, "\t" for TSV) |
IndentSpaces | int | 2 | Indentation spaces for JSON pretty-printing |
IncludeHiddenColumns | bool | false | When false, hidden columns are excluded from output |
VisibleOnly | bool | false | When true, only currently visible rows (post-filter) are exported |
IncludeGroupHeaders | bool | true | Includes group header rows in CSV/HTML output |
DateFormat | string | "yyyy-MM-dd" | Format string for DateTime values |
NullValueRepresentation | string | "" | String to emit for null/DBNull values |
IncludeHeaders | bool | true | Whether column headers are included as the first row/entry |
QuoteAllStrings | bool | false | CSV only: wraps all string values in double quotes |
Examples
Export to CSV File
var engine = grid.ExportEngine;
engine.ExportToFile("Csv", @"C:\exports\data.csv", new ExportOptions
{
Delimiter = ",",
IncludeHeaders = true,
NullValueRepresentation = "N/A"
});Export to JSON String
var engine = grid.ExportEngine;
string json = engine.ExportToString("Json", new ExportOptions
{
IndentSpaces = 4,
IncludeHiddenColumns = false,
DateFormat = "yyyy-MM-ddTHH:mm:ss"
});
File.WriteAllText(@"C:\exports\data.json", json);Stream Export for Web Response
using (var ms = new MemoryStream())
{
grid.ExportEngine.ExportToStream("Csv", ms);
ms.Position = 0;
var response = HttpContext.Current.Response;
response.ContentType = "text/csv";
response.AddHeader("Content-Disposition", "attachment; filename=data.csv");
ms.CopyTo(response.OutputStream);
}Plugin Discovery + Excel Export
var engine = grid.ExportEngine;
engine.DiscoverPlugins();
if (engine.IsRegistered("Excel") && engine.IsAvailable("Excel"))
{
engine.ExportToFile("Excel", @"C:\reports\summary.xlsx", new ExportOptions
{
DateFormat = "MM/dd/yyyy",
NullValueRepresentation = "-"
});
}
else
{
engine.ExportToFile("Csv", @"C:\reports\summary.csv");
}