Closed joeaudette closed 9 years ago
hi Joe
It wouldn't be very hard to program an alternative/overload but I'm having a hard time to see how to get that into the public interface. I assume that the alternative interface would be something like:
public static Pager Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalPages)
This is exactly the same signature as the existing method. An alternative I can think of is adding a new option that indicates that totalItemCount means totalPages, but that's quite hacky in my opinion.
Ideas?
Hi Martijn,
Yes, I thought that might be a problem. I guess possible options would be to make a method signature that takes a new class for paging parameters that would encapsulate all the parameters together like:
public class PagingInfo
{
private int totalpages = 1;
public int TotalPages
{
get { return totalpages; }
set { totalpages = value; }
}
private int itemsPerPage = 10;
public int ItemsPerPage
{
get { return itemsPerPage; }
set { itemsPerPage = value; }
}
private int currentPage = 1;
public int CurrentPage
{
get { return currentPage; }
set { currentPage = value; }
}
}
or after aspnet vnext the object could be an assembly neutral interface https://github.com/aspnet/Home/wiki/Assembly-Neutral-Interfaces
or if you don't like that idea, what about an alternate method name to avoid the signature clash? I guess the hard part is thinking of a good alternate name
After having given it a little bit more thought I think the least intrusive way is to add an extra option. Not pretty, but easy to program and not too hard to use:
@Html.Pager(10, 1, 3).UseItemCountAsPageCount()
The main advantage of adding it as an option is that most users probably won't notice.
That seems like a reasonable solution to me, I understand the other alternatives are even less pretty. It would be great if you implement that, I would certainly use it and give up implementing my own pager.
Alright let's do it.
Excellent! Thank You! I'll keep an eye out for the next Nuget update.
New version is on NuGet. Enjoy!
Wow! That was fast! Thank you very much!
I confirm it is working great! Many thanks!
Good to hear. Closing the issue :)
Hi Martijn,
I started working on my own pager for mvc but found yours which looks very nice. One problem for me is that the project I'm working on already has data access methods for returning a page of data, we pass in the page size and current page number and it gives us totalPages as an output parameter rather than totalItems.
I was wondering if you would consider implementing support/overloads for passing that in as an alternative to totalItems which is currently used to calculate totalpages inside the pager code?
Thanks, Joe