Customising a JSON data source |
Docs
If you want to customise your JSON data source you can do so and then supply the transformed JSON as a string to the GridModel constructor |
Loading...
Razor code
HttpClient client = new HttpClient();
string json = await client.GetStringAsync("https://api.nobelprize.org/v1/prize.json");
NobelPrizes nobelPrizes = System.Text.Json.JsonSerializer.Deserialize<NobelPrizes>(json);
List<NobelPrizeLaureate> transformedList = nobelPrizes.prizes.Where(p => p.laureates != null).SelectMany(p => p.laureates.Select(l => new { p, l })).Select(x => new NobelPrizeLaureate(x.p, x.l)).ToList();
var gridModel = new GridModel(DataSourceType.JSON, System.Text.Json.JsonSerializer.Serialize(transformedList));
gridModel.Columns = new List<GridColumn>()
{
new GridColumn("Id"),
new GridColumn("Year") { Filter = true, Lookup = new Lookup()},
new GridColumn("Category") { Filter = true, Lookup = new Lookup()},
new GridColumn("Firstname"),
new GridColumn("Surname"),
new GridColumn("Motivation"),
new GridColumn("Share") { Filter = true, Lookup = new Lookup()}
};
gridModel.Cache = true;
@(await new DbNetSuiteCore.GridControl(HttpContext).Render(gridModel))