A simple Blazor component designed to streamline data export tasks effortlessly. With this component, users can conveniently export their input data to a CSV file by simply clicking a dedicated button.
$ dotnet add package EdenForge.BlazorCSVDownload Component
Usage Guide:
To utilize the CSVDownload component, follow the syntax:
@Class: Defines the Bootstrap CSS class, e.g., "btn btn-primary".
@Data: Input data to be exported.
@Description: Description for the button.
@FileName: Name of the output file.
Usage Examples:
In Demo.razor
@page "/demo"
@using EdenForge.Blazor.Components
@code {
// Cars class definition
public class Cars
{
public string Id { get; set; }
public string CarMake { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public int Price { get; set; }
}
public string Filename = "Cars.csv";
public string Class = "btn btn-primary";
public string Description = "CSV Download";
public List<Cars>? Car { get; set; }
protected override async Task OnInitializedAsync()
{
Car = new List<Cars>
{
new Cars { Id = "CAR_001", CarMake = "Toyota", Model = "Corolla", Year = 2018, Price = 18000 },
new Cars { Id = "CAR_002", CarMake = "Honda", Model = "Civic", Year = 2019, Price = 20000 },
new Cars { Id = "CAR_003", CarMake = "Ford", Model = "Fusion", Year = 2020, Price = 22000 },
new Cars { Id = "CAR_004", CarMake = "Chevrolet", Model = "Malibu", Year = 2017, Price = 19000 },
new Cars { Id = "CAR_005", CarMake = "BMW", Model = "3 Series", Year = 2021, Price = 35000 }
};
}
}
Results:
Cars.csv
"Id","CarMake","Model","Year","Price"
"CAR_001","Toyota","Corolla","2018","18000"
"CAR_002","Honda","Civic","2019","20000"
"CAR_003","Ford","Fusion","2020","22000"
"CAR_004","Chevrolet","Malibu","2017","19000"
"CAR_005","BMW","3 Series","2021","35000"
This example demonstrates how to use the CSVDownload component to export car data to a CSV file. Customize the class, description, and file name according to your requirements.
Feel free to integrate this NuGet package into your Blazor application to simplify data export tasks.