Awesome ASP.net Core and MVC Controls
Grid using array data source
In this demo you can see how an array data source can be used to provide data for the awesome grid control.
GridArrayDataSource/Index.cshtml
@Html.Awe().Grid("GridArrayData").Url(Url.Action("GridGetItems"))
<script>
function getVal(i) {
return function (model) {
return model.Values[i];
};
}
</script>
Demos/Grid/GridArrayDataSourceController.cs
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using AweCoreDemo.ViewModels;
using Omu.AwesomeMvc;
namespace AweCoreDemo.Controllers.Demos.Grid
{
public class GridArrayDataSourceController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult GridGetItems(GridParams g)
{
var data = new[]
{
new[] { "Id", "Name", "Meal" },
new[] { "1", "Vincenzo", "Pizza" },
new[] { "2", "Ella", "French toast" },
new[] { "3", "Zazzles", "Pizza" },
new[] { "4", "Evan", "Banana" }
};
var columns = new List<Column>();
columns.Add(new Column { Header = "Id", ClientFormat = ".(Id)", Width = 100});
for (var i = 1; i < data[0].Length; i++)
{
columns.Add(new Column{ Header = data[0][i], ClientFormatFunc = "getVal("+i+")" });
}
var items = new List<GridArrayRow>();
for (var i = 1; i < data.Length; i++)
{
items.Add(new GridArrayRow{ Id = data[i][0], Values = data[i]});
}
g.Columns = columns.ToArray();
var model = new GridModelBuilder<GridArrayRow>(items.AsQueryable(), g).Build();
return Json(model);
}
}
}
ViewModels/GridArrayRow.cs
namespace AweCoreDemo.ViewModels
{
public class GridArrayRow
{
public string Id { get; set; }
public string[] Values { get; set; }
}
}
Comments