Blazor

How to get REST API Data in Blazor Grid| Blazor CRUD Operations | Part 2 | Blazor Tutorial

How to get REST API Data in Blazor Grid| Blazor CRUD Operations | Part 2 | Blazor Tutorial

Till now, we have learned how to get Data from your REST API and print that in DOM as HTML Table, like the below sample:

but what if we want this data to filter, Short or search, means what if we want this data to be in a smart data grid?

Here In this article we’ll add a grid from Ignite UI for Blazor in my application from the NuGet package and will check this out with the below steps but before going ahead I would suggest you to read me previous blog for making an HTTP communication in Blazor App:

REST API Communication and CRUD Operations in Blazor

Step 1: Install NuGet Package for IgniteUI.Blazor

Step 2: Configure Ignite UI for Blazor by adding the required tag in the _Host.cshtml file (For Blazor server project)

<script src="_content/IgniteUI.Blazor/app.bundle.js"></script>

<script src="_framework/blazor.server.js"></script>

Like the below image:

Step 3: Now, use the below-using statements in “_imports.razor” for all the razor components

@using IgniteUI.Blazor.Controls;

Step 4: Register IgniteUI for Blazor controls in your project’s Start-up file like other services:

services.AddIgniteUIBlazor(typeof(DataGridModule));

Like below:

Step 5: We are done with all configuration settings and now one your razor component where you want to use Ignite UI Data Grid and comment the previous HTML table code and add the below code for using Data Grid in auto-generate columns:

<DataGrid DataSource="@Employees" Height="500px" Width="100%"></DataGrid>

Here in this code spinet, DataSource is mapped with the local variable “Employees” which is having all the JSON data coming from REST API service.

Now run the application and navigate to “/Employees” and I hope you’ll also the beautiful Data Grid will all the default features like Sorting, Filtering, Column hiding, column Pinning:

Now, In this Data Grid you have tons of feature to use as default, get your mouse over the column header and click on the three dots:

This grid has generated the auto-generated columns but you can edit the columns and can make your own with custom data, for more details I would suggest you check the official document with the below link:

Blazor Data Grid Overview

Thanks for reading this article :)

Nitin Pandit

With over 10 years of vast development experience with different technologies, Nitin Pandit is Microsoft certified Most Valued Professional (Microsoft MVP) with a rich skillset that includes developing and managing IT/Web-based applications in different technologies, such as – C#.NET, ADO.NET, LINQ to SQL, WCF, and ASP.NET 2.0/3.x/4.0, WCF, WPF, MVC 5.0 (Razor), and Silverlight, along with client-side programming techniques, like jQuery and AngularJS. Nitin possesses a Master’s degree in Computer Science and has been actively contributing to the development community for its betterment. He has written more than 100 blogs/articles and 3 eBooks on different technologies to help improve the knowledge of young technology professionals. He has trained more than one lakh students and professionals, as a speaker in workshops and AppFests, conducted in more than 25 universities in North India.