Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Update (#96)
Browse files Browse the repository at this point in the history
Added Global Search
Updated to .Net Core 3.1.3
Updated Sample to Blazor 3.2.0 Preview 3
  • Loading branch information
IvanJosipovic authored Mar 31, 2020
1 parent 01f77cf commit d3516d9
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.102
dotnet-version: 3.1.201

- name: Dotnet Build
run: dotnet build --configuration Release
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.102
dotnet-version: 3.1.201

- name: SonarQube Install
run: dotnet tool install dotnet-sonarscanner --tool-path ./
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.102
dotnet-version: 3.1.201

- name: Dotnet Pack
working-directory: src/BlazorTable
Expand Down
2 changes: 1 addition & 1 deletion lgtm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ extraction:
csharp:
index:
dotnet:
version: "3.1.102"
version: "3.1.201"
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview2.20160.5" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-preview3.20175.8" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/BlazorTable.Sample.Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<span class="oi oi-home" aria-hidden="true"></span> Add Column
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="/GlobalSearch" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Global Search
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="/EmptyData" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> EmptyDataTemplate
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable.Sample.Shared/Pages/AddColumn.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

protected override async Task OnInitializedAsync()
{
data = await Http.GetJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
data = await Http.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
}

public class PersonData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
protected override async Task OnInitializedAsync()
{
data = await Http.GetJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
data = await Http.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
}
public class PersonData
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable.Sample.Shared/Pages/Detail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

protected override async Task OnInitializedAsync()
{
data = await Http.GetJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
data = await Http.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
}

public class PersonData
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable.Sample.Shared/Pages/EditMode.razor
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

protected override async Task OnInitializedAsync()
{
data = await Http.GetJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
data = await Http.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
}

public class PersonData
Expand Down
71 changes: 71 additions & 0 deletions src/BlazorTable.Sample.Shared/Pages/GlobalSearch.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@page "/GlobalSearch"

@using BlazorTable

<h1>Global Search</h1>

Search: <input type="text" class="form-controls" value="@Table?.GlobalSearch" @onchange="@(x => Table.GlobalSearch = x.Value.ToString())" />

<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true" @ref="Table">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true" />
<Column TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%" />
<Column TableItem="PersonData" Title="Email" Field="@(x => x.email)" Sortable="true" Filterable="true" Width="20%">
<Template>
<a href="mailto:@context.email">@context.email</a>
</Template>
</Column>
<Column TableItem="PersonData" Title="Paid" Field="@(x => x.paid)" Sortable="true" Filterable="true" Width="10%">
<Template>
@context.paid.ToString()
</Template>
</Column>
<Column TableItem="PersonData" Title="Price" Field="@(x => x.price)" Sortable="true" Filterable="true" Width="10%" Format="C" Align="Align.Right" />
<Column TableItem="PersonData" Title="Created Date" Field="@(x => x.created_date)" Sortable="true" Filterable="true" Width="10%">
<Template>
@(context.created_date.HasValue ? context.created_date.Value.ToShortDateString() : string.Empty)
</Template>
</Column>
<Column TableItem="PersonData" Title="Enum" Field="@(x => x.cc_type)" Sortable="true" Filterable="true" Width="10%">
<Template>
@context.cc_type
</Template>
</Column>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
{
[Inject]
private HttpClient Http { get; set; }

private ITable<PersonData> Table;

private PersonData[] data;

protected override async Task OnInitializedAsync()
{
data = await Http.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");


Console.WriteLine($"{"Astrix Mariette".IndexOf("Astrix")}");
}

public class PersonData
{
public int? id { get; set; }
public string full_name { get; set; }
public string email { get; set; }
public bool? paid { get; set; }
public decimal? price { get; set; }
public CreditCard? cc_type { get; set; }
public DateTime? created_date { get; set; }
}

public enum CreditCard
{
none = 0,
[Description("MasterCard")]
MasterCard = 1,
Visa = 2
}
}
2 changes: 1 addition & 1 deletion src/BlazorTable.Sample.Shared/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

protected override async Task OnInitializedAsync()
{
data = await Http.GetJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
data = await Http.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
}

public class PersonData
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable.Sample.Shared/Pages/Row.razor
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Selected: @(selectedItems.Any() ? selectedItems.Select(x => x.full_name).Aggrega

protected override async Task OnInitializedAsync()
{
data = await Http.GetJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
data = await Http.GetFromJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
}

public class PersonData
Expand Down
1 change: 1 addition & 0 deletions src/BlazorTable.Sample.Shared/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using System.ComponentModel
@using System.Net.Http.Json
7 changes: 3 additions & 4 deletions src/BlazorTable.Sample.Wasm/BlazorTable.Sample.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview2.20160.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview2.20160.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview2.20160.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview2.20160.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/BlazorTable.Sample.Wasm/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"BlazorTable.Sample.Wasm": {
"commandName": "Project",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
Expand Down
5 changes: 3 additions & 2 deletions src/BlazorTable/BlazorTable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.2" />
<PackageReference Include="LINQKit.Core" Version="1.1.17" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.3" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
59 changes: 57 additions & 2 deletions src/BlazorTable/Components/Table.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components;
using LinqKit;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -65,6 +66,12 @@ public partial class Table<TableItem> : ITable<TableItem>
[Parameter]
public IEnumerable<TableItem> Items { get; set; }

/// <summary>
/// Search all columns for the specified string, supports spaces as a delimiter
/// </summary>
[Parameter]
public string GlobalSearch { get; set; }

[Inject]
private ILogger<ITable<TableItem>> Logger { get; set; }

Expand All @@ -84,7 +91,7 @@ public partial class Table<TableItem> : ITable<TableItem>
public int PageNumber { get; private set; }

/// <summary>
/// Total Count of Item
/// Total Count of Items
/// </summary>
public int TotalCount { get; private set; }

Expand Down Expand Up @@ -120,6 +127,12 @@ private IEnumerable<TableItem> GetData()
}
}

// Global Search
if (!string.IsNullOrEmpty(GlobalSearch))
{
ItemsQueryable = ItemsQueryable.Where(GlobalSearchQuery(GlobalSearch));
}

TotalCount = ItemsQueryable.Count();

var sortColumn = Columns.Find(x => x.SortColumn);
Expand All @@ -136,6 +149,12 @@ private IEnumerable<TableItem> GetData()
}
}

// if the current page is filtered out, we should go back to a page that exists
if (PageNumber > TotalPages)
{
PageNumber = TotalPages - 1;
}

// if PageSize is zero, we return all rows and no paging
if (PageSize <= 0)
return ItemsQueryable.ToList();
Expand Down Expand Up @@ -395,5 +414,41 @@ private void OnRowClickHandler(TableItem tableItem)
break;
}
}

private Expression<Func<TableItem, bool>> GlobalSearchQuery(string value)
{
Expression<Func<TableItem, bool>> expression = null;

foreach (string keyword in value.Trim().Split(" "))
{
Expression<Func<TableItem, bool>> tmp = null;

foreach (var column in Columns)
{
var newQuery = Expression.Lambda<Func<TableItem, bool>>(
Expression.AndAlso(
Expression.NotEqual(column.Field.Body, Expression.Constant(null)),
Expression.GreaterThanOrEqual(
Expression.Call(
Expression.Call(column.Field.Body, "ToString", Type.EmptyTypes),
typeof(string).GetMethod(nameof(string.IndexOf), new[] { typeof(string), typeof(StringComparison) }),
new[] { Expression.Constant(keyword), Expression.Constant(StringComparison.OrdinalIgnoreCase) }),
Expression.Constant(0))),
column.Field.Parameters[0]);

if (tmp == null)
tmp = newQuery;
else
tmp = tmp.Or(newQuery);
}

if (expression == null)
expression = tmp;
else
expression = expression.And(tmp);
}

return expression;
}
}
}
13 changes: 7 additions & 6 deletions src/BlazorTable/Interfaces/ITable.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;


namespace BlazorTable
{
/// <summary>
Expand All @@ -26,7 +22,7 @@ public interface ITable
int PageNumber { get; }

/// <summary>
/// Total Count of Item
/// Total Count of Items
/// </summary>
int TotalCount { get; }

Expand Down Expand Up @@ -106,5 +102,10 @@ public interface ITable
/// Select Type: None, Single or Multiple
/// </summary>
public SelectionType SelectionType { get; set; }

/// <summary>
/// Search all columns for the specified string, supports spaces as a delimiter
/// </summary>
string GlobalSearch { get; set; }
}
}

0 comments on commit d3516d9

Please sign in to comment.