chore(demos): add grid viewcomponent mvc example
This commit is contained in:
Родитель
bc49f58290
Коммит
2ab28eee2c
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<IViewComponentResult> InvokeAsync(IEnumerable<Product> gridModel)
|
||||
{
|
||||
return View("default", gridModel);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
@{
|
||||
ViewData["Title"] = "View Component";
|
||||
}
|
||||
<h3>@ViewData["Title"]</h3>
|
||||
@model IEnumerable<Product>
|
||||
|
||||
@await Component.InvokeAsync("Grid", Model)
|
|
@ -0,0 +1,23 @@
|
|||
@using Telerik.Examples.Mvc.Models
|
||||
|
||||
@model IEnumerable<Product>
|
||||
|
||||
@(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()
|
||||
)
|
Загрузка…
Ссылка в новой задаче