mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-02 20:17:58 +08:00
fix(module: table): refresh when datasource is changed (#298)
* fix(module: table): refresh when datasource is changed
This commit is contained in:
parent
7cc424c0f0
commit
9730d73cf4
@ -6,8 +6,8 @@
|
||||
<Spin Spinning="Loading">
|
||||
@if (!HidePagination && PaginationPosition.Contains("top"))
|
||||
{
|
||||
<Pagination Class="@PaginationClass"
|
||||
Total="Total"
|
||||
<Pagination Class="@_paginationClass"
|
||||
Total="ActualTotal"
|
||||
PageSize="PageSize"
|
||||
Current="PageIndex"
|
||||
OnPageIndexChange="HandlePageIndexChange"
|
||||
@ -66,8 +66,8 @@
|
||||
</CascadingValue>
|
||||
@if (!HidePagination && PaginationPosition.Contains("bottom"))
|
||||
{
|
||||
<Pagination Class="@PaginationClass"
|
||||
Total="Total"
|
||||
<Pagination Class="@_paginationClass"
|
||||
Total="ActualTotal"
|
||||
PageSize="PageSize"
|
||||
Current="PageIndex"
|
||||
OnPageIndexChange="HandlePageIndexChange"
|
||||
|
@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
@ -16,7 +14,15 @@ namespace AntDesign
|
||||
/// topLeft | topCenter | topRight |bottomLeft | bottomCenter | bottomRight
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string PaginationPosition { get; set; } = "bottomRight";
|
||||
public string PaginationPosition
|
||||
{
|
||||
get => _paginationPosition;
|
||||
set
|
||||
{
|
||||
_paginationPosition = value;
|
||||
SetPaginationClass();
|
||||
}
|
||||
}
|
||||
|
||||
[Parameter]
|
||||
public int Total { get; set; }
|
||||
@ -42,13 +48,18 @@ namespace AntDesign
|
||||
[Parameter]
|
||||
public EventCallback<PaginationEventArgs> OnPageSizeChange { get; set; }
|
||||
|
||||
private IEnumerable<TItem> ShowItems => Total > 0 ? DataSource : DataSource.Skip((PageIndex - 1) * PageSize).Take(PageSize);
|
||||
private IEnumerable<TItem> ShowItems => Total > _total ? _dataSource : _dataSource.Skip((PageIndex - 1) * PageSize).Take(PageSize);
|
||||
|
||||
private int ActualTotal => Total > 0 ? Total : _total;
|
||||
private int ActualTotal => Total > _total ? Total : _total;
|
||||
|
||||
private int _total = 0;
|
||||
private string _paginationPosition = "bottomRight";
|
||||
private string _paginationClass;
|
||||
|
||||
private string PaginationClass => $"ant-table-pagination ant-table-pagination-{Regex.Replace(PaginationPosition, "bottom|top", "").ToLowerInvariant()}";
|
||||
private void SetPaginationClass()
|
||||
{
|
||||
_paginationClass = $"ant-table-pagination ant-table-pagination-{Regex.Replace(_paginationPosition, "bottom|top", "").ToLowerInvariant()}";
|
||||
}
|
||||
|
||||
private void HandlePageIndexChange(PaginationEventArgs args)
|
||||
{
|
||||
|
@ -17,8 +17,9 @@ namespace AntDesign
|
||||
get => _dataSource;
|
||||
set
|
||||
{
|
||||
_total = value.Count();
|
||||
_dataSource = value;
|
||||
_total = value?.Count() ?? 0;
|
||||
_dataSource = value ?? Enumerable.Empty<TItem>();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,6 +59,7 @@ namespace AntDesign
|
||||
public ColumnContext ColumnContext { get; set; } = new ColumnContext();
|
||||
|
||||
private IEnumerable<TItem> _dataSource;
|
||||
|
||||
private ISelectionColumn _headerSelection;
|
||||
|
||||
ISelectionColumn ITable.HeaderSelection
|
||||
@ -73,7 +75,7 @@ namespace AntDesign
|
||||
var list = new List<TItem>();
|
||||
foreach (var index in checkedIndex)
|
||||
{
|
||||
list.Add(DataSource.ElementAt(index));
|
||||
list.Add(_dataSource.ElementAt(index));
|
||||
}
|
||||
|
||||
SelectedRowsChanged.InvokeAsync(list);
|
||||
@ -105,6 +107,7 @@ namespace AntDesign
|
||||
base.OnInitialized();
|
||||
|
||||
SetClass();
|
||||
SetPaginationClass();
|
||||
}
|
||||
|
||||
private void ChangeSelection(int[] indexes)
|
||||
|
Loading…
Reference in New Issue
Block a user