diff --git a/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Controllers/Grid/ViewComponentController.cs b/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Controllers/Grid/ViewComponentController.cs new file mode 100644 index 0000000..49c22b5 --- /dev/null +++ b/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Controllers/Grid/ViewComponentController.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Telerik.Examples.Mvc.Models; + +namespace Telerik.Examples.Mvc.Controllers.Grid +{ + public class ViewComponentController : Controller + { + public IActionResult ViewComponent() + { + var random = new Random(); + + var data = Enumerable.Range(1, 10) + .Select(x => new Product + { + Discontinued = x % 2 == 1, + ProductID = x, + ProductName = "Product " + x, + UnitPrice = random.Next(1, 1000), + UnitsInStock = random.Next(1, 1000), + UnitsOnOrder = random.Next(1, 1000) + + }) + .ToList(); + + return View(data); + } + } +} diff --git a/Telerik.Examples.Mvc/Telerik.Examples.Mvc/ViewComponents/GridViewComponent.cs b/Telerik.Examples.Mvc/Telerik.Examples.Mvc/ViewComponents/GridViewComponent.cs new file mode 100644 index 0000000..140e7ad --- /dev/null +++ b/Telerik.Examples.Mvc/Telerik.Examples.Mvc/ViewComponents/GridViewComponent.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Mvc; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using Telerik.Examples.Mvc.Models; + +namespace Telerik.Examples.Mvc.ViewComponents +{ + public class GridViewComponent : ViewComponent + { + public async Task InvokeAsync(IEnumerable gridModel) + { + return View("default", gridModel); + } + } +} diff --git a/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Grid/ViewComponent.cshtml b/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Grid/ViewComponent.cshtml new file mode 100644 index 0000000..4cab5f1 --- /dev/null +++ b/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Grid/ViewComponent.cshtml @@ -0,0 +1,7 @@ +@{ + ViewData["Title"] = "View Component"; +} +

@ViewData["Title"]

+@model IEnumerable + +@await Component.InvokeAsync("Grid", Model) \ No newline at end of file diff --git a/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Shared/Components/Grid/Default.cshtml b/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Shared/Components/Grid/Default.cshtml new file mode 100644 index 0000000..fafb278 --- /dev/null +++ b/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Shared/Components/Grid/Default.cshtml @@ -0,0 +1,23 @@ +@using Telerik.Examples.Mvc.Models + +@model IEnumerable + +@(Html.Kendo().Grid(Model) + .Name("grid") + .DataSource(dataSource => dataSource + .Ajax() + .PageSize(5) + .ServerOperation(false) + ) + .Columns(columns => + { + columns.Bound(product => product.ProductID); + columns.Bound(product => product.ProductName); + columns.Bound(product => product.UnitsInStock); + columns.Bound(product => product.Discontinued); + }) + .Pageable() + .Sortable() + .Filterable() + .Groupable() +) \ No newline at end of file