using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; namespace AntDesign { public partial class Table : ITable { [Parameter] public bool HidePagination { get; set; } /// /// topLeft | topCenter | topRight |bottomLeft | bottomCenter | bottomRight /// [Parameter] public string PaginationPosition { get => _paginationPosition; set { _paginationPosition = value; InitializePagination(); } } [Parameter] public int Total { get => _total > _dataSourceCount ? _total : _dataSourceCount; set { _total = value; } } [Parameter] public EventCallback TotalChanged { get; set; } [Parameter] public int PageIndex { get; set; } = 1; [Parameter] public EventCallback PageIndexChanged { get; set; } [Parameter] public int PageSize { get; set; } = 10; [Parameter] public EventCallback PageSizeChanged { get; set; } [Parameter] public EventCallback OnPageIndexChange { get; set; } [Parameter] public EventCallback OnPageSizeChange { get; set; } private int _total = 0; private int _dataSourceCount = 0; private string _paginationPosition = "bottomRight"; private string _paginationClass; private void InitializePagination() { _paginationClass = $"ant-table-pagination ant-table-pagination-{Regex.Replace(_paginationPosition, "bottom|top", "").ToLowerInvariant()}"; } private async Task HandlePageIndexChange(PaginationEventArgs args) { PageIndex = args.PageIndex; await PageIndexChanged.InvokeAsync(args.PageIndex); await OnPageIndexChange.InvokeAsync(args); ReloadAndInvokeChange(); StateHasChanged(); } private void HandlePageSizeChange(PaginationEventArgs args) { PageSize = args.PageSize; ReloadAndInvokeChange(); PageSizeChanged.InvokeAsync(args.PageSize); OnPageSizeChange.InvokeAsync(args); } } }