Coder Social home page Coder Social logo

dataneek / paginable-collections Goto Github PK

View Code? Open in Web Editor NEW
57.0 5.0 12.0 240 KB

PaginableCollections is a set of abstractions and extensions used to provide developers with a consistent way to paginate their data across all .NET (and .NET Core) application stacks.

License: MIT License

C# 76.88% PowerShell 15.62% Shell 7.50%
paginable queryable collections extensions paging page pager

paginable-collections's People

Contributors

alexinea avatar dataneek avatar kronic avatar wshirey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

paginable-collections's Issues

Page 0 when querying empty collections

There is an issue when a collection is empty, the paginable has PageNumber = 0. This is odd... it should show PageNumber = 1, even though no items are being returned.

UI Page Information

I usually embed this within a pagination control. Look to adding it to the framework:

const int MaximumPageNumbersToDisplay = 5;

var firstPageToDisplay = 1;
var lastPageToDisplay = Model.TotalPageCount;
var pageNumbersToDisplay = lastPageToDisplay;

if (Model.TotalPageCount > MaximumPageNumbersToDisplay)
{
    var maxPageNumbersToDisplay = MaximumPageNumbersToDisplay;
    firstPageToDisplay = Model.PageNumber - maxPageNumbersToDisplay / 2;
    if (firstPageToDisplay < 1)
    {
        firstPageToDisplay = 1;
    }
    pageNumbersToDisplay = maxPageNumbersToDisplay;
    lastPageToDisplay = firstPageToDisplay + pageNumbersToDisplay - 1;
    if (lastPageToDisplay > Model.TotalPageCount)
    {
        firstPageToDisplay = Model.TotalPageCount - maxPageNumbersToDisplay + 1;
    }
}

var totalPageNumber = Model.TotalPageCount;
if (totalPageNumber == 0)
{
    totalPageNumber = 1;
}

Extension Method to Easily Convert Enumerable to a Paginable

Create an extension method to help users get pages of data from static generic collections.

For example, examine the integer array below.

var integers = new int[] { 2, 4, 6, 8, 10, 14 };

To get a page of this data (i.e page 2, where each page has 3 items), we would first, need to convert the collection to an IQueryable (by converting it to a List), and then to our specific page, such as:

var paginable = integers.ToList().AsQueryable().ToPaginable(2, 3);

That is not fun :(.

A better syntax would be:

var paginable = integers.ToPaginable(2, 3);

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.