Collections
Structr.Collections package is intended to help organize search results collections into pagination-friendly arrays, which provide all needed data to display page control buttons in UI. Instance of package main class - PageList
- contains data about page number, page size, first and last pages of whole selection, etc.
Installation
Collections package is available on NuGet.
Usage
Let's imagine we have some set of goods gotten from database using search criteria "fruits":
But for some reason we could show only 3 items from search results per page. So, user will get totally 5 pages and currently will see one of them. Let it be the second one. Than after using all skips and takes in our SQL-query we'll get something like this:
Before sending this result to presentation level, it will be nice to send some pagination info along with fruits
-list to provide data you need for user control generation purpose. These are: buttons with page numbers, arrows, total count info. At this moment PagedList
comes to our help:
totalItems
parameter (which is 13) usually comes from first SQL COUNT(*)
-like query intended to get total count of elements in search before applying SKIP
and TAKE
operators. The second and third parameters here are: pageNumber
and pageSize
respectively. Based on such result
you can successfully create user interface or provide info about search results to you API-client.
Properties
TotalItems
int
Gets declared total count of items in superset collection.
PageNumber
int
Gets current page number.
PageSize
int
Gets page size.
TotalPages
int
Gets total count of pages.
HasPreviousPage
bool
Determines if there is a page before current.
HasNextPage
bool
Determines if there is a page after current.
IsFirstPage
bool
Determines whether current page is the first one.
IsLastPage
bool
Determines whether current page is the last one.
FirstItemOnPage
int
Gets number of first item on page.
LastItemOnPage
int
Gets number of last item on page.
Count
int
Gets count of items on page.
Static methods
Empty
PagedList<T>
Creates an empty paged list.
Extensions
To easily get a paged list from the original list use extension methods:
It is very common to convert an existing paged list of items of one type (Entities for example) into an paged list of items of another type (DTO for example).
For such conversion it is best to use AutoMapper extensions.
Use SerializablePagedList
class with ToSerializablePagedList()
and ToPagedList()
methods if you need serialize and deserialize a paged list (to JSON for example):
Last updated