@page "/test"
@using Syncfusion.Blazor.Grids
@using System.Dynamic;
@code {
public List ToolbarItems = new List() { "Search" };
public List Orders = new List() { };
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 20).Select((x) =>
{
dynamic d = new DynamicDictionary();
d.OrderID = 1000 + x;
d.CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)];
d.Freight = 1 + x;
d.OrderDate = DateTime.Now.AddDays(-x);
return d;
}).Cast().ToList();
// Additional record to set Freight = null and consider Freight column as nullable int
dynamic d = new DynamicDictionary();
d.OrderID = 1021;
d.CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)];
d.Freight = null;
d.OrderDate = DateTime.Now.AddDays(-21);
Orders.Add(d);
}
public class DynamicDictionary : DynamicObject
{
Dictionary dictionary = new Dictionary();
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
string name = binder.Name;
return dictionary.TryGetValue(name, out result);
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
dictionary[binder.Name] = value;
return true;
}
public override System.Collections.Generic.IEnumerable GetDynamicMemberNames()
{
return this.dictionary?.Keys;
}
}
}