简体   繁体   English

动态滚动Telerik MVC网格

[英]Dynamic Scrolling Telerik MVC Grid

I am trying to take off the pagination from a couple of Telerik MVC Grids that have a large amount of data loaded into them (upwards of 5000, probably more once they hit production). 我正在尝试从几个已加载大量数据的Telerik MVC网格中分页(多达5000个,一旦投入生产,可能还会更多)。 With our smaller grids, I would just take off the Pageable property(see code below) and the scrolling functionality just works. 在较小的网格中,我将取消Pageable属性(请参见下面的代码),并且滚动功能才起作用。

With the larger grids I get a JSON error saying that the length of the string exceeds the value set on the maxJsonLength property. 对于较大的网格,我会收到JSON错误,表明字符串的长度超过了在maxJsonLength属性上设置的值。 I updated the webconfig to be set to the max value as per this links suggestion but it still gave me the same error. 我已根据此链接建议将webconfig更新为最大值,但仍给我相同的错误。

The version of Telerik that I am using is plain Telerik(not Kendo) and is the MVC version (main UI DLL is Telerik.Web.MVC, version 2012.2.801.340). 我使用的Telerik版本是普通的Telerik(不是Kendo),并且是MVC版本(主UI DLL是Telerik.Web.MVC,版本2012.2.801.340)。

All documentation that I have found either points me to the new version of Kendo or a RadGrid, which is not included/supported in my version. 我找到的所有文档都将我指向Kendo的新版本或RadGrid,而我的版本不包含或不支持该版本。

Is there a way to acheive this, either by loading it all at once like this does here , or creating a dynamically loading grid using the Telerik version I have, or am I out of luck? 是否有办法做到这一点,或者像在这里那样一次全部加载,或者使用我拥有的Telerik版本创建一个动态加载网格,还是我不走运? I am also open to suggestions for another way to achieve this, but the results have to be in a Grid of some sort. 我也乐于接受其他建议来实现这一目标,但是结果必须在某种形式的Grid中。

Below is the basic code for what I have for all grids. 以下是我对所有网格都有的基本代码。 The larger grids that I am having issues with have more columns than this one which help account for the JSON error. 我遇到的较大的网格具有比该网格更多的列,这有助于解决JSON错误。

@(Html.Telerik().Grid<ApportionmentCode>()
                .DataBinding(dataBinding => dataBinding.Ajax().Select("AjaxGetAppCodes", "AppCode"))
                .Name("Grid")
                .Columns(columns =>
                {
                    columns.Bound(o => o.Id)
                           .Title("ID")
                           .Width(50)
                           .HtmlAttributes(new { @class = "text-center" })
                           .Hidden();
                    columns.Bound(o => o.Code)
                           .Title("AppCode")
                           .Width(90)
                           .HtmlAttributes(new { @class = "text-center" });
                    columns.Bound(o => o.Description)
                           .Title("Description")
                           .HtmlAttributes(new { style = "min-width: 200px;" })
                           .ClientTemplate("<span class=\"clip tooltip\"><#= Description #></span>");
                    columns.Command(commands =>
                    {
                        commands.Custom("edit")
                                .Text("Edit")
                                .ButtonType(GridButtonType.Image)
                                .Action("Edit", "AppCode")
                                .ImageHtmlAttributes(new { @class = "t-edit", title = "Edit" })
                                .DataRouteValues(route => route.Add(o => o.Id));
                    })
                    .Width(78)
                    .HtmlAttributes(new { @class = "nowrap" })
                    .IncludeInContextMenu(false);
                })
                .ToolBar(commands => commands.Custom()
                                             .Text("Add")
                                             .Action("Create", "AppCode", Request.GetRouteValues())
                                             .ButtonType(GridButtonType.ImageAndText)
                                             .ImageHtmlAttributes(new { @class = "t-add" })
                                             .HtmlAttributes(new { @class = "addButton" }))
                .Filterable()
                .ClientEvents(events =>
                                {
                                    events.OnDataBound("onDataBound");
                                    events.OnComplete("AddGridFilter");
                                    events.OnLoad("OnGridLoad");
                                })
                .ColumnContextMenu()
                .Sortable()
                .Pageable(paging => paging.PageSize(20).Style(GridPagerStyles.NextPreviousAndNumeric).Position(GridPagerPosition.Bottom)) //When removed, this is the line that causes the JSON error
                .Resizable(resizing => resizing.Columns(true))
                .Scrollable(a => a.Height("auto")))

Thanks in advance 提前致谢

In the controller, I assume you have something like: 在控制器中,我假设您具有以下内容:

DataSourceResult result = model.ToDataSourceResult(request);
return Json(result, JsonRequestBehavior.AllowGet);

If you use the Newtonsoft package and change it to this, this should allow a larger amount of data through. 如果您使用Newtonsoft软件包并将其更改为该软件包,则应允许处理大量数据。

DataSourceResult result = model.ToDataSourceResult(request);
var json = Newtonsoft.Json.JsonConvert.SerializeObject(result);
return Content(json, "text/json");

EDIT: 编辑:

If the problem is too much data and you don't want paging, how about trying virtualization by adding: 如果问题是数据过多,并且您不希望分页,那么如何通过添加以下内容来尝试虚拟化:

.Scrollable(scrollable => scrollable.Virtual(true))

You'll still need a page size, an example is here: http://demos.telerik.com/aspnet-mvc/grid/virtualization-remote-data 您仍然需要页面大小,此处是一个示例: http : //demos.telerik.com/aspnet-mvc/grid/virtualization-remote-data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM