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

Grid Paging when not directly connected to the model

6 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 17 Jan 2013, 12:25 PM
Hi,

I'm having a problem with paging where the whole data set is return each turn rather than just the records that are due to appear on that page of the grid.

If I connect straight to the model e.g.

var model = new Context();

var reqassess = model.ReqAssesses;

return reqassess;


Then the query will select the top 30 records etc

But in our projects we tend to have a service layer and repositories
Controller:

public ActionResult Products_Read([DataSourceRequest] DataSourceRequest request)
{
            return Json(GetRequests().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

GetRequests method:

var reqassess = reqAssessService.GetReqAssess();
return reqassess;


Service layer:

public IEnumerable<ReqAssess> GetReqAssess()

{

 return _repository.GetReqAssess();

}

Repository

public IEnumerable<ReqAssess> GetReqAssess()

{      
return _context.ReqAssesses.Where(r => r.CompId == "TEST").ToList();
}

When I do it this way it returns the whole dataset everytime, which causes significant performance problems. Are you able to help me with this at all?

Thanks

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 21 Jan 2013, 09:37 AM
Hello Ben,

 This may happen if you forgot to include kendo.aspnetmvc.min.js to your project. The latter is vital for sending the right paging info to the controller. 

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ben
Top achievements
Rank 1
answered on 21 Jan 2013, 05:18 PM
Hi,

Thanks for your reply.

I have these js files being loaded and in this order:

<script src="~/Scripts/jquery.min.js" type="text/javascript"></script>

<script src="~/Scripts/kendo.web.min.js" type="text/javascript"></script>

<script src="~/Scripts/kendo.aspnetmvc.min.js"></script>

And if I change the data retrieval techinque just to grab the data straight from the model in the controller then it works just as it should. So I think i'm ok in terms of the javascript files included. Do yooiu have any other ideas?

Thanks for your help.

Ben

 

 

 

 

 

0
Atanas Korchev
Telerik team
answered on 22 Jan 2013, 07:02 AM
Hello Ben,

 Unfortunately we are out of more ideas. Could you show us how your grid configuration looks like? Ideally  you could send us a running subset of your project which we can troubleshoot.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ben
Top achievements
Rank 1
answered on 23 Jan 2013, 11:09 AM
Hi

I've connected my files up to an SQL CE instance, i assuming i'm still getting the same problem but as I can't profile the queries in SQL CE i can't be certain but if I switch the connection string back to my sql server then I can see that the grid is requesting all rows from the table with each page (which is 600,000 odd rows).

I've attached a copy of my files, I really appreciate all your help with this as it seems like a great tool but i need to prove this part works before i can get authorisation to purchase it.

Thanks

Ben
0
Accepted
Atanas Korchev
Telerik team
answered on 23 Jan 2013, 11:31 AM
Hi Ben,

 The ToDataSourceResult extension method would perform paging in the database only if you use an IQueryable returned by a linq-enabled provider (Entity Framework, Linq to SQL etc). Your code returns all data even before giving it to the grid. This is what the ToList() method does - it executes the query and retrieves all items. Try returning an IQueryable instead:

public IQueryable<ReqAssess> GetReqAssess()

{       
       return _context.ReqAssesses.Where(r => r.CompId == "TEST");
}


If this is not feasible you need to implement the paging yourself:

public IEnumerable<ReqAssess> GetReqAssess(int take, int skip)

{       
return _context.ReqAssesses.Where(r => r.CompId == "TEST").Skip(skip).Take(take).ToList();
}



All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ben
Top achievements
Rank 1
answered on 23 Jan 2013, 12:03 PM
Thanks for your help, I knew it would be something obvious I was missing. IQueryable is fine for our purposes.

Thanks
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ben
Top achievements
Rank 1
Share this question
or