From 6208e44668970b0a0857a1445c30dd1da0bf644e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Kova=C4=8D?= Date: Mon, 3 Aug 2020 11:26:48 +0200 Subject: [PATCH 1/3] Update MatTable.razor Fixed a null reference exception. --- src/MatBlazor/Components/MatTable/MatTable.razor | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/MatBlazor/Components/MatTable/MatTable.razor b/src/MatBlazor/Components/MatTable/MatTable.razor index 1d78a878..0e839049 100644 --- a/src/MatBlazor/Components/MatTable/MatTable.razor +++ b/src/MatBlazor/Components/MatTable/MatTable.razor @@ -458,7 +458,17 @@ foreach (var item in items) { - var values = properties.Where(x => x.GetValue(item, null).ToString() != null).Select(x => x.GetValue(item, null).ToString()); + var values = properties.Where(x => { + var tmp = x.GetValue(item, null); + if(tmp == null || tmp.ToString() == null) + { + return false; + } + else + { + return true; + } + }).Select(x => x.GetValue(item, null).ToString()); if (!values.Any()) { From 9acfb052a3b9b80556c18dd56a8b5ba6ac6d117a Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 8 Oct 2020 15:46:12 -0700 Subject: [PATCH 2/3] one line logic --- src/MatBlazor/Components/MatTable/MatTable.razor | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/MatBlazor/Components/MatTable/MatTable.razor b/src/MatBlazor/Components/MatTable/MatTable.razor index 0e839049..40496e96 100644 --- a/src/MatBlazor/Components/MatTable/MatTable.razor +++ b/src/MatBlazor/Components/MatTable/MatTable.razor @@ -458,17 +458,7 @@ foreach (var item in items) { - var values = properties.Where(x => { - var tmp = x.GetValue(item, null); - if(tmp == null || tmp.ToString() == null) - { - return false; - } - else - { - return true; - } - }).Select(x => x.GetValue(item, null).ToString()); + var values = properties.Where(x => x.GetValue(item, null)?.ToString() != null).Select(x => x.GetValue(item, null).ToString()); if (!values.Any()) { From 34cf229a1621c59324172a844e6ffbbd0e064661 Mon Sep 17 00:00:00 2001 From: Henrique Clausing Date: Sat, 10 Oct 2020 15:12:44 -0300 Subject: [PATCH 3/3] Suggested implementations: - ColGroup tag before ; - OnRowGenerating custom action, after rendering. It will allow to create dictionaries (by ex.) with object instance (from list) and ElementReference. It's usefull when you want to create a button on TableRow with drop down Menu, for set its reference to Menu instance when clicked. --- src/MatBlazor.Demo/Demo/DemoTable.razor | 28 +++++++++++++++++-- .../Components/MatTable/MatTable.razor | 16 ++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/MatBlazor.Demo/Demo/DemoTable.razor b/src/MatBlazor.Demo/Demo/DemoTable.razor index f36474a4..0379e3ff 100644 --- a/src/MatBlazor.Demo/Demo/DemoTable.razor +++ b/src/MatBlazor.Demo/Demo/DemoTable.razor @@ -3,7 +3,14 @@
Example
- + + + + + + + + Name Price @@ -18,6 +25,10 @@ @code { + void TestRowGenerating() + { + System.Diagnostics.Debug.WriteLine("RowGenerating called successful."); + } public class Car { @@ -49,7 +60,14 @@ + TestRowGenerating()""> + + + + + + + Name Price @@ -90,6 +108,12 @@ new Car(""Ford Mondeo"", 16000, 120), }; + void TestRowGenerating() + { + System.Diagnostics.Debug.WriteLine(""RowGenerating called successful.""); + } + + } ")> diff --git a/src/MatBlazor/Components/MatTable/MatTable.razor b/src/MatBlazor/Components/MatTable/MatTable.razor index 609c355a..fdf03291 100644 --- a/src/MatBlazor/Components/MatTable/MatTable.razor +++ b/src/MatBlazor/Components/MatTable/MatTable.razor @@ -14,6 +14,7 @@ } + @MatColGroup @if (UseSortHeaderRow) { @@ -27,6 +28,7 @@ @if (ItemList != null) { + @CallRowGenerating() @foreach (var item in ItemList) { MatTableRow { get; set; } + [Parameter] + public RenderFragment MatColGroup { get; set; } + + /// /// Not Functioning /// @@ -123,6 +129,9 @@ protected IEnumerable ItemList { get; set; } + [Parameter] + public Action OnRowsGenerating { get; set; } + private string[] FilteredColumns => FilterByColumnName?.Split(";") ?? Array.Empty(); protected override async Task OnInitializedAsync() @@ -154,7 +163,7 @@ if (PageSize <= 0) PageSize = 5; } - + StartPage = 1; CurrentPage = StartPage; @@ -474,4 +483,9 @@ return filteredCollection; } + string CallRowGenerating() + { + OnRowsGenerating?.Invoke(); + return ""; + } }