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

[Solved] MVC Grid + JSON paging

3 Answers 226 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ondrej
Top achievements
Rank 1
Ondrej asked on 28 Jun 2010, 08:25 AM
Hi,

Is it possible to use MVC Grid with custom paged data, which is loaded from JSON and sorted and filtered manually?
Like from DTO objects?

I dont know the way how to get this working without using IQueryable.

Thanks,

Ondrej

3 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 28 Jun 2010, 08:56 AM
Hi,

I've remembered that there was one blog post, which covers some of your requirements. You can check on this link.

Regards,
Peter
0
Ondrej
Top achievements
Rank 1
answered on 28 Jun 2010, 10:08 AM
Hi,

Thanks,
but I already checked that link some days ago, and that's not what Im looking for.

I found also this article: http://weblogs.asp.net/rashid/archive/2009/11/05/using-telerik-mvc-grid-in-crud-scenario.aspx
but always Im not sure if this is the right way of working without IQueryable...

I need to load data from JSON and paged myself, not by MVC GRID.

Thanks
0
Ondrej
Top achievements
Rank 1
answered on 28 Jun 2010, 12:41 PM
I finally found the solution,

Instead of using something from your sample at http://blogs.telerik.com/atanaskorchev/posts/09-11-09/using_telerik_grid_for_asp_net_mvc_without_any_server-side_code.aspx

And instead of using :
            var db = new NorthwindDataContext(); 
 
            return View(new GridModel<Customer> 
            { 
                Data = db.Customers 
            }); 
in: public ActionResult _AjaxBinding()

I can simulate JSON data in ajax Controller action and it work perfect:)
<
             Html.Telerik().Grid<MvcApplication1.Models.Customer>("customers") 
                 .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "Home")) 
                 .Name("grid1") 
                 .Pageable() 
                 .Sortable() 
                 .Filterable() 
                 .Groupable() 
                 .Render(); 
             %> 
public ActionResult Index() 
        { 
            ViewData["Message"] = "Welcome to ASP.NET MVC!"; 
 
            var db = new NorthwindDataContext(); 
 
            ViewData["customers"] = db.Customers; 
 
            return View(); 
        } 

[GridAction] 
        public ActionResult _AjaxBinding() 
        { 
            //var db = new NorthwindDataContext(); 
 
            //return View(new GridModel<Customer> 
            //{ 
            //    Data = db.Customers 
            //}); 
 
            int page = Convert.ToInt32(Request.Form["page"]); 
            int size = Convert.ToInt32(Request.Form["size"]); 
 
            var db = new NorthwindDataContext(); 
 
            var jsonData = new 
            { 
                data = (from Customer cust in db.Customers 
                          select new 
                          { 
                              CustomerID = cust.CustomerID, 
                              ContactName = cust.ContactName, 
                              ContactTitle = cust.ContactTitle, 
                              CompanyName = cust.CompanyName, 
                              City = cust.City, 
                              Address = cust.Address, 
                              PostalCode = cust.PostalCode, 
                              Country = cust.Country 
                          }).Skip((page-1) * size).Take(size), 
                total = db.Customers.Count() 
            }; 
 
            return Json(jsonData, JsonRequestBehavior.AllowGet); 
        } 




Tags
Grid
Asked by
Ondrej
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Ondrej
Top achievements
Rank 1
Share this question
or