Skip to content

Commit c166f78

Browse files
committed
chore(examples): add remaining vol1 grid examples
1 parent 4251fcf commit c166f78

File tree

164 files changed

+14171
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+14171
-7
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using Kendo.Mvc.Extensions;
2+
using Kendo.Mvc.UI;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Web;
7+
using System.Web.Mvc;
8+
using Telerik.Examples.Mvc.Areas.GridCRUDWithObjectColumn.Models;
9+
10+
namespace Telerik.Examples.Mvc.Areas.GridCRUDWithObjectColumn.Controllers
11+
{
12+
public class HomeController : Controller
13+
{
14+
private static ICollection<Product> products;
15+
private static ICollection<Category> categories;
16+
17+
public HomeController()
18+
{
19+
if (products == null)
20+
{
21+
var random = new Random();
22+
products = Enumerable.Range(1, 100).Select(x => new Product
23+
{
24+
Discontinued = x % 2 == 1,
25+
ProductID = x,
26+
ProductName = "Product " + x,
27+
UnitPrice = random.Next(1, 1000),
28+
UnitsInStock = random.Next(1, 1000),
29+
UnitsOnOrder = random.Next(1, 1000),
30+
Category = new Category
31+
{
32+
CategoryID = x,
33+
CategoryName = "Category" + x
34+
}
35+
36+
}).ToList();
37+
38+
categories = Enumerable.Range(1, 100).Select(x => new Category
39+
{
40+
CategoryID = x,
41+
CategoryName = "Category" + x
42+
43+
}).ToList();
44+
}
45+
}
46+
public ActionResult Index()
47+
{
48+
return View();
49+
}
50+
51+
52+
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
53+
{
54+
return Json(products.ToDataSourceResult(request));
55+
}
56+
57+
public ActionResult AllCategories()
58+
{
59+
return Json(categories, JsonRequestBehavior.AllowGet);
60+
}
61+
62+
63+
[AcceptVerbs("Post")]
64+
public ActionResult Create([DataSourceRequest] DataSourceRequest request, Product product)
65+
{
66+
//save item to database
67+
return Json(new[] { product }.ToDataSourceResult(request, ModelState));
68+
}
69+
70+
[AcceptVerbs("Post")]
71+
public ActionResult Update([DataSourceRequest] DataSourceRequest request, Product product)
72+
{
73+
//save item to database
74+
products.Add(product);
75+
return Json(new[] { product }.ToDataSourceResult(request, ModelState));
76+
}
77+
78+
[AcceptVerbs("Post")]
79+
public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, Product product)
80+
{
81+
//remove item from database
82+
products.Remove(product);
83+
return Json(new[] { product }.ToDataSourceResult(request, ModelState));
84+
}
85+
}
86+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Web.Mvc;
2+
3+
namespace Telerik.Examples.Mvc.Areas.GridCRUDWithObjectColumn
4+
{
5+
public class GridCRUDWithObjectColumnAreaRegistration : AreaRegistration
6+
{
7+
public override string AreaName
8+
{
9+
get
10+
{
11+
return "GridCRUDWithObjectColumn";
12+
}
13+
}
14+
15+
public override void RegisterArea(AreaRegistrationContext context)
16+
{
17+
context.MapRoute(
18+
"GridCRUDWithObjectColumn_default",
19+
"GridCRUDWithObjectColumn/{controller}/{action}/{id}",
20+
new { action = "Index", id = UrlParameter.Optional }
21+
);
22+
}
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace Telerik.Examples.Mvc.Areas.GridCRUDWithObjectColumn.Models
7+
{
8+
public class Category
9+
{
10+
public int CategoryID { get; set; }
11+
12+
public string CategoryName { get; set; }
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace Telerik.Examples.Mvc.Areas.GridCRUDWithObjectColumn.Models
7+
{
8+
public class Product
9+
{
10+
public int ProductID { get; set; }
11+
12+
public string ProductName { get; set; }
13+
14+
public decimal UnitPrice { get; set; }
15+
16+
public int UnitsInStock { get; set; }
17+
18+
public int UnitsOnOrder { get; set; }
19+
20+
public bool Discontinued { get; set; }
21+
22+
public Category Category { get; set; }
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@(Html.Kendo().DropDownListFor(x => x).Name("Category").DataSource(x => x.Read(y => y.Action("AllCategories", "Home"))).DataTextField("CategoryName").DataValueField("CategoryID"))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@using Kendo.Mvc.UI
2+
3+
@{
4+
ViewBag.Title = "Index";
5+
}
6+
7+
@(Html.Kendo().Grid<Telerik.Examples.Mvc.Areas.GridCRUDWithObjectColumn.Models.Product>()
8+
.Name("grid")
9+
.DataSource(dataSource => dataSource
10+
.Ajax()
11+
.Read(read => read.Action("Read", "Home"))
12+
.Update(update => update.Action("Update", "Home"))
13+
.Create(create => create.Action("Create", "Home"))
14+
.Destroy(destroy => destroy.Action("Destroy", "Home"))
15+
.Model(m =>
16+
{
17+
m.Id(id => id.ProductID);
18+
m.Field(f => f.ProductID).Editable(false);
19+
})
20+
)
21+
.ToolBar(t => t.Create())
22+
.Columns(columns =>
23+
{
24+
columns.Bound(product => product.ProductID);
25+
columns.Bound(product => product.ProductName);
26+
columns.Bound(product => product.UnitsInStock);
27+
columns.Bound(product => product.Discontinued);
28+
columns.Bound(product => product.Category.CategoryName).EditorTemplateName("DropDownEditor");
29+
columns.Command(command => command.Edit());
30+
})
31+
.Pageable()
32+
.Sortable()
33+
.Filterable()
34+
.Groupable()
35+
.Editable()
36+
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>@ViewBag.Title - My ASP.NET Application</title>
7+
@Styles.Render("~/Content/css")
8+
@Scripts.Render("~/bundles/modernizr")
9+
</head>
10+
<body>
11+
<div class="navbar navbar-inverse navbar-fixed-top">
12+
<div class="container">
13+
<div class="navbar-header">
14+
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
15+
<span class="icon-bar"></span>
16+
<span class="icon-bar"></span>
17+
<span class="icon-bar"></span>
18+
</button>
19+
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
20+
</div>
21+
<div class="navbar-collapse collapse">
22+
<ul class="nav navbar-nav">
23+
</ul>
24+
</div>
25+
</div>
26+
</div>
27+
28+
<div class="container body-content">
29+
@RenderBody()
30+
<hr />
31+
<footer>
32+
<p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
33+
</footer>
34+
</div>
35+
36+
@Scripts.Render("~/bundles/jquery")
37+
@Scripts.Render("~/bundles/bootstrap")
38+
@RenderSection("scripts", required: false)
39+
</body>
40+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "~/Views/Shared/_Layout.cshtml";
3+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
3+
<configuration>
4+
<configSections>
5+
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
6+
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
7+
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
8+
</sectionGroup>
9+
</configSections>
10+
11+
<system.web.webPages.razor>
12+
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.3.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
13+
<pages pageBaseType="System.Web.Mvc.WebViewPage">
14+
<namespaces>
15+
<add namespace="System.Web.Mvc" />
16+
<add namespace="System.Web.Mvc.Ajax" />
17+
<add namespace="System.Web.Mvc.Html" />
18+
<add namespace="System.Web.Routing" />
19+
<add namespace="System.Web.Optimization" />
20+
<add namespace="Telerik.Examples.Mvc" />
21+
<add namespace="Kendo.Mvc.UI" />
22+
</namespaces>
23+
</pages>
24+
</system.web.webPages.razor>
25+
26+
<appSettings>
27+
<add key="webpages:Enabled" value="false" />
28+
</appSettings>
29+
30+
<system.webServer>
31+
<handlers>
32+
<remove name="BlockViewHandler"/>
33+
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
34+
</handlers>
35+
</system.webServer>
36+
</configuration>

0 commit comments

Comments
 (0)