Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatTable features #749

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/MatBlazor.Demo/Demo/DemoTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
<h5 class="mat-h5">Example</h5>
<DemoContainer>
<Content>
<MatTable Items="@cars" class="mat-elevation-z5">
<MatTable Items="@cars" class="mat-elevation-z5" OnRowsGenerating="() => TestRowGenerating()">
<MatColGroup>
<colgroup>
<col span="1" style="width: 60%;">
<col span="1" style="width: auto;">
<col span="1" style="width: auto;">
</colgroup>
</MatColGroup>
<MatTableHeader>
<th>Name</th>
<th>Price</th>
Expand All @@ -18,6 +25,10 @@

@code
{
void TestRowGenerating()
{
System.Diagnostics.Debug.WriteLine("RowGenerating called successful.");
}

public class Car
{
Expand Down Expand Up @@ -49,7 +60,14 @@
</Content>
<SourceContent>
<BlazorFiddle Template="MatBlazor" Code=@(@"
<MatTable Items=""@cars"" class=""mat-elevation-z5"">
<MatTable Items=""@cars"" class=""mat-elevation-z5"" OnRowsGenerating=""() => TestRowGenerating()"">
<MatColGroup>
<colgroup>
<col span=""1"" style=""width: 60%;"">
<col span=""1"" style=""width: auto;"">
<col span=""1"" style=""width: auto;"">
</colgroup>
</MatColGroup>
<MatTableHeader>
<th>Name</th>
<th>Price</th>
Expand Down Expand Up @@ -90,6 +108,12 @@
new Car(""Ford Mondeo"", 16000, 120),
};

void TestRowGenerating()
{
System.Diagnostics.Debug.WriteLine(""RowGenerating called successful."");
}


}

")></BlazorFiddle>
Expand Down
18 changes: 16 additions & 2 deletions src/MatBlazor/Components/MatTable/MatTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
<CascadingValue Value="@this">
<table class="@ClassMapper.AsString()" style="@StyleMapper.AsString()" @ref="Ref" @attributes="Attributes" Id="@Id">
@MatColGroup
<thead>
@if (UseSortHeaderRow)
{
Expand All @@ -27,6 +28,7 @@
<tbody>
@if (ItemList != null)
{
@CallRowGenerating()
@foreach (var item in ItemList)
{
<TableRow Class="@RowClass"
Expand Down Expand Up @@ -109,6 +111,10 @@
[Parameter]
public RenderFragment<TableItem> MatTableRow { get; set; }

[Parameter]
public RenderFragment MatColGroup { get; set; }


/// <summary>
/// Not Functioning
/// </summary>
Expand All @@ -123,6 +129,9 @@

protected IEnumerable<TableItem> ItemList { get; set; }

[Parameter]
public Action OnRowsGenerating { get; set; }

private string[] FilteredColumns => FilterByColumnName?.Split(";") ?? Array.Empty<string>();

protected override async Task OnInitializedAsync()
Expand Down Expand Up @@ -154,7 +163,7 @@
if (PageSize <= 0)
PageSize = 5;
}

StartPage = 1;
CurrentPage = StartPage;

Expand Down Expand Up @@ -458,7 +467,7 @@

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 => x.GetValue(item, null)?.ToString() != null).Select(x => x.GetValue(item, null).ToString());

if (!values.Any())
{
Expand All @@ -474,4 +483,9 @@
return filteredCollection;
}

string CallRowGenerating()
{
OnRowsGenerating?.Invoke();
return "";
}
}