I am using Telerik Grid MVC with AJAX binding.
I thought that if I provide IQueryable to the grid, paging/sorting/filtering would be done at the database server. Like so:
[GridAction]
public ActionResult Select()
{
return View(new GridModel(Mapper.Map<IEnumerable<DokumentVM>>(db.Dokumenti)));
}
I created test data of about 10000 documents in database, and upper command resulted in each of them hauled into the grid. And obviously, it takes forever.
Grid is bound via AJAX, like this:
@(Html.Telerik().Grid<ViewModels.DokumentVM>()
.DataBinding(b => b.Ajax().Select("Select", "Dokument"))
.Pageable(p => p.PageSize(20))
.Sortable(s => s.SortMode(GridSortMode.MultipleColumn).OrderBy(m => { m.Add("Date").Descending(); m.Add("Number").Descending(); })))
Inside Select ActionMethod, when inspecting Request (its Form), I see that grid sends all info needed for proper functioning:
page: 1
size: 20
orderBy: Date-desc~Number-desc
But when I further inspect SQL command sent to database, I see that there is only SELECT command present, no WHERE, no ORDER by, no nothing, which brings down all my data.
I am wondering if it is possible for Paging/Sorting/Filtering to work automatically, or do I need to translate info sent by the grid into SQL commands myself. I was under impression that all I needed is to provide IQueryable and Grid would do the rest. But that’s not working for me.
Maybe I am doing something wrong, or maybe this is not even possible?
The problem is using AutoMapper! when you call this line :
at first , AutoMapper tries to convert all of your
db.Dokumentirows into new form in memory function. After that the mapped data passes to GridModel. All things about paging and ordering happens inside this class.So you should avoid using AutoMapper at this level and using a different strategy. for example you can make a query like this :
and then pass the
qvariable intoGridModelclass.