Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

would you consider an option to pass in total pages instead of total items? #45

Closed
joeaudette opened this issue Nov 16, 2014 · 10 comments
Closed

Comments

@joeaudette
Copy link

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

@martijnboland
Copy link
Owner

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?

@joeaudette
Copy link
Author

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

@martijnboland
Copy link
Owner

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.

@joeaudette
Copy link
Author

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.

@martijnboland
Copy link
Owner

Alright let's do it.

@joeaudette
Copy link
Author

Excellent! Thank You! I'll keep an eye out for the next Nuget update.

martijnboland added a commit that referenced this issue Nov 17, 2014
…rn the total number of pages instead of the total number of items. Fixes issue #45.
@martijnboland
Copy link
Owner

New version is on NuGet. Enjoy!

@joeaudette
Copy link
Author

Wow! That was fast! Thank you very much!

@joeaudette
Copy link
Author

I confirm it is working great! Many thanks!

@martijnboland
Copy link
Owner

Good to hear. Closing the issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants