How can I integrate Telerik Grid paging for ASP.NET MVC (http://demos.telerik.com/aspnet-mvc/Grid) with my NHibernate data access with minimal coding?
+1
A:
I really don't know what your standards for minimal coding are but on Telerik site you provided there's a quite verbose example:
public partial class GridController : Controller
{
public ActionResult FirstLook(bool? ajax, bool? scrolling, bool? paging, bool? filtering, bool? sorting, bool? grouping, bool? showFooter)
{
ViewData["ajax"] = ajax ?? true;
ViewData["scrolling"] = scrolling ?? true;
ViewData["paging"] = paging ?? true;
ViewData["filtering"] = filtering ?? true;
ViewData["grouping"] = grouping ?? true;
ViewData["sorting"] = sorting ?? true;
ViewData["showFooter"] = showFooter ?? true;
return View(GetOrderDto());
}
[GridAction]
public ActionResult _FirstLook()
{
return View(new GridModel(GetOrderDto()));
}
}
So all you need to do is implement this GetOrderDto
method (which by the way should be placed in some repository and not part of the controller logic) in which you would use your existing NHibernate data access.
Darin Dimitrov
2010-03-19 22:03:56
All what you explained is what I have already done. However, GetOrderDto() reads ALL orders from the database and returns IEnumerable<Order> which will be used by Telerik Grid to render the correct page. I want to retreive from the database only the needed page using NHibernate data access.
Khalil Dahab
2010-03-19 22:24:50
When you click on a page number the grid posts this number to the controller action. Once you have the current page and the number of rows you would like to show per page you could use `SetFirstResult` and `SetMaxResult` on your NHibernate query to paginate the result set (http://stackoverflow.com/questions/54754/how-can-you-do-paging-with-nhibernate).
Darin Dimitrov
2010-03-19 22:33:37