Paging class, php paging class

Source: Internet
Author: User

Paging class, php paging class

 

/// <Summary> /// paging // </summary> /// <typeparam name = "T"> type </typeparam> public class PagedList <T>: list <T> {// <summary> // cache paging constructor // </summary> // <param name = "source"> data source </param> /// <param name = "pageIndex"> current page number </param> /// <param name = "pageSize"> Number of records displayed on each page </param> public pagedList (IQueryable <T> source, int pageIndex, int pageSize) {if (source = null |! Source. any () throw new ArgumentNullException ("source"); int total = source. count (); TotalCount = total; TotalPages = total/pageSize; if (total % pageSize> 0) TotalPages ++; PageSize = pageSize; PageIndex = pageIndex; AddRange (source. skip (pageIndex * pageSize ). take (pageSize ). toList ());} /// <summary> /// cache paging constructor /// </summary> /// <param name = "source"> data source </param> /// <param name = "pageIndex"> current page number </pa Ram> // <param name = "pageSize"> Number of records displayed per page </param> public PagedList (IList <T> source, int pageIndex, int pageSize) {if (source = null |! Source. any () throw new ArgumentNullException ("source"); TotalCount = source. count (); TotalPages = TotalCount/pageSize; if (TotalCount % pageSize> 0) TotalPages ++; PageSize = pageSize; PageIndex = pageIndex; AddRange (source. skip (pageIndex * pageSize ). take (pageSize ). toList ());} /// <summary> /// non-Cache paging constructor // </summary> /// <param name = "source"> data source </param> /// <param name = "pageIndex"> current page number </param> /// <Param name = "pageSize"> Number of records displayed per page </param> // <param name = "totalCount"> total number of records </param> public PagedList (IEnumerable <t> source, int pageIndex, int pageSize, int totalCount) {if (source = null |! Source. any () throw new ArgumentNullException ("source"); TotalCount = totalCount; TotalPages = TotalCount/pageSize; if (TotalCount % pageSize> 0) TotalPages ++; PageSize = pageSize; pageIndex = pageIndex; AddRange (source) ;}/// <summary >/// current page number /// </summary> public int PageIndex {get; private set ;} /// <summary> /// number of records displayed on each page /// </summary> public int PageSize {get; private set ;} /// <summary> /// total number of records /// </summary> public int TotalCount {get; private set ;} /// <summary> /// total number of pages /// </summary> public int TotalPages {get; private set ;} /// <summary> /// previous page exists /// </summary> public bool HasPreviousPage {get {return (PageIndex> 0 );}} /// <summary> /// there is a next page // </summary> public bool HasNextPage {get {return (PageIndex + 1 <TotalPages );}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.