From a4648d37c5e403f4a81309c7ce69f4576937db64 Mon Sep 17 00:00:00 2001 From: James Yeung Date: Sun, 31 Oct 2021 14:23:03 +0800 Subject: [PATCH] feat(module: table): reload data with specific page index and size (#2072) --- components/table/ITable.cs | 2 ++ components/table/Table.razor.Pagination.cs | 37 +++++++++++++++++++++- components/table/Table.razor.cs | 10 ++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/components/table/ITable.cs b/components/table/ITable.cs index 93a01f38..67319f1e 100644 --- a/components/table/ITable.cs +++ b/components/table/ITable.cs @@ -6,6 +6,8 @@ namespace AntDesign { void ReloadData(); + void ReloadData(int? pageIndex, int? pageSize = null); + QueryModel GetQueryModel(); void SetSelection(string[] keys); diff --git a/components/table/Table.razor.Pagination.cs b/components/table/Table.razor.Pagination.cs index b6774505..84fc8ff5 100644 --- a/components/table/Table.razor.Pagination.cs +++ b/components/table/Table.razor.Pagination.cs @@ -1,4 +1,5 @@ -using System.Text.RegularExpressions; +using System; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; @@ -134,5 +135,39 @@ namespace AntDesign StateHasChanged(); } + + private void ChangePageSize(int pageSize) + { + pageSize = Math.Max(1, pageSize); + + if (_pageSize == pageSize) + { + return; + } + + _pageSize = pageSize; + + if (PageSizeChanged.HasDelegate) + { + PageSizeChanged.InvokeAsync(_pageSize); + } + } + + private void ChangePageIndex(int pageIndex) + { + pageIndex = Math.Max(1, pageIndex); + + if (_pageIndex == pageIndex) + { + return; + } + + _pageIndex = pageIndex; + + if (PageIndexChanged.HasDelegate) + { + PageIndexChanged.InvokeAsync(_pageIndex); + } + } } } diff --git a/components/table/Table.razor.cs b/components/table/Table.razor.cs index fe7dc785..cf4d6cfe 100644 --- a/components/table/Table.razor.cs +++ b/components/table/Table.razor.cs @@ -217,6 +217,16 @@ namespace AntDesign this.ReloadAndInvokeChange(); } + public void ReloadData(int? pageIndex, int? pageSize = null) + { + ChangePageIndex(pageIndex ?? 1); + ChangePageSize(pageSize ?? PageSize); + + FlushCache(); + + this.ReloadAndInvokeChange(); + } + public QueryModel GetQueryModel() => BuildQueryModel(); private QueryModel BuildQueryModel()