You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

PaginatedListAync

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

PaginatedListAync

The paginate_items function is designed to handle pagination for a given dataset. It takes three input parameters: data (list or array): The dataset to be paginated. page_number (integer): The current page number you want to retrieve. page_size (integer): The number of items to display per page. The function calculates the necessary pagination information based on the input parameters and returns a dictionary containing the following key-value pairs: "Items": A list of items for the specified page. "PageNumber": The current page number. "TotalPages": The total number of pages required to display all the data with the given page size. "TotalCount": The total count of items in the dataset. "HasPreviousPage": A boolean indicating whether there is a previous page before the current page. "HasNextPage": A boolean indicating whether there is a next page after the current page. This function helps you efficiently manage and retrieve paginated data, making it useful for implementing pagination in web applications or APIs when dealing with large datasets.

1.0.0
nugetNuGet
Version published
Maintainers
1
Created
Source

IQueryable Pagination Function

Function: PaginateQueryable<T>

Purpose: Efficiently paginate data retrieved from IQueryable sources, particularly useful for database queries with Entity Framework or LINQ to SQL.

Parameters:

  • data (IQueryable): The data source to paginate.
  • pageNumber (int): The current page number (1-based index).
  • pageSize (int): Number of items per page.

Return Value: A PaginationResult<T> with:

  • Items: List of data elements for the specified page.
  • PageNumber: Current page number.
  • TotalPages: Total pages required.
  • TotalCount: Total items in the dataset.
  • HasPreviousPage: True if a previous page exists.
  • HasNextPage: True if a next page exists.

Usage: Include the function, create an IQueryable query, call PaginateQueryable, and access the result for efficient pagination.

Example:

IQueryable<MyEntity> query = dbContext.MyEntities.Where(e => e.IsActive);
int pageNumber = 2;
int pageSize = 10;
var paginatedList = await query.PaginateQueryable(pageNumber, pageSize,cancellationToken);

Performance: Optimizes data retrieval by minimizing database queries for large datasets.


Contributions: Contributions welcome.

Contact: [Sourav Das] at [sourav99166@gmail.com].

Keywords

FAQs

Package last updated on 06 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts