enisn / AutoFilterer

AutoFilterer is a mini filtering framework library for dotnet. The main purpose of the library is to generate LINQ expressions for Entities over DTOs automatically. The first aim is to be compatible with Open API 3.0 Specifications
MIT License
458 stars 37 forks source link

about PaginationFilter return query result. #62

Closed neozhu closed 1 year ago

neozhu commented 1 year ago

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

neozhu commented 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);
    }
}
enisn commented 1 year ago

You may use ApplyFilterWithoutPagination method to get count.

var items = await source.ApplyFilter(filter);
var count = await filter.ApplyFilterWithoutPagination(source).CountAsync();
neozhu commented 1 year ago

thank you for your reply