Skip to content
IzzyBlazor 0.1.0-alpha.20

Enter all results ↑ ↓ move Esc close

Export

Since 0.1.0-alpha.20
Download what's on screen as Excel or CSV.

Static server-side rendering: no circuit, no WebAssembly.

Export to Excel

ExportExcelHref adds a link to an endpoint you map with DataExport.WriteExcelAsync, which streams rows from the database with flat memory. The link carries the filter, sort, search and visible columns, and works with no script. The fields you give DataExport decide what can be written, whatever the address says, and their captions head the file. Give them the grid's keys so a download matches the screen: a filter on a key they don't have matches nothing.

Preview

Orders for Excel
NumberCustomer Total
1001Margaret Hamilton$66.25
1002Katherine Johnson$108.00
1003Grace Hopper$149.75
1004Barbara Liskov$191.50
1005Linus Torvalds$233.25

Code

Export.razor
@* The usual setup: Excel alone, one icon that downloads. Sort or page it, then download: the file has
   every matching row, in the columns on screen. The endpoint is in the app: DataExport.WriteExcelAsync,
   in Results.Stream. *@
@using Rows = IzzyBlazor.Site.Examples.Table.Orders
<DataGrid Items="Rows.All" PageSize="5" Caption="Orders for Excel" ExportExcelHref="/examples/orders.xlsx" QueryPrefix="excel-" Grow>
    <PropertyColumn Property="o => o.Number" Align="CellAlign.Start" Width="6.Rem" />
    <PropertyColumn Property="o => o.Customer" Sortable />
    <PropertyColumn Property="o => o.Total" Format="C" Sortable Width="8.Rem" />
</DataGrid>

Excel and CSV

Add ExportCsvHref to offer CSV too: one button with a chevron then opens a menu of both, Excel first.

Preview

Orders to export
NumberCustomer Total
1001Margaret Hamilton$66.25
1002Katherine Johnson$108.00
1003Grace Hopper$149.75
1004Barbara Liskov$191.50
1005Linus Torvalds$233.25

Code

ExportBoth.razor
@* With CSV as well as Excel, one button with a chevron opens a menu of both. The endpoints are in the
   app: DataExport.WriteExcelAsync and WriteCsvAsync, in Results.Stream. *@
@using Rows = IzzyBlazor.Site.Examples.Table.Orders
<DataGrid Items="Rows.All" PageSize="5" Caption="Orders to export" ExportExcelHref="/examples/orders.xlsx" ExportCsvHref="/examples/orders.csv" QueryPrefix="export-" Grow>
    <PropertyColumn Property="o => o.Number" Align="CellAlign.Start" Width="6.Rem" />
    <PropertyColumn Property="o => o.Customer" Sortable />
    <PropertyColumn Property="o => o.Total" Format="C" Sortable Width="8.Rem" />
</DataGrid>

Connection lost

Rejoining the server…