The .NET MAUI DataGrid supports binding the item source from a local JSON file.
Create a JSON data model.
OrderInfo
public class OrderInfo
{
public int OrderID { get; set; }
public string? CustomerID { get; set; }
public int EmployeeID { get; set; }
public double Freight { get; set; }
public string? ShipCity { get; set; }
public bool Verified { get; set; }
public DateTime OrderDate { get; set; }
public string? ShipName { get; set; }
public string? ShipCountry { get; set; }
public DateTime ShippedDate { get; set; }
public string? ShipAddress { get; set; }
}Please place the JSON file in the 'Resources\raw' folder and ensure that the file's property is set as 'MauiAsset'.
OrderInfoViewModel
Read the JSON file using the FileSystem.OpenAppPackageFileAsync() method and deserialize the JSON object using the Newtonsoft.Json package.
const string templateFileName = "OrderInfo.Json";
public async void LoadFile()
{
this.OrdersInfoCollection = new List<OrderInfo>();
using (var stream = await FileSystem.OpenAppPackageFileAsync(templateFileName))
using (var reader = new StreamReader(stream))
{
this.OrdersInfoCollection = JsonConvert.DeserializeObject<List<OrderInfo>>(await reader.ReadToEndAsync())!;
}
}The following screenshot shows how to bind Itemsource from a JSON file in SfDataGrid.
Take a moment to pursue this documentation, where you can find more about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid(SfDataGrid).
I hope you enjoyed learning about how to bind Itemsource from a JSON file in SfDataGrid.
You can refer to our .NET MAUI DataGrid's feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI 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 .NET MAUI DataGrid and other .NET MAUI components. If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac or feedback portal. We are always happy to assist you!
