简体   繁体   English

使用MVCContrib网格进行服务器端分页

[英]Server side paging with MVCContrib grid

I have to use stored procedures to fetch and page data. 我必须使用存储过程来获取和分页数据。 This particular stored procedure has all sorts of parameters, including paging information. 该特定存储过程具有各种参数,包括寻呼信息。 Obviously, paging needs to be done server side, one page of data needs to be fetched each time a user selects a new page. 显然,需要在服务器端完成分页,每次用户选择新页面时都需要提取一页数据。

I'm trying to get this work with MVCContrib, but it seems to me that the grid and its pager support only local paging and filtering. 我正在尝试使用MVCContrib进行此工作,但在我看来,网格及其寻呼机仅支持本地分页和过滤。 Number of available pages is determined by the number of already present items in the collection, or so it seems to me. 可用页面的数量取决于集合中已存在的项目的数量,或者在我看来。

Is there a way to make MVCContrib work with server side paging? 有没有办法让MVCContrib与服务器端分页一起工作?

There is a class called CustomPagination in MVCContrib. MVCContrib中有一个名为CustomPagination的类。 The constructor takes following arguments 构造函数采用以下参数

(Enumerable<T> dataSource, int pageNumber, int pageSize, int totalItems)

Then you pass that to the Grid and Pager. 然后将其传递给Grid和Pager。

You'll need to implement the IPagination interface yourself, add a page parameter to your action method then pass this into your stored procedure to get the appropriate collection of items. 您需要自己实现IPagination接口,向action方法添加一个page参数,然后将其传递给存储过程以获取相应的项集合。 Then populate each of the IPagination properties from this and your knowledge of how your stored procedure works. 然后从中填充每个IPagination属性以及您对存储过程如何工作的了解。

If you want more concrete examples of this, a sample of your stored procedure (or cut down version of it) may be helpful. 如果您需要更具体的示例,您的存储过程示例(或其缩减版本)可能会有所帮助。

"Number of available pages is determined by the number of already present items in the collection, or so it seems to me." “可用页面的数量取决于集合中已存在的项目的数量,或者在我看来。”

Perhaps you're looking at samples that are using a flavour of LINQ. 也许您正在查看使用LINQ风格的样本。 This does not necessarily mean that the entire collection is in memory. 这并不一定意味着整个集合都在内存中。 Also, even if they are in memory, I would still call this server side paging - To me, client side paging in a web application means javascript. 此外,即使它们在内存中,我仍然会调用此服务器端分页 - 对我来说,Web应用程序中的客户端分页意味着javascript。

PS: this may help you get started, though by the sounds of it you will need to ignore the Entity Framework bits of it: PS:这可能会帮助你开始,虽然通过它的声音,你将需要忽略它的实体框架位:

http://weblogs.asp.net/rajbk/archive/2010/05/08/asp-net-mvc-paging-sorting-filtering-using-the-mvccontrib-grid-and-pager.aspx http://weblogs.asp.net/rajbk/archive/2010/05/08/asp-net-mvc-paging-sorting-filtering-using-the-mvccontrib-grid-and-pager.aspx

Where they use the "AsPagination()" extension you'll need to call your stored procedure and populate your own implementation of IPagination. 如果他们使用“AsPagination()”扩展名,您需要调用存储过程并填充自己的IPagination实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM