Git Product home page Git Product logo

n.pag's Introduction

N.Pag

Library to handle pagination pattern between frontend & backend side.

How it work?

N.Pag enables easy pagination mechanism by evaulate LINQ string to IQueryable interface, which can You use on Entity Framework Level to filter, sort, skip & take data! Parameters are deliver to web api by QueryParams.

How to use?

  1. Fetch nuget package.
  2. Create of implementation Your PaginationQuery class from base classes: EncodedPaginationQueryBase or PaginationQueryBase
    1. EncodedPaginationQueryBase - parameters Where & OrderBy must be encoded by base64,
    2. PaginationQueryBase - parameters are normal.
  3. Create controler method with argument of Your query.
  4. Invoke method FilterBy<TModel>(myAwesomeQuery) on the IQuerable (DbContext or other collection).
  5. Return Your awsome filtered data ๐Ÿคฃ!

Example

Endpoints

users?pageSize=20&page=2&where=c3RhdHVzID09ICJOIg== <=> where status == "N"

users?pageSize=20&where=c3RhdHVzID09ICJOIg==&orderBy=bmFtZS1kZXNj <=> order by name-desc

Queries
public class GetUsersQuery : EncodedPaginationQueryBase
{
  // Some additional fields
}
Api Methods
[HttpGet]
[ProducesResponseType(typeof(PaginationResult<User>), StatusCodes.Status200OK)]
public async Task<IActionResult> Get(GetUsersQuery query)
{
    var count = await _context.Users.Where(paginationQuery).CountAsync();
    var filtered = await _context.Users.FilterBy(paginationQuery).ToListAsync();
    
    // pagination wrapper
    var result = new PaginationResult<User>
    {
        List = filtered,
        TotalCount = count
    };
    
    return Json(result);
}

Nuget

https://www.nuget.org/packages/N.Pag/

n.pag's People

Contributors

don-flamingo avatar

Stargazers

Mark avatar

Watchers

 avatar

Forkers

bubdm

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.