PageSort is a simple .Net Standard library that is built to ease paging, sort and filtering of IQueryable collections. This is the main repository for PageSort and its extensions.
You need to reference the PageSort namespace in your project.
Using PageSort;
collection - collection.Page(1, 20);
The Page IQueryable extension takes the pageNumber and the pageSize. It returns paged collection of the specified source query.
var pageQuery = new PageQuery{
PageNumber = 1,
PageSize = 20,
};
var collection = new IQueryable<Student>();
var pagedCollection = GeneratePaging(collection, pageQuery);
The GeneratePaging() method takes an IQueryable collection and a PageQuery object. This method returns a PageResult object.
var sortedCollection = collection.OrderByProperty(sortProperty);
var sortedCollection = collection.OrderByDescendingProperty(sortProperty);
You can also use the GeneratePaging Method to perform both paging and sorting Operations on a collection
var pageQuery = new PageQuery{
PageNumber = 1,
PageSize = 20,
SortProperty = "DateOfBirth",
SortOrder = ListSortDirection.Descending
};
var collection = new IQueryable<Student>();
var pagedCollection = GeneratePaging(collection, pageQuery);
Below is an example of a PageResult
{
CurrentPage = 1,
PageSize = 20,
TotalCount = 200,
TotalPages = 10,
Collection = collection,
PreviousPage = true,
NextPage = true
}
- CurrentPage is an integer that represents the current page of the collection that is being returned
- PageSize is the size of the collection that is to be returned per page.
- TotalCount is the total number of Items in the collection for which paging is done.
- TotalPages is the total number of pages that can be generated from the collection. This value is dependant on the PageSize value that is passed.
- Collection is the list of items in the current page.
- PreviousPage is a boolean that tells whether there are previous pages or not. This is set to false if PageNumber is 1 or the collection can only have one page.
- NextPage is a boolean that tells whether there are more pages or not. It is set to false if there is only one page, or we are on the last page of the collection
First, install NuGet. Then, install PageSort from the package manager console:
PM> Install-Package PageSort
You can also install the PageSort Package using the .NET CLI
dotnet add package PageSort
You can also add the package reference to the project file of your project.
<PackageReference Include="PageSort Version="1.0.2" />
If you run into problems, please share it with me via email at stanleybarna@gmail.com
PageSort is Copyright © 2019 Stanley Barnabas Nagwere and other contributors under the MIT license.