This is a migrated thread and some comments may be shown as answers.

Grid Error (Server side binding and client side paging, sorting, etc)

12 Answers 718 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Romel
Top achievements
Rank 1
Romel asked on 06 May 2014, 01:22 PM
Hi all, I am hoping to get some valuable feedback and answers from this forum, since I am at wits end, trying to figure out this error:  =)

I have an MVC4 application using the Kendo Grid and I am trying to implement something similar to the example given here:

http://demos.telerik.com/kendo-ui/web/grid/local-data.html

The demo has a code snippet like this:
@model IEnumerable<Kendo.Mvc.Examples.Models.ProductViewModel>

@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ProductName).Title("Product Name");
columns.Bound(p => p.UnitPrice).Title("Unit Price").Width(130);
columns.Bound(p => p.UnitsInStock).Title("Units In Stock").Width(130);
columns.Bound(p => p.Discontinued).Width(130);
})
.Pageable()
.Sortable()
.Scrollable(scr=>scr.Height(430))
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(false)
)
)

and for the controller, like this:
using System.Web.Mvc;

namespace Kendo.Mvc.Examples.Controllers
{
public partial class GridController : Controller
{
public ActionResult Local_Data()
{
var model = productService.Read();

return View(model);
}
}
}

The grid in my application is bound from server side and would like to do the paging, sorting and etc from the client side once it's bound and displayed in the view. It is very much set up like the example given above. I tried to Google this hoping to get some tips and I stumbled upon this Telerik thread:

http://www.telerik.com/forums/grid-server-side-binding-and-client-side-paging-sorting-etc

The Telerik staff mentioned in this forum that "This can be achieved by setting DataSource ServerOperation setting to false and pass the data to the Grid constructor". So, I followed his advice and also followed the demo given, however, my grid is always failing and gives me an error about "maxJsonLength" property and JavaScript serializer. Any advice on how I go about this? I tried changing the maxJson length property in web.config, but that did not work.

So, is what I am trying to accomplish possible? Is there something I am missing? Thanks very much for your time and I look forward to the response(s).

Romel

12 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 06 May 2014, 02:05 PM | edited on 06 Sep 2021, 09:48 AM
Hello Romel,


Please take a look at the following documentation page, which describes the possible resolutions for the issue.

I hope this information helps.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Romel
Top achievements
Rank 1
answered on 06 May 2014, 11:21 PM
Thanks for the post Dimiter. I actually finally figured it out.... =)  Thanks for the assist.

Romel
0
Travis
Top achievements
Rank 1
answered on 31 Jul 2015, 02:05 PM
How does that link's solution help when the viewmodel collection is bound server side? I can see how it works for client side binding where you have a specific read action on your datasource, but not for server bound.
0
Dimiter Madjarov
Telerik team
answered on 03 Aug 2015, 09:03 AM

Hello Travis,

The issue is not related to the server binding of the Grid. Are you experiencing any difficulties with it?

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Travis
Top achievements
Rank 1
answered on 03 Aug 2015, 01:27 PM
@(Html.Kendo().Grid(Model.SearchResults)

... 

.DataSource(dataSource => dataSource.Ajax().PageSize(10).ServerOperation(false))

 

I am binding on server then wanting all of the sorting and paging on the client. It seems the grid is making a "behind the scenes" call to serialize the datasource for use on the client. How can I hook in to that serialization and increase the max json size?

0
Romel
Top achievements
Rank 1
answered on 03 Aug 2015, 06:06 PM

Hey Travis,

Can you also post the code for how you populate your Model.SearchResults and the Controller as well. Also, can you post the entire code for how you're constructing the grid (Razor)? The way I figured this is out is I accidentally saw that my Model for the grid is populating all of its properties when being created in the controller via its constructor. One of the properties is "Comments" and could get very long..... =) So, I eventually created a ViewModel and customized it to what I need to present/display on my grid. 

Hope this helps, and if not, post your code and we can take a look.

 

Romel

0
Dimiter Madjarov
Telerik team
answered on 04 Aug 2015, 07:59 AM | edited on 06 Sep 2021, 09:47 AM

Hello Travis,

The current Grid is still using an Ajax dataSource, so it is depending on the JavaScriptSerializer. I would suggest to check the following documentation page, which demonstrates how to increase the MaxJsonLength. You should also assure that there are no circular references in the model.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Travis
Top achievements
Rank 1
answered on 05 Aug 2015, 02:40 PM

Yes I looked at that link as it was referred to in the original post and reply.

The ajax part of the datasource is so that sorting and filtering on done on the client while the data is bound through the view model in the grid constructor's razor code.

The exception occurs in the razor view where it seems it is serializing the view model data for use on the client. It looks to be happening "behind the scenes" I do not see anyway to hook in to this and provide a custom json serializer. If I add a read action to the datasource it won't have the form post data which contains the search criteria the grid's data is based on.

0
Romel
Top achievements
Rank 1
answered on 05 Aug 2015, 10:07 PM
Post your code for the Model, Controller and Razor code as to how you're constructing the grid.
0
Dimiter Madjarov
Telerik team
answered on 06 Aug 2015, 07:54 AM

Hello Travis,

Please provide an isolated runnable example that demonstrates the issue (here or in a separate support ticket), so we could inspect it locally and pin-point the reason for the problem.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Travis
Top achievements
Rank 1
answered on 28 Apr 2016, 07:00 PM

All of the documentation links for this post are 404 - I am still running into this issue.

Please change your internal code so that it follows this example when it is serialized

var json = Json(result, JsonRequestBehavior.AllowGet);

json.MaxJsonLength = Int32.MaxValue;

return json;

 

I cannot hook in to this through an MVC controller. You are serializing for the client as part of this code

.DataSource(dataSource => dataSource.Ajax().PageSize(10).ServerOperation(false))

The grid is server bound to the View Model in the cshtml

 

0
Dimiter Madjarov
Telerik team
answered on 29 Apr 2016, 10:44 AM | edited on 06 Sep 2021, 09:46 AM

Hello Travis,

Indeed some of the documentation links have been moved. Here is the correct one for the article you are looking for.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Maya
Top achievements
Rank 1
commented on 02 Sep 2021, 03:02 PM

I also have the same issue mentioned in this thread. None of the document link is working here. How can get those help?
Ivan Danchev
Telerik team
commented on 06 Sep 2021, 09:49 AM

Hello Maya,

The old invalid links have been replaced with working ones.

Tags
Grid
Asked by
Romel
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Romel
Top achievements
Rank 1
Travis
Top achievements
Rank 1
Share this question
or