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

Commit

Permalink
1.9.0 (#117)
Browse files Browse the repository at this point in the history
Replaced ASCII with images
Added Page Size Selector
Fixed bug 114
Updated to popper 2.3.3
Updated Sample to Blazor Wasm RC1
  • Loading branch information
IvanJosipovic authored May 4, 2020
1 parent 42f8ac4 commit 7d0a527
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<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-preview5.20210.3" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-rc1.20217.1" />
</ItemGroup>

<ItemGroup>
Expand Down
56 changes: 56 additions & 0 deletions src/BlazorTable.Sample.Shared/Bugs/114.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@page "/114"

@using BlazorTable

<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="95%" DefaultSortColumn="true" />
<DetailTemplate TableItem="PersonData" Context="context2">
<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true" style="background-color: white;">
<Column TableItem="PersonData" Title="Actions">
<Template>
<button type="button" class="btn btn-outline-primary" @onclick="@(() => HandleClick())">Edit</button>
<button type="button" class="btn btn-outline-danger" @onclick="@(() => HandleClick())">Delete</button>
</Template>
</Column>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
</DetailTemplate>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

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

private PersonData[] data;

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

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
}

private void HandleClick()
{

}
}
3 changes: 1 addition & 2 deletions src/BlazorTable.Sample.Shared/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
</DetailTemplate>
<Pager ShowPageNumber="true" ShowTotalCount="true" />
<Pager ShowPageNumber="true" ShowTotalCount="true" ShowPageSizes="true" />
</Table>

@code
Expand Down Expand Up @@ -92,7 +92,6 @@
/// Returns row CSS if price over 800
/// </summary>
public string RowClass => price.GetValueOrDefault(0) > 800 ? "table-danger" : null;

}

public enum CreditCard
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorTable.Sample.Wasm/BlazorTable.Sample.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview4.20210.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-rc1.20223.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-rc1.20223.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-rc1.20223.4" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable.Tests/BlazorTable.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="PuppeteerSharp" Version="2.0.3" />
<PackageReference Include="PuppeteerSharp.Contrib.Extensions" Version="1.0.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorTable/BlazorTable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageId>BlazorTable</PackageId>
<Description>Blazor Table Component with Sorting, Paging and Filtering</Description>
<Authors>Ivan Josipovic</Authors>
<PackageProjectUrl>https://BlazorTable.netlify.com</PackageProjectUrl>
<PackageProjectUrl>https://BlazorTable.netlify.app</PackageProjectUrl>
<PackageTags>Blazor;Table;Component;Grid;DataTable;Data;Sort;Filter;AspNetCore;AspNet</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/IvanJosipovic/BlazorTable</RepositoryUrl>
Expand All @@ -25,7 +25,7 @@
<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">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
13 changes: 12 additions & 1 deletion src/BlazorTable/Components/Pager.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
{
<div class="d-flex justify-content-end">
<ul class="pagination">
@if (ShowPageSizes)
{
<li class="page-item" title="Set Page Size">
<select class="form-control" value="@Table.PageSize" @onchange="SetPageSize">
@foreach (int option in PageSizes)
{
<option value="@option">@option</option>
}
</select>
</li>
}
@if (ShowPageNumber)
{
<li class="page-item disabled" @onclick="@(() => Table.FirstPage())" title="Page @(Table.PageNumber + 1)/@(Table.TotalPages)">
Expand All @@ -16,7 +27,7 @@
<a class="page-link" href="#" tabindex="-1" aria-disabled="true">@Table.TotalCount</a>
</li>
}
@if ((ShowPageNumber || ShowTotalCount))
@if (ShowPageNumber || ShowTotalCount)
{
<li aria-hidden="true" class="page-item disabled">
<a class="page-link" href="#" tabindex="-1" aria-disabled="true">&nbsp;</a>
Expand Down
22 changes: 22 additions & 0 deletions src/BlazorTable/Components/Pager.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Threading;

namespace BlazorTable
{
Expand Down Expand Up @@ -27,5 +29,25 @@ public partial class Pager
/// </summary>
[Parameter]
public bool ShowTotalCount { get; set; }

/// <summary>
/// Page size options
/// </summary>
[Parameter]
public List<int> PageSizes { get; set; } = new List<int>() { 15, 30, 60 };

/// <summary>
/// Show Page Size Options
/// </summary>
[Parameter]
public bool ShowPageSizes { get; set; }

private void SetPageSize(ChangeEventArgs args)
{
if (int.TryParse(args.Value.ToString(), out int result))
{
Table.SetPageSize(result);
}
}
}
}
34 changes: 20 additions & 14 deletions src/BlazorTable/Components/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

<thead class="@TableHeadClass">
<tr style="cursor: pointer;">

@if (_detailTemplate != null)
{
<th style="width: 1%">
</th>
<th style="width: 1%"></th>
}
@foreach (IColumn<TableItem> column in Columns)
{
Expand All @@ -41,16 +39,18 @@
@if (column.SortColumn)
{
if (column.SortDescending)
{<span aria-hidden="true">&#11014;</span> }
{ <span aria-hidden="true"><img src="/_content/BlazorTable/images/sort-desc.png" /></span> }
else
{ <span aria-hidden="true">&#11015;</span>}
{ <span aria-hidden="true"><img src="/_content/BlazorTable/images/sort-asc.png" /></span> }
}

@if (column.Filterable)
{
<div class="float-right" @onclick="@((x) => column.ToggleFilter())" @onclick:stopPropagation>
<a href="javascript:;" @ref="column.FilterRef" aria-expanded="@(column.FilterOpen ? "true" : "false")" style="text-decoration: none" aria-label="@(column.Filter == null ? "unfiltered" : "filtered")">
<span aria-hidden="true" style="@(column.Filter == null ? "opacity: 0.2;" : string.Empty)">&#128269;</span>
<span aria-hidden="true" style="@(column.Filter == null ? "opacity: 0.2;" : string.Empty)">
<img src="/_content/BlazorTable/images/filter.png" />
</span>
</a>
</div>
<CascadingValue Value="column" Name="Column">
Expand Down Expand Up @@ -88,12 +88,18 @@
{
<tr @key="item" aria-selected="@(SelectedItems.Contains(item) ? "true" : null)" class="@RowClass(item) @(SelectedItems.Contains(item) ? "table-active" : "")" @onclick="(() => OnRowClickHandler(item))">

@{int locali = i;}
@{
int locali = i;
bool isOpen = detailsViewOpen.ContainsKey(locali) && detailsViewOpen[locali];
}
@if (_detailTemplate != null)
{
<td>
<a href="javascript:;" style="text-decoration: none" @onclick="@(() => { detailsViewOpen[locali] = !detailsViewOpen[locali]; StateHasChanged(); })" title="Details View" aria-expanded="@(detailsViewOpen[locali] ? "true" : "false")">
<span style="">@(detailsViewOpen[locali] ? "" : "")</span>
<a href="javascript:;" style="text-decoration: none" @onclick="@(() => { detailsViewOpen[locali] = !isOpen; StateHasChanged(); })" title="Details View" aria-expanded="@(isOpen ? "true" : "false")">
@if (isOpen)
{<span aria-hidden="true"><img src="/_content/BlazorTable/images/minus.png" /></span>}
else
{<span aria-hidden="true"><img src="/_content/BlazorTable/images/plus.png" /></span>}
</a>
</td>
}
Expand All @@ -106,16 +112,16 @@

@if (IsEditMode && column.EditTemplate != null)
@column.EditTemplate(item)
else
if (column.Template == null)
else
if (column.Template == null)
@column.Render(item)
else
@column.Template(item)
else
@column.Template(item)
</td>
}
</tr>

if (_detailTemplate != null && detailsViewOpen[locali])
if (_detailTemplate != null && isOpen)
{
<tr>
<td></td>
Expand Down
19 changes: 16 additions & 3 deletions src/BlazorTable/Components/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,13 @@ private IEnumerable<TableItem> GetData()
return Items;
}

private bool[] detailsViewOpen;
private Dictionary<int, bool> detailsViewOpen = new Dictionary<int, bool>();

/// <summary>
/// Gets Data and redraws the Table
/// </summary>
public void Update()
{
detailsViewOpen = new bool[PageSize];
FilteredItems = GetData();
Refresh();
}
Expand Down Expand Up @@ -212,6 +211,7 @@ public void FirstPage()
if (PageNumber != 0)
{
PageNumber = 0;
detailsViewOpen.Clear();
Update();
}
}
Expand All @@ -224,6 +224,7 @@ public void NextPage()
if (PageNumber + 1 < TotalPages)
{
PageNumber++;
detailsViewOpen.Clear();
Update();
}
}
Expand All @@ -236,6 +237,7 @@ public void PreviousPage()
if (PageNumber > 0)
{
PageNumber--;
detailsViewOpen.Clear();
Update();
}
}
Expand All @@ -246,6 +248,7 @@ public void PreviousPage()
public void LastPage()
{
PageNumber = TotalPages - 1;
detailsViewOpen.Clear();
Update();
}

Expand Down Expand Up @@ -325,7 +328,7 @@ public void SetEmptyDataTemplate(EmptyDataTemplate emptyDataTemplate)
}

private RenderFragment _emptyDataTemplate;

/// <summary>
/// Set the template to use for loading data
/// </summary>
Expand Down Expand Up @@ -456,5 +459,15 @@ private Expression<Func<TableItem, bool>> GlobalSearchQuery(string value)
/// </summary>
[Parameter]
public bool ShowSearchBar { get; set; }

/// <summary>
/// Set Table Page Size
/// </summary>
/// <param name="pageSize"></param>
public void SetPageSize(int pageSize)
{
PageSize = pageSize;
Update();
}
}
}
6 changes: 6 additions & 0 deletions src/BlazorTable/Interfaces/ITable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,11 @@ public interface ITable
/// Shows Search Bar above the table
/// </summary>
bool ShowSearchBar { get; set; }

/// <summary>
/// Set Table Page Size
/// </summary>
/// <param name="pageSize"></param>
void SetPageSize(int pageSize);
}
}
32 changes: 5 additions & 27 deletions src/BlazorTable/wwwroot/BlazorTable.min.js

Large diffs are not rendered by default.

Binary file added src/BlazorTable/wwwroot/images/filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/BlazorTable/wwwroot/images/minus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/BlazorTable/wwwroot/images/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/BlazorTable/wwwroot/images/sort-asc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/BlazorTable/wwwroot/images/sort-desc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7d0a527

Please sign in to comment.