QuickPaginator 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package QuickPaginator --version 1.0.6
NuGet\Install-Package QuickPaginator -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="QuickPaginator" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add QuickPaginator --version 1.0.6
#r "nuget: QuickPaginator, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install QuickPaginator as a Cake Addin
#addin nuget:?package=QuickPaginator&version=1.0.6

// Install QuickPaginator as a Cake Tool
#tool nuget:?package=QuickPaginator&version=1.0.6

Quick Paginator (.NET)

Author: Ryan Kueter
Updated: September, 2022

About

Quick Paginator is a free .NET library, available from the NuGet Package Manager, that provides a quick way to paginate a list of items.

Targets:

  • .NET 6

Use Case

The following is an example of how you would initialize the Paginator:

using QuickPaginator;

public class UsersModel : PageModel
{
    private readonly IUsersDataService _usersDataService;
	
    [BindProperty]
    public Paginator Pager { get; set; }

    [BindProperty]
    public List<User> ActiveUsers { get; set; }

    [BindProperty(SupportsGet = true)]
    public int? Number { get; set; } = 1;

    public int PageCount { get; set; } = 10;

    public UsersModel(IUsersDataService usersDataService)
    {
        _usersDataService = usersDataService;
        ActiveUsers = new();
    }

	public async Task OnGetAsync()
    {
        if (ModelState.IsValid)
        {
            var response = await _usersDataService.GetAllUsers();
            if (response.Response is not null && response.Response.IsSuccess())
            {
                var result = response.Users.ToList();

                // Paginator(<CurrentPageNumber>, <ResultCount>, <PageCount>)
                Pager = new Paginator(Number, result.Count(), PageCount);

                // Active Users
                ActiveUsers = result.Skip(Pager.Skip).Take(Pager.Take).ToList();
            }
        }
    }
}

The following is an example of how you would use the Paginator in a Razor pages application.

<nav class="app-pagination">
	@{
		var pager = Model.Pager;
	}
	<ul class="pagination justify-content-center">
		@if (pager.PageCount <= 1)
		{
			<li class="page-item active">No more results.</li>
		}
		else
		{
			@if (pager.Previous is not -1)
			{
				<li class="page-item">
					<a class="page-link" href="~/Admin/Users/@pager.First">First</a>
				</li>
				<li class="page-item">
					<a class="page-link" href="~/Admin/Users/@pager.Previous">Previous</a>
				</li>
			}
			else
			{
				<li class="page-item disabled">
					<a class="page-link" tabindex="-1" aria-disabled="true">First</a>
				</li>
				<li class="page-item disabled">
					<a class="page-link" tabindex="-1" aria-disabled="true">Previous</a>
				</li>
			}
			@foreach (var b in pager.BetweenPages)
			{
				<li class="page-item @b.Value"><a class="page-link" href="~/Admin/Users/@b.Key">@b.Key</a></li>
			}
			@if (pager.Next is not -1)
			{
				<li class="page-item">
					<a class="page-link" href="~/Admin/Users/@pager.Next">Next</a>
				</li>
				<li class="page-item">
					<a class="page-link" href="~/Admin/Users/@pager.Last">Last</a>
				</li>
			}
			else
			{
				<li class="page-item disabled">
					<a class="page-link" tabindex="-1" aria-disabled="true">Next</a>
				</li>
				<li class="page-item disabled">
					<a class="page-link" tabindex="-1" aria-disabled="true">Last</a>
				</li>
			}
		}
	</ul>
	<div class="d-flex justify-content-center">
		@if (pager.PageCount >= 1)
		{
			<span>(@pager.CurrentCount of @pager.TotalCount results)</span>
		}
	</div>
</nav>

Contributions

Quick Paginator is being developed for free by me, Ryan Kueter, in my spare time. So, if you use this library and see a need for improvement, please send your ideas.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.21 197 11/26/2023
1.0.20 622 11/26/2022
1.0.19 357 10/28/2022
1.0.18 333 10/28/2022
1.0.17 357 10/16/2022
1.0.16 386 10/16/2022
1.0.15 369 10/16/2022
1.0.14 375 10/15/2022
1.0.13 373 10/14/2022
1.0.12 370 10/12/2022
1.0.11 374 10/12/2022
1.0.10 386 10/4/2022
1.0.9 425 9/29/2022
1.0.8 410 9/27/2022
1.0.7 408 9/27/2022
1.0.6 396 9/26/2022
1.0.5 432 9/26/2022
1.0.4 426 9/26/2022
1.0.3 357 9/26/2022
1.0.2 417 9/26/2022
1.0.1 396 9/26/2022

Fixed calculation.