From d1f1227a4f953ea11e9e4469070a8d2c59fea07f Mon Sep 17 00:00:00 2001 From: Andrzej Bakun Date: Fri, 5 Mar 2021 16:58:38 +0100 Subject: [PATCH] feat(module: table): add OnExpand event (#1208) --- components/table/Column.razor.cs | 5 ++++- components/table/ITable.cs | 2 ++ components/table/Table.razor.cs | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/components/table/Column.razor.cs b/components/table/Column.razor.cs index b72d9a36..4cc7a659 100644 --- a/components/table/Column.razor.cs +++ b/components/table/Column.razor.cs @@ -191,8 +191,11 @@ namespace AntDesign private void ToggleTreeNode() { + bool expandValueBeforeChange = RowData.Expanded; RowData.Expanded = !RowData.Expanded; - Table?.Refresh(); + Table?.OnExpandChange(RowData.CacheKey); + if (RowData.Expanded != expandValueBeforeChange) + Table?.Refresh(); } private void FilterSelected(TableFilter filter) diff --git a/components/table/ITable.cs b/components/table/ITable.cs index 2e8ac321..154c6e0a 100644 --- a/components/table/ITable.cs +++ b/components/table/ITable.cs @@ -28,6 +28,8 @@ namespace AntDesign internal void SelectionChanged(); + internal void OnExpandChange(int cacheKey); + internal void Refresh(); internal void ReloadAndInvokeChange(); diff --git a/components/table/Table.razor.cs b/components/table/Table.razor.cs index f23d1bb2..8e384572 100644 --- a/components/table/Table.razor.cs +++ b/components/table/Table.razor.cs @@ -103,6 +103,9 @@ namespace AntDesign [Parameter] public Func, string> ExpandedRowClassName { get; set; } = _ => ""; + [Parameter] + public EventCallback> OnExpand { get; set; } + [Parameter] public SortDirection[] SortDirections { get; set; } = SortDirection.Preset.Default; @@ -145,8 +148,17 @@ namespace AntDesign int ITable.ExpandIconColumnIndex => ExpandIconColumnIndex; int ITable.TreeExpandIconColumnIndex => _treeExpandIconColumnIndex; bool ITable.HasExpandTemplate => ExpandTemplate != null; + SortDirection[] ITable.SortDirections => SortDirections; + void ITable.OnExpandChange(int cacheKey) + { + if (OnExpand.HasDelegate && _dataSourceCache.TryGetValue(cacheKey, out var currentRowData)) + { + OnExpand.InvokeAsync(currentRowData); + } + } + public void ReloadData() { PageIndex = 1;