2020-07-10 17:57:20 +08:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-06-02 19:15:15 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
2020-07-10 17:57:20 +08:00
|
|
|
|
public partial class Table<TItem> : ITable
|
2020-06-02 19:15:15 +08:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
2020-06-16 14:44:21 +08:00
|
|
|
|
public bool HidePagination { get; set; }
|
2020-06-02 19:15:15 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// topLeft | topCenter | topRight |bottomLeft | bottomCenter | bottomRight
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter]
|
2020-07-02 20:30:01 +08:00
|
|
|
|
public string PaginationPosition
|
|
|
|
|
{
|
|
|
|
|
get => _paginationPosition;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_paginationPosition = value;
|
2020-07-10 17:57:20 +08:00
|
|
|
|
InitializePagination();
|
2020-07-02 20:30:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-02 19:15:15 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-07-10 17:57:20 +08:00
|
|
|
|
public int Total
|
|
|
|
|
{
|
|
|
|
|
get => _total > _dataSourceCount ? _total : _dataSourceCount;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_total = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-02 19:15:15 +08:00
|
|
|
|
|
2020-06-03 00:22:10 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<int> TotalChanged { get; set; }
|
|
|
|
|
|
2020-06-02 19:15:15 +08:00
|
|
|
|
[Parameter]
|
2020-11-08 16:55:34 +08:00
|
|
|
|
public int PageIndex
|
|
|
|
|
{
|
|
|
|
|
get => _pageIndex;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_pageIndex != value)
|
|
|
|
|
{
|
|
|
|
|
_pageIndex = value;
|
|
|
|
|
_waitingReloadAndInvokeChange = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-28 12:51:36 +08:00
|
|
|
|
|
2020-06-03 00:22:10 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<int> PageIndexChanged { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-11-08 16:55:34 +08:00
|
|
|
|
public int PageSize
|
|
|
|
|
{
|
|
|
|
|
get => _pageSize;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_pageSize != value)
|
|
|
|
|
{
|
|
|
|
|
_pageSize = value;
|
|
|
|
|
_waitingReloadAndInvokeChange = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-28 12:51:36 +08:00
|
|
|
|
|
2020-06-03 00:22:10 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<int> PageSizeChanged { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<PaginationEventArgs> OnPageIndexChange { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<PaginationEventArgs> OnPageSizeChange { get; set; }
|
|
|
|
|
|
2021-02-28 12:51:36 +08:00
|
|
|
|
private int _total;
|
|
|
|
|
private int _dataSourceCount;
|
2020-07-02 20:30:01 +08:00
|
|
|
|
private string _paginationPosition = "bottomRight";
|
|
|
|
|
private string _paginationClass;
|
2020-11-08 16:55:34 +08:00
|
|
|
|
private int _pageIndex = 1;
|
|
|
|
|
private int _pageSize = 10;
|
2020-06-02 19:15:15 +08:00
|
|
|
|
|
2020-07-10 17:57:20 +08:00
|
|
|
|
private void InitializePagination()
|
2020-07-02 20:30:01 +08:00
|
|
|
|
{
|
|
|
|
|
_paginationClass = $"ant-table-pagination ant-table-pagination-{Regex.Replace(_paginationPosition, "bottom|top", "").ToLowerInvariant()}";
|
|
|
|
|
}
|
2020-06-03 00:22:10 +08:00
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
private async Task HandlePageChange(PaginationEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (_pageIndex != args.Page)
|
|
|
|
|
{
|
|
|
|
|
await HandlePageIndexChange(args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_pageSize != args.PageSize)
|
|
|
|
|
{
|
|
|
|
|
await HandlePageSizeChange(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 17:57:20 +08:00
|
|
|
|
private async Task HandlePageIndexChange(PaginationEventArgs args)
|
2020-06-03 00:22:10 +08:00
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
_pageIndex = args.Page;
|
2020-07-08 16:12:49 +08:00
|
|
|
|
|
2021-03-06 10:20:41 +08:00
|
|
|
|
if (PageIndexChanged.HasDelegate)
|
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
await PageIndexChanged.InvokeAsync(args.Page);
|
2021-03-06 10:20:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (OnPageIndexChange.HasDelegate)
|
|
|
|
|
{
|
|
|
|
|
await OnPageIndexChange.InvokeAsync(args);
|
|
|
|
|
}
|
2020-07-08 16:12:49 +08:00
|
|
|
|
|
2020-07-10 17:57:20 +08:00
|
|
|
|
ReloadAndInvokeChange();
|
2020-06-19 23:06:33 +08:00
|
|
|
|
|
2020-07-10 17:57:20 +08:00
|
|
|
|
StateHasChanged();
|
2020-06-03 00:22:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 23:26:49 +08:00
|
|
|
|
private async Task HandlePageSizeChange(PaginationEventArgs args)
|
2020-06-03 00:22:10 +08:00
|
|
|
|
{
|
2021-03-06 10:20:41 +08:00
|
|
|
|
_pageSize = args.PageSize;
|
2020-07-08 16:12:49 +08:00
|
|
|
|
|
2021-03-06 10:20:41 +08:00
|
|
|
|
if (PageSizeChanged.HasDelegate)
|
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
await PageSizeChanged.InvokeAsync(args.PageSize);
|
2021-03-06 10:20:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (OnPageSizeChange.HasDelegate)
|
|
|
|
|
{
|
2021-03-11 23:26:49 +08:00
|
|
|
|
await OnPageSizeChange.InvokeAsync(args);
|
2021-03-06 10:20:41 +08:00
|
|
|
|
}
|
2021-03-11 23:26:49 +08:00
|
|
|
|
|
|
|
|
|
ReloadAndInvokeChange();
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
2020-06-03 00:22:10 +08:00
|
|
|
|
}
|
2020-06-02 19:15:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|