Nudes.Paginator.Core 2.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Nudes.Paginator.Core --version 2.0.4                
NuGet\Install-Package Nudes.Paginator.Core -Version 2.0.4                
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="Nudes.Paginator.Core" Version="2.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nudes.Paginator.Core --version 2.0.4                
#r "nuget: Nudes.Paginator.Core, 2.0.4"                
#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 Nudes.Paginator.Core as a Cake Addin
#addin nuget:?package=Nudes.Paginator.Core&version=2.0.4

// Install Nudes.Paginator.Core as a Cake Tool
#tool nuget:?package=Nudes.Paginator.Core&version=2.0.4                

Paginator

Paginator is a c# lib for handling pagination and transfer of data and use on client libraries

Installation

if you need all packages (mostly on Backend with ASPNETCore)

dotnet add package Nudes.Paginator

but you can also use its individual packages and configure to your specific need

dotnet add package Nudes.Paginator.Core
dotnet add package Nudes.Paginator.Validator

Usage

Nudes.Paginator.Core

The core lib contains only what you would call a DTO or the protocol/contract of pagination, it is used to make an contract between server and clients on how paged data will be transfered. If you are on a client you will require only this or one of it's specific libs that we are planning like blazor and xamarin

Usually requests will received on the following query data: Page; PageSize; Field; Sorting Direction and any custom data that you will use to filter data

NOTICE: For user-friendlyness this lib considers the first page as 1 and not 0

Return data will always follow the following contract

{
    "pagination" : {
        "page": 13,
        "pageSize": 40,
        "sorting": [
            {
                "field": "property",
                "sortDirection": 0
            }
        ],
        "total": 5000,
        "pageCount": 125,
        "isFirstPage": false,
        "isLastPage": false
    },
    "items" : []
}

The in facto pagination methods are extensions on top of IQueryable<T> hence can work on top of EFCore

PageRequest request = GetPageRequest();
IQueryable<T> data = GetData();

var total = await data.CountAsync(); //required to calculate page data correctly

//the second parameter of PaginateBy is the default field for Sorting, if request has an field specified the specified field will be used if Descending Sort is desired use PagineByDescending
var items = await data.PaginateBy(request, d=> d.Field) 
    .Select(d => MapToResult(d))
    .ToListAsync();

return request.ToResult(items, total);

FluentValidation

This lib will be mostly used on server as well and is a default implementation of an validator of PagedRequest, you can use it directly or you can create your own and include it's validation

public class SpecificValidator : AbstractValidator<MyRequest>
{
    public SpecificValidator()
    {
        //MyRequest must inherit from PagedRequest
        this.Include(new PageRequestValidator<MyRequest>()); 
        
        //insert your specific business validation here like
        RuleFor(d=> d.Type).NotEmpty();
    }
}

Client side and sorting

On the client side sorting information will be received through the query param sorting, this param is mapped to an array and should be passed as such: ?sorting[0].field=fieldName&sorting[0].sortDirection=ascending being an array also means we can have a multi-field sorting.

This lib also accepts complex property as a field name, just call separated through a '.' as you would on c# code firstLevelProperty.secondLevelProperty.thirdLevelProperty, just remember that these properties will be matched against the type you are invoking .PaginateBy so the clients would have access to your DTOs and should not know the real types you are storing on your database, so be sure to map/project to DTO before paginating

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Nudes.Paginator.Core:

Package Downloads
Nudes.Paginator.FluentValidation

Paginator is a lib to help with pagination in projects the Idea is to be used heavily on the backend but as well be used on clients like blazor and xamarin

Nudes.Paginator

Paginator is a lib to help with pagination in projects the Idea is to be used heavily on the backend but as well be used on clients like blazor and xamarin

Nudes.Paginator.EfCore

Paginator is a lib to help with pagination in projects the Idea is to be used heavily on the backend but as well be used on clients like blazor and xamarin

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.6 541 10/31/2023
2.0.5 209 10/31/2023
2.0.4 334 9/29/2023
2.0.3 213 9/29/2023
2.0.2 212 9/29/2023
1.0.780 4,352 3/11/2022
1.0.738 1,243 2/16/2022
1.0.494 800 10/5/2020
1.0.491 775 10/5/2020
1.0.490 683 10/5/2020
1.0.488 798 10/4/2020