mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-05 05:27:37 +08:00
63d09f76a5
* feat: add pagination and empty * fix: indent * feat(module: table): add checkbox selection * feat(module: table): add radio selection * feat: add selected rows
70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public partial class Table<TItem>
|
|
{
|
|
[Parameter]
|
|
public bool ShowPagination { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// topLeft | topCenter | topRight |bottomLeft | bottomCenter | bottomRight
|
|
/// </summary>
|
|
[Parameter]
|
|
public string PaginationPosition { get; set; } = "bottomRight";
|
|
|
|
[Parameter]
|
|
public int Total { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> TotalChanged { get; set; }
|
|
|
|
[Parameter]
|
|
public int PageIndex { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> PageIndexChanged { get; set; }
|
|
|
|
[Parameter]
|
|
public int PageSize { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> PageSizeChanged { get; set; }
|
|
|
|
[Parameter]
|
|
public bool ClientSide { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<PaginationEventArgs> OnPageIndexChange { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<PaginationEventArgs> OnPageSizeChange { get; set; }
|
|
|
|
private IEnumerable<TItem> ShowItems => !ClientSide ? DataSource : DataSource.Skip(_pageIndex - 1 * _pageSize).Take(_pageSize);
|
|
|
|
private int ActualTotal => !ClientSide ? Total : DataSource.Count();
|
|
|
|
private int _pageSize = 10;
|
|
private int _pageIndex = 1;
|
|
|
|
private string PaginationClass => $"ant-table-pagination ant-table-pagination-{Regex.Replace(PaginationPosition, "bottom|top", "").ToLowerInvariant()}";
|
|
|
|
private void HandlePageIndexChange(PaginationEventArgs args)
|
|
{
|
|
PageIndexChanged.InvokeAsync(args.PageIndex);
|
|
OnPageIndexChange.InvokeAsync(args);
|
|
}
|
|
|
|
private void HandlePageSizeChange(PaginationEventArgs args)
|
|
{
|
|
PageSizeChanged.InvokeAsync(args.PageSize);
|
|
OnPageSizeChange.InvokeAsync(args);
|
|
}
|
|
}
|
|
}
|