Articles in this section
Category / Section

How to create an array of Grid components and set references in Blazor application?

1 min read

This article explains how to create an array of Grid components and set references to those components.

In the following example, we have created an array of Blazor Grid components based on the number of strings (Id’s) present in the GridIds List and defined the Grid reference while creating the components.

Find the following code snippets for your reference.


 
@using Syncfusion.Blazor.Grids
 
@foreach (var id in GridIDs)
{
    <h2>@id</h2>
    <SfGrid @ref="myComponents[id]" DataSource="@Orders" AllowPaging="true">
    </SfGrid>
}
 
 
@code{
    private List<string> GridIDs = new List<string> { "Grid1", "Grid2", "Grid3", "Grid4" };
    private Dictionary<string, SfGrid<Order>> myComponents = new Dictionary<string, SfGrid<Order>>();
    public List<Order> Orders { get; set; }
 
    protected override void OnInitialized()
    {
        Orders = Enumerable.Range(1, 5).Select(x => new Order()
        {
            OrderID = 1000 + x,
            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
            Freight = 2.1 * x,
            OrderDate = DateTime.Now.AddDays(-x),
        }).ToList();
    }
 
    public class Order
    {
        public int? OrderID { get; set; }
        public string CustomerID { get; set; }
        public DateTime? OrderDate { get; set; }
        public double? Freight { get; set; }
    }
}

 

Take a moment to peruse the documentation.

Conclusion

I hope you enjoyed learning about how to create an array of Grid components and set references in Blazor application.

You can refer to our Blazor Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Grid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied