Pagination

Pagination is a process of dividing a collection of items into chunks (pages). In most cases it is done because of performance considerations related to the amount of data that needs to be transfered across layer/process/server boundaries.

Getting a range of items from a collection

    using OpenWaves.Pagination;

    ...

    var range = collection.GetRange(firstItemIndex, maxItemsCount);


If a collection implements ILazyCollection<T>, GetRange extension method will use ILazyCollection.GetRange(...).
If a collection implements IQuerable<T>, GetRange method will use Querable.Skip(...).Take(...).
If a collection does not implement any of the above, GetRange method will use Enumerable.Skip(...).Take(...).

Paginating a collection

Paginate extension method can be used to divide a collection into pages of equal size.

    using OpenWaves.Pagination;

    ...

    var pages = collection.Paginate(5); // 5 items per page

    var numberOfPages = pages.Count();

    var firstPage = pages.First();

    var firstPageItems = firstPage.GetItems();    

Pages returned by Paginate implement IPage<T> providing, in addition to items of the page, additional information about the page such as index of the page and index of the first and last item on the page.

    public interface IPage<out T>
    {
        int Index { get; }
        int FirstItemIndex { get; }
        int LastItemIndex { get; }
        IEnumerable<T> GetItemsRange();
    }

Ass long as IPage<T>.GetItemsRange() is not called, paginated collection is not enumerated. Implementation of GetItemsRange() depends on GetRange extension method trying to get the range in an effective manner.

Paginated UI

See: Paginated UI

Last edited Jul 12, 2011 at 1:55 PM by mgrzyb, version 4

Comments

No comments yet.