QuickPaginator 1.0.9

There is a newer version of this package available.
See the version list below for details.
dotnet add package QuickPaginator --version 1.0.9                
NuGet\Install-Package QuickPaginator -Version 1.0.9                
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.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add QuickPaginator --version 1.0.9                
#r "nuget: QuickPaginator, 1.0.9"                
#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.9

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

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;
	
    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 301 11/26/2023
1.0.20 735 11/26/2022
1.0.19 387 10/28/2022
1.0.18 355 10/28/2022
1.0.17 383 10/16/2022
1.0.16 413 10/16/2022
1.0.15 397 10/16/2022
1.0.14 404 10/15/2022
1.0.13 406 10/14/2022
1.0.12 394 10/12/2022
1.0.11 403 10/12/2022
1.0.10 416 10/4/2022
1.0.9 445 9/29/2022
1.0.8 435 9/27/2022
1.0.7 448 9/27/2022
1.0.6 427 9/26/2022
1.0.5 460 9/26/2022
1.0.4 465 9/26/2022
1.0.3 372 9/26/2022
1.0.2 446 9/26/2022
1.0.1 424 9/26/2022

Updated the documentation.