!2298 feat(#I4Q03I): add OnSort action on Table component

* refactor: 重构 Table 组件 OnSort 回调委托
* feat: 动态多列排序功能
This commit is contained in:
Argo 2022-01-09 09:34:23 +00:00
parent 386e2a4364
commit 67cc577960
2 changed files with 33 additions and 8 deletions

View File

@ -50,10 +50,16 @@ public partial class Table<TItem>
public List<string>? SortList { get; set; } public List<string>? SortList { get; set; }
/// <summary> /// <summary>
/// 获得/设置 表头排序时回调方法 /// 获得/设置 点击表头排序时回调方法
/// </summary>
[Parameter]
public Action<string, SortOrder>? OnSort { get; set; }
/// <summary>
/// 获得/设置 内部表头排序时回调方法
/// </summary> /// </summary>
[NotNull] [NotNull]
protected Func<Task>? OnSortAsync { get; set; } protected Func<string, SortOrder, Task>? IntenralOnSortAsync { get; set; }
/// <summary> /// <summary>
/// 点击列进行排序方法 /// 点击列进行排序方法
@ -76,9 +82,9 @@ public partial class Table<TItem>
SortName = col.GetFieldName(); SortName = col.GetFieldName();
// 通知 Table 组件刷新数据 // 通知 Table 组件刷新数据
if (OnSortAsync != null) if (IntenralOnSortAsync != null)
{ {
await OnSortAsync(); await IntenralOnSortAsync(SortName, SortOrder);
} }
}; };

View File

@ -659,7 +659,14 @@ public partial class Table<TItem> : BootstrapComponentBase, IDisposable, ITable
Interop = new JSInterop<Table<TItem>>(JSRuntime); Interop = new JSInterop<Table<TItem>>(JSRuntime);
// 设置 OnSort 回调方法 // 设置 OnSort 回调方法
OnSortAsync = QueryAsync; IntenralOnSortAsync = async (sortName, sortOrder) =>
{
// 调用 OnSort 回调方法
OnSort?.Invoke(sortName, SortOrder);
// 重新查询
await QueryAsync();
};
// 设置 OnFilter 回调方法 // 设置 OnFilter 回调方法
OnFilterAsync = async () => OnFilterAsync = async () =>
@ -1116,9 +1123,21 @@ public partial class Table<TItem> : BootstrapComponentBase, IDisposable, ITable
private int GetColumnCount() private int GetColumnCount()
{ {
var colspan = ColumnVisibles.Count(col => col.Visible); var colspan = ColumnVisibles.Count(col => col.Visible);
if (IsMultipleSelect) colspan++; if (IsMultipleSelect)
if (ShowLineNo) colspan++; {
if (ShowExtendButtons) colspan++; colspan++;
}
if (ShowLineNo)
{
colspan++;
}
if (ShowExtendButtons)
{
colspan++;
}
return colspan; return colspan;
} }