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();