Git Product home page Git Product logo

b9_pagination's Introduction

B9_Pagination

Version Downloads

Extensions for simple pagination

How to use?

You can use PaginationQuery model for set pagination parameter

var pagination = new PaginationQuery(pageNumber: 1, pageSize: 10);

var paginationResult = await items
    .Where(x => x.Id > 10)
    .GetPaginationAsync(pagination);

or set directly in method

var paginationResult = await items
    .Where(x => x.Id > 10)
    .GetPaginationAsync(pageNumber: 1, pageSize: 10);

Check out the sample project

You can use pagination in API endpoints

[HttpGet]
[ProducesResponseType(typeof(IPagination<GetShortAccountDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetClientAccounts(
       [FromQuery] PaginationQuery pagination = default,
       [FromQuery] FilterDto filter = default,
       UserEnums.SortBy? sortBy = default,
       CancellationToken cancellationToken = default)
       => (await _accountService.GetAccountsAsync(pagination, filter, sortBy, cancellationToken)).ToActionResult();

What if you need to do something(Select,Where,GroupBy,etc) with the data before doing pagination?

You can use Pager<T> and manage validation yourself

var mappedItems = items
    .GroupBy(dto => dto.Name)
    .Select(g => new UserDto
    {
       Name = g.Key,
       Contacts = g.Select(dto => new UserContactDto
       {
          Email = dto.Email,
          Count = dto.Count
       })
     })
     .ToList();

var totalCount = mappedItems.Count();
var pager = new Pager<UserDto>(totalCount, pagination.PageNumber, pagination.PageSize);

if (!pager.IsValidPage)
       return pager.GetEmptyPagination();

return pager.GetPagination(mappedItems);

Additionaly if you need just map type you can use extension methods for map with AutoMapper GetPaginationWithMapAsync(this IQueryable<object> items, PaginationQuery pagination, IMapper mapper, CancellationToken cancellationToken = default) or GetPaginationWithMapAsync<TResult>(this IQueryable<object> items, PaginationQuery pagination, IConfigurationProvider configurationProvider, CancellationToken cancellationToken = default)

b9_pagination's People

Contributors

bodikborn avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.