Closed neozhu closed 1 year ago
like this
public class PaginatedData<T>
{
public int CurrentPage { get; private set; }
public int TotalItems { get; private set; }
public int TotalPages { get; private set; }
public bool HasPreviousPage => CurrentPage > 1;
public bool HasNextPage => CurrentPage < TotalPages;
public IEnumerable<T> Items { get; set; }
public PaginatedData(IEnumerable<T> items, int total,int pageIndex,int pageSize)
{
Items = items;
TotalItems = total;
CurrentPage = pageIndex;
TotalPages = (int)Math.Ceiling(total / (double)pageSize);
}
public static async Task<PaginatedData<T>> CreateAsync(IQueryable<T> source, int pageIndex, int pageSize)
{
var count = await source.CountAsync();
var items = await source.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
return new PaginatedData<T>(items, count, pageIndex, pageSize);
}
}
You may use ApplyFilterWithoutPagination
method to get count.
var items = await source.ApplyFilter(filter);
var count = await filter.ApplyFilterWithoutPagination(source).CountAsync();
thank you for your reply
May I ask how to use a query based on PaginationFilterBase to return a paged data result, which should have two values of TotalPages and TotalItems to display on the pagination control of datagrid component; Hope to get your reply, thank you