From 2629130e390a7a0ee606c1cfd099e2110e480d96 Mon Sep 17 00:00:00 2001 From: Argo Date: Sat, 22 Jan 2022 03:44:32 +0000 Subject: [PATCH] =?UTF-8?q?!2343=20feat(#I4RQG7):=20add=20SortString=20par?= =?UTF-8?q?ameter=20on=20Table=20component=20*=20doc:=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20SortString=20=E7=A4=BA=E4=BE=8B=20*=20feat:=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=20SortList=20=E6=94=B9=E7=94=A8=20SortString=20*=20re?= =?UTF-8?q?factor:=20=E7=A7=BB=E9=99=A4=20SortList=20=E4=BD=BF=E7=94=A8=20?= =?UTF-8?q?SortString=20=E6=96=B9=E4=BE=BF=E4=BB=A3=E7=A0=81=E7=BC=96?= =?UTF-8?q?=E5=86=99=20*=20feat:=20=E5=A2=9E=E5=8A=A0=20SortListString=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE=E5=A4=9A?= =?UTF-8?q?=E5=88=97=E6=8E=92=E5=BA=8F=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Samples/Table/TablesFilter.razor | 4 ++-- .../Samples/Table/TablesFilter.razor.cs | 18 +++++++----------- .../Components/Table/Table.razor.Edit.cs | 2 +- .../Components/Table/Table.razor.Sort.cs | 6 +++--- .../Components/Table/Table.razor.cs | 5 ++++- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Samples/Table/TablesFilter.razor b/src/BootstrapBlazor.Shared/Samples/Table/TablesFilter.razor index adaa3477f..1870796a6 100644 --- a/src/BootstrapBlazor.Shared/Samples/Table/TablesFilter.razor +++ b/src/BootstrapBlazor.Shared/Samples/Table/TablesFilter.razor @@ -122,11 +122,11 @@ -

点击列头进行排序时,组件内部查询前调用此回调,可以在此处根据条件设置 SortList 参数,即可实现动态多列排序功能,本例中点击时间列头进行正序排序时,内部使用 DateTime, Count 倒序时使用 DateTime desc, Count desc

+

点击列头进行排序时,组件内部调用 OnSort 回调,可以在此处根据业务逻辑设置其返回值即可实现动态多列排序功能,本例中点击 时间 列头进行正序排序时,内部使用 DateTime, Count 倒序时使用 DateTime desc, Count desc

diff --git a/src/BootstrapBlazor.Shared/Samples/Table/TablesFilter.razor.cs b/src/BootstrapBlazor.Shared/Samples/Table/TablesFilter.razor.cs index 80af697f3..e89d10e81 100644 --- a/src/BootstrapBlazor.Shared/Samples/Table/TablesFilter.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Table/TablesFilter.razor.cs @@ -26,7 +26,7 @@ public partial class TablesFilter [NotNull] private IStringLocalizer? Localizer { get; set; } - private List SortList { get; } = new List { "DateTime desc", "Address" }; + private string SortString { get; set; } = "DateTime desc, Address"; /// /// OnInitialized 方法 @@ -81,28 +81,24 @@ public partial class TablesFilter }); } - private void OnSort(string sortName, SortOrder sortOrder) + private string OnSort(string sortName, SortOrder sortOrder) { + string sortString = ""; if (sortName == nameof(Foo.DateTime)) { if (sortOrder == SortOrder.Asc) { - SortList.Clear(); - SortList.Add(nameof(Foo.DateTime)); - SortList.Add(nameof(Foo.Count)); + sortString = "DateTime, Count"; } else if (sortOrder == SortOrder.Desc) { - SortList.Clear(); - SortList.Add($"{nameof(Foo.DateTime)} desc"); - SortList.Add($"{nameof(Foo.Count)} desc"); + sortString = "DateTime desc, Count desc"; } else { - SortList.Clear(); - SortList.Add($"{nameof(Foo.DateTime)} desc"); - SortList.Add(nameof(Foo.Count)); + sortString = "DateTime desc, Count"; } } + return sortString; } } diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs index ab8dc3fdb..8a02749b8 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs @@ -443,7 +443,7 @@ public partial class Table SearchText = SearchText, SortOrder = SortOrder, SortName = SortName, - SortList = SortList, + SortList = SortString?.SpanSplit(",", StringSplitOptions.RemoveEmptyEntries), Filters = Filters.Values, Searchs = GetSearchs(), AdvanceSearchs = GetAdvanceSearchs(), diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Sort.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Sort.cs index 349ee4077..dd576cbbe 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Sort.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Sort.cs @@ -44,16 +44,16 @@ public partial class Table public string SortIcon { get; set; } = "fa fa-sort"; /// - /// 获得/设置 多列排序顺序 默认为空 设置时支持 Order 后缀 "Name" "Age desc" + /// 获得/设置 多列排序顺序 默认为空 多列时使用逗号分割 如:"Name, Age desc" /// [Parameter] - public List? SortList { get; set; } + public string? SortString { get; set; } /// /// 获得/设置 点击表头排序时回调方法 /// [Parameter] - public Action? OnSort { get; set; } + public Func? OnSort { get; set; } /// /// 获得/设置 内部表头排序时回调方法 diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.cs b/src/BootstrapBlazor/Components/Table/Table.razor.cs index eee6b1ef9..ee96da3b4 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.cs @@ -663,7 +663,10 @@ public partial class Table : BootstrapComponentBase, IDisposable, ITable IntenralOnSortAsync = async (sortName, sortOrder) => { // 调用 OnSort 回调方法 - OnSort?.Invoke(sortName, SortOrder); + if (OnSort != null) + { + SortString = OnSort(sortName, SortOrder); + } // 重新查询 await QueryAsync();