Customer Information Screen Using C1 Blazor Input Controls
Blazor is a framework that enables developers to create Single Page Web applications with C# and HTML. Blazor has two types of projects - Blazor Server App and Blazor Web Assembly. Blazor applications can interop with JavaScript, which can be triggered with the .NET Code.
ComponentOne started development for Blazor platform after Microsoft announced the Blazor preview. The Blazor Edition includes FlexGrid, FlexChart, FlexPie, ListView, TreeMap, Calendar, ComboBox, AutoComplete, NumericBox, TimeEditor, DatePicker and DateTimePicker controls. More controls will be added based on user feedback.
In this blog, we are going to create a Customer Information screen using the GcDemo DataServices' Northwind Database and Blazor Input Controls for a Store, which retrieves the Customer information for Orders. We will also apply Filtering based on OrderID, Date Range using Blazor Input controls.
To create the above screen, we will use the following C1 Blazor Input Controls:
- C1AutoComplete
- C1NumericBox
- C1TextBox
- C1DateTimeEditor
- C1ListView
The C1AutoComplete will be used to display Customer List, and C1NumericBox will be used to get the number of records. The Order information will be displayed using C1ListView. C1TextBox and C1DateTimeEditor will be used to filter items.
Download C1 Blazor Controls | Blazor Demo
Let's create the above screen with the following steps:
Install NuGet Packages:
To use the C1Blazor controls, we need to install the following C1 Blazor controls from the NuGet in the Blazor project.
Reference Required Script and Style Files:
After installing the NuGet packages, we’re required to add the script and styles files for C1 Controls so that they might render correctly and work fine.
For this, we need to add the following scripts in the wwwroot\index.html file:
Adding Controls in the Code:
After installing the NuGet packages and adding the scripts & styles file, we may add the required controls in the Blazor page.
For this, we need to import the required namespace in the page as follows:
The above screen can be split into three parts:
- Order Search
- Filter Order
- Display Orders
Order Search:
For searching Order from the DataBase, we required the CustomerId which can be retrieved from the API and will be displayed using the AutoComplete.
Here is the code to fetch the Customers from the API:
Once the Customers data is fetched, the data can be displayed in the C1AutoComplete using the following code:
When the Customer is selected, we may fetch the records from the API using the following code snippet:
Once the Orders are fetched, we may fetch the number of records using the C1NumericBoxes using the following code:
Filter Orders:
Once the records are fetched, we can apply filtering. Here, we would use the C1TextBox to filter the records according to OrderID with the Contains operator. Also, the DateTimeEditor would be used to filter the records between a range of dates using the following code snippet:
Display Orders:
The Orders will be displayed using the C1ListView. After displaying the selected Orders, we would show the details of selected records with the help of the SelectionChanged event.
Now, we are ready to execute the sample.