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

13 posts, 0 answers
  1. Romel
    Romel avatar
    23 posts
    Member since:
    May 2012

    Posted 06 May 2014 Link to this post

    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
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 06 May 2014 Link to this post

    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!
     
  3. Romel
    Romel avatar
    23 posts
    Member since:
    May 2012

    Posted 06 May 2014 in reply to Dimiter Madjarov Link to this post

    Thanks for the post Dimiter. I actually finally figured it out.... =)  Thanks for the assist.

    Romel
  4. Travis
    Travis avatar
    13 posts
    Member since:
    Jul 2013

    Posted 31 Jul 2015 in reply to Dimiter Madjarov Link to this post

    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.
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 03 Aug 2015 Link to this post

    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!
     
  6. Travis
    Travis avatar
    13 posts
    Member since:
    Jul 2013

    Posted 03 Aug 2015 in reply to Dimiter Madjarov Link to this post

    @(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?

  7. Romel
    Romel avatar
    23 posts
    Member since:
    May 2012

    Posted 03 Aug 2015 in reply to Travis Link to this post

    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

  8. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 04 Aug 2015 Link to this post

    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!
     
  9. Travis
    Travis avatar
    13 posts
    Member since:
    Jul 2013

    Posted 05 Aug 2015 in reply to Dimiter Madjarov Link to this post

    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.

  10. Romel
    Romel avatar
    23 posts
    Member since:
    May 2012

    Posted 05 Aug 2015 in reply to Travis Link to this post

    Post your code for the Model, Controller and Razor code as to how you're constructing the grid.
  11. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 06 Aug 2015 Link to this post

    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!
     
  12. Travis
    Travis avatar
    13 posts
    Member since:
    Jul 2013

    Posted 28 Apr 2016 Link to this post

    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

     

  13. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 29 Apr 2016 Link to this post

    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!
     
Back to Top