Introduction
In this article, we will create a reusable grid component for Blazor called BlazorGrid. It will display the user data in a grid and will support the client-side pagination.
Take a look at the final application.
Table of Contents
.Net 6.x
Creating Blazor Library project
Creating BlazorGrid component
Now, we will add the component view page to our project. Right-click on the BlazorGridComponent project and then select Add >> New Item. An “Add New Item” dialog box will open; select “Web” from the left panel, then select “Razor” from templates panel, and name it BlazorGrid.razor. Click Add. Refer to the image below.
Create Blazor Server Web Application for test
Add Reference Razor Class Library project
Adding the BlazorGrid component to the Blazor project
Using BlazorGrid component
Execution Demo
.Net 5.x
Prerequisites
Here’s what you’ll need to use our Razor Class Library project with the Blazor framework:
Visual Studio 2019 with the ASP.NET and Web Development workload
.NET 5.0+ Framework
step 1:Create a new Razor Class Library project
step 2:Create a new Blazor Server Library project
source on github:https://github.com/iaspnetcore/iAspNetCore.RazorComponents/commit/7eeb63fdab78db8bae3ba68d1a2225e47697a288
Table.razor
step 1:Create a Table component (Table.razor)
Step 2:Add Reference Razor Class Library project
Step 3:
outpiut
ID | Name |
---|---|
2021/2/15 | 49 |
2021/2/16 | 45 |
2021/2/17 | -1 |
2021/2/18 | 29 |
2021/2/19 | -4 |
.Net core 3.x
https://dzone.com/articles/blazorgrid-a-reusable-grid-component-for-blazor
update
current version: asp .net core 3.x 2020.03.26
Introduction
In this article, we will create a reusable grid component for Blazor called BlazorGrid. It will display the user data in a grid and supports client-side pagination.
Source Code
Get the source code from GitHub
Part one:Create Razor Class Library project named with iAspNetCore.RazorComponents
step 1:Create new a new Razor Class Library project
From Visual Studio
From the command line
Navigate to the folder where you want to create your project.
Open the command prompt or Windows PowerShell as an administrator.
Run the following command:
step 2:Creating a BlazorGrid Component
Part two:using iAspNetCore.RazorComponents Razor Class Library project
Demo in blazor server project
step 1:Create a Blazor server Web Application
step 2:Adding the BlazorGrid Component to the Blazor server Project
Select Add Reference... Then, select the BlazorGridComponent project and click OK
path:\src\demo\BlazorServer\BlazorServer.csproj
step3:Using the BlazorGrid Component
Open TestApplication\Pages\FetchData.cshtml file. In the HTML section of the code put the following lines inside the else section.
path:\src\demo\BlazorServer\Pages\FetchData.razor
output
Create reusable UI using the Razor class library project in ASP.NET Core
Weather forecast
This component demonstrates fetching data from a service.
Date | Temp. (C) | Temp. (F) | Summary |
---|---|---|---|
2020/3/27 | 53 | 127 | Freezing |
2020/3/28 | 8 | 46 | Balmy |
2020/3/29 | 12 | 53 | Freezing |
2020/3/30 | -17 | 2 | Scorching |
2020/3/31 | 48 | 118 | Chilly |
BlazorGrid
Date | TemperatureC | TemperatureF | Summary |
---|---|---|---|
2020/3/27 | 53 | 127 | Freezing |
2020/3/28 | 8 | 46 | Balmy |
2020/3/29 | 12 | 53 | Freezing |
2020/3/30 | -17 | 2 | Scorching |