16

I am trying to refresh a Kendo UI grid but have not yet been successful. Would anybody please advise what I missed or what I did wrong?

I have the following code:

.cshtml:

 $('#btnRefresh').click(function (e){

            $.ajax({
                type: 'POST',
                url: "@(Url.Content("~/Administration/RefreshAll/"))",

                success: function () {
                    $("#Product").data("kendoGrid").dataSource.read();
                    $('#Product').data('kendoGrid').refresh();
                    //grid.refresh();
                    location.reload(true);
                },
                error: function (){
                    $("#btnRefresh").removeAttr('disabled');
                }
            });


      });

Controller:

public ActionResult RefreshAll([DataSourceRequest] DataSourceRequest request)
        {
            db.ProcessAll();
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            return View();
        }

1 Answer 1

36

your script should be

$('#btnRefresh').click(function (e){
        var grid = $("#Product").data("kendoGrid");
               grid.dataSource.page(1);
               grid.dataSource.read();
      });

in your controller add references to

  • using Kendo.Mvc.UI;
  • using Kendo.Mvc.Extensions;

your ActionResult should be

public ActionResult RefreshAll([DataSourceRequest] DataSourceRequest request)
        {
            //assuming db.ProcessAll() will return a list object
            return Json(db.ProcessAll().ToDataSourceResult(request));
        }
4
  • public void ProcessAll() therefore i could not return as JSON
    – Spidey
    May 9, 2013 at 21:49
  • You need to pass a list object to model.
    – HaBo
    May 9, 2013 at 22:22
  • @HaBo Thanks, but this gives "TypeError: $(...).data(...) is undefined" error. I also looked on many pages and tried different variations of this solution but still get the same error. Any idea?
    – Jack
    Dec 5, 2015 at 15:36
  • @chrisrof check your selectors for grid
    – HaBo
    Dec 6, 2015 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.