Skip to content

Commit b202aaf

Browse files
authored
chore: add the save on server grid sample
1 parent c9224af commit b202aaf

File tree

8 files changed

+208
-1
lines changed

8 files changed

+208
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Telerik.Examples.Mvc.Areas.GridSaveStateOnServerSide.Models;
2+
using Kendo.Mvc.Extensions;
3+
using Kendo.Mvc.UI;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Web;
8+
using System.Web.Mvc;
9+
10+
namespace Telerik.Examples.Mvc.Areas.GridSaveStateOnServerSide.Controllers
11+
{
12+
public class HomeController : Controller
13+
{
14+
public ActionResult Index()
15+
{
16+
ViewBag.Message = "Welcome to ASP.NET MVC!";
17+
18+
return View();
19+
}
20+
21+
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
22+
{
23+
var products = Enumerable.Range(1, 100).Select(index => new Product
24+
{
25+
ProductID = index,
26+
ProductName = index + " Product Name"
27+
});
28+
29+
return Json(products.ToDataSourceResult(request));
30+
}
31+
32+
public ActionResult Save(string data)
33+
{
34+
Session["data"] = data;
35+
36+
return new EmptyResult();
37+
}
38+
39+
public ActionResult Load()
40+
{
41+
return Json(Session["data"], JsonRequestBehavior.AllowGet);
42+
}
43+
}
44+
}
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.GridSaveStateOnServerSide
4+
{
5+
public class EditorImportExportKendoWidgetAreaRegistration : AreaRegistration
6+
{
7+
public override string AreaName
8+
{
9+
get
10+
{
11+
return "GridSaveStateOnServerSide";
12+
}
13+
}
14+
15+
public override void RegisterArea(AreaRegistrationContext context)
16+
{
17+
context.MapRoute(
18+
"GridSaveStateOnServerSide_default",
19+
"GridSaveStateOnServerSide/{controller}/{action}/{id}",
20+
new { action = "Index", id = UrlParameter.Optional }
21+
);
22+
}
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace Telerik.Examples.Mvc.Areas.GridSaveStateOnServerSide.Models
7+
{
8+
public class Product
9+
{
10+
public int ProductID { get; set; }
11+
public string ProductName { get; set; }
12+
public double UnitPrice { get; set; }
13+
public int UnitsInStock { get; set; }
14+
public bool Discontinued { get; set; }
15+
}
16+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
@{
2+
ViewBag.Title = "Home Page";
3+
}
4+
5+
<button id="save">Save state</button>
6+
<button id="load">Load state</button>
7+
<br />
8+
9+
@(Html.Kendo().Grid<Telerik.Examples.Mvc.Areas.GridSaveStateOnServerSide.Models.Product>()
10+
.Name("grid")
11+
.DataSource(ds => ds.Ajax().Read("Read", "Home"))
12+
.Pageable()
13+
.Groupable()
14+
.Sortable()
15+
.Reorderable(r => r.Columns(true))
16+
.Resizable(r => r.Columns(true))
17+
)
18+
19+
<script>
20+
21+
$("#save").click(function () {
22+
var grid = $("#grid").data("kendoGrid");
23+
24+
var dataSource = grid.dataSource;
25+
26+
var state = {
27+
columns: grid.columns,
28+
page: dataSource.page(),
29+
pageSize: dataSource.pageSize(),
30+
sort: dataSource.sort(),
31+
filter: dataSource.filter(),
32+
group: dataSource.group()
33+
};
34+
35+
$.ajax({
36+
url: "../Home/Save",
37+
data: {
38+
data: JSON.stringify(state)
39+
}
40+
});
41+
});
42+
43+
$("#load").click(function () {
44+
var grid = $("#grid").data("kendoGrid");
45+
46+
var dataSource = grid.dataSource;
47+
48+
$.ajax({
49+
url: "../Home/Load",
50+
success: function (state) {
51+
state = JSON.parse(state);
52+
53+
var options = grid.options;
54+
55+
options.columns = state.columns;
56+
57+
options.dataSource.page = state.page;
58+
options.dataSource.pageSize = state.pageSize;
59+
options.dataSource.sort = state.sort;
60+
options.dataSource.filter = state.filter;
61+
options.dataSource.group = state.group;
62+
63+
grid.destroy();
64+
65+
$("#grid")
66+
.empty()
67+
.kendoGrid(options);
68+
}
69+
});
70+
});
71+
72+
</script>
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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.2.9.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+
23+
</namespaces>
24+
</pages>
25+
</system.web.webPages.razor>
26+
27+
<appSettings>
28+
<add key="webpages:Enabled" value="false" />
29+
</appSettings>
30+
31+
<system.webServer>
32+
<handlers>
33+
<remove name="BlockViewHandler"/>
34+
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
35+
</handlers>
36+
</system.webServer>
37+
</configuration>

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Telerik.Examples.Mvc.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,9 @@
13591359
<Compile Include="Areas\GanttImportExportUsingMpxj\GanttImportExportUsingMpxjAreaRegistration.cs" />
13601360
<Compile Include="Areas\DefineCustomHtmlHelper\Controllers\HomeController.cs" />
13611361
<Compile Include="Areas\DefineCustomHtmlHelper\DefineCustomHtmlHelperAreaRegistration.cs" />
1362+
<Compile Include="Areas\GridSaveStateOnServerSide\Controllers\HomeController.cs" />
1363+
<Compile Include="Areas\GridSaveStateOnServerSide\GridSelectionByFieldAreaRegistration.cs" />
1364+
<Compile Include="Areas\GridSaveStateOnServerSide\Models\Product.cs" />
13621365
<Compile Include="Areas\GridTimestamp\Controllers\HomeController.cs" />
13631366
<Compile Include="Areas\GridTimestamp\GridTimestampAreaRegistration.cs" />
13641367
<Compile Include="Areas\GridTimestamp\Models\Product.cs" />
@@ -2702,6 +2705,9 @@
27022705
<Content Include="Areas\UploadAmazonS3\Views\Home\Index.cshtml" />
27032706
<Content Include="Areas\UploadAmazonS3\Views\web.config" />
27042707
<Content Include="Areas\UploadAmazonS3\Views\_ViewStart.cshtml" />
2708+
<Content Include="Areas\GridSaveStateOnServerSide\Views\_ViewStart.cshtml" />
2709+
<Content Include="Areas\GridSaveStateOnServerSide\Views\Home\Index.cshtml" />
2710+
<Content Include="Areas\GridSaveStateOnServerSide\Views\web.config" />
27052711
<None Include="packages.config" />
27062712
<Content Include="Images\200.png" />
27072713
<Content Include="Images\country-flags\bg.png" />

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Web.config

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
2121
</assemblies>
2222
</compilation>
23-
<httpRuntime targetFramework="4.8" />
23+
<httpRuntime targetFramework="4.8" maxQueryStringLength="32768" />
2424
<pages>
2525
<namespaces>
2626
<add namespace="Kendo.Mvc.UI" />
@@ -35,6 +35,11 @@
3535
<remove name="TRACEVerbHandler" />
3636
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
3737
</handlers>
38+
<security>
39+
<requestFiltering>
40+
<requestLimits maxQueryString="32768" />
41+
</requestFiltering>
42+
</security>
3843
</system.webServer>
3944
<runtime>
4045
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

0 commit comments

Comments
 (0)