Export & import
Wire CSV/Excel/PDF export onto a list, and import the same formats with per-row error reporting.
Export
TabularExport turns a query into a downloadable file in any of the three formats. Add an /export endpoint that runs the same query spec as your list, and point the DataGrid's export menu at it — the export then honors the active filters and sort:
csharp
group.MapGet("/export", async (AppDbContext db, [AsParameters] PagedRequest req, string format, CancellationToken ct) =>
{
var rows = await db.Set<Project>().AsNoTracking().ApplyQuery(req).ToListAsync(ct);
return TabularExport.ToResult(rows, format, columns: p => new { p.Name, p.CreatedAt });
});Import
TabularImport.ReadRows parses an uploaded CSV/XLSX into header-keyed rows. Validate each row, collect per-row errors, and return an ImportResult so bad rows are reported by line number without failing the batch:
csharp
var result = new ImportResult();
foreach (var (row, i) in TabularImport.ReadRows(stream, fileName).Select((r, i) => (r, i + 2)))
{
if (string.IsNullOrWhiteSpace(row["Name"])) { result.AddError(i, "Name is required"); continue; }
// … dedupe, map, add
result.Imported++;
}
return Results.Ok(result);The frontend offers "download template → fill → upload" and shows the per-row errors. See Export & import.