Skip to content

Commit

Permalink
Suggested alternative ITable interface approach so content components…
Browse files Browse the repository at this point in the history
… do not need to specify the parent table type
  • Loading branch information
conficient committed Jan 13, 2020
1 parent 191d481 commit 7933d5c
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ Blazor Table Component with Sorting, Paging and Filtering
@context.created_date.ToShortDateString()
</Template>
</Column>
<Pager TableItem="PersonData" ShowPageNumber="true" ShowTotalCount="true" />
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>
```
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 @@ -27,7 +27,7 @@
@(context.created_date.HasValue ? context.created_date.Value.ToShortDateString() : string.Empty)
</Template>
</Column>
<Pager TableItem="PersonData" ShowPageNumber="true" ShowTotalCount="true" />
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
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 @@ -48,7 +48,7 @@
<input type="date" @bind-value="@context.created_date" class="form-control form-control-sm" />
</EditTemplate>
</Column>
<Pager TableItem="PersonData" ShowPageNumber="true" ShowTotalCount="true" />
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorTable.Sample.Shared/Pages/EmptyData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<Table TableItem="SampleData" Items="data" PageSize="15" @ref="Table" ColumnReorder="true">
<Column TableItem="SampleData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true" />
<Column TableItem="SampleData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%" />
<EmptyDataTemplate TableItem="SampleData">
<EmptyDataTemplate>
<Template>
<div class="text-center">
No rows found!
</div>
</Template>
</EmptyDataTemplate>
<Pager TableItem="SampleData" ShowPageNumber="true" ShowTotalCount="true" />
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
Expand Down
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 @@ -36,7 +36,7 @@
@context.cc_type
</Template>
</Column>
<Pager TableItem="PersonData" ShowPageNumber="true" ShowTotalCount="true" />
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
Expand Down
1 change: 0 additions & 1 deletion src/BlazorTable/Components/EmptyDataTemplate.razor
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
@namespace BlazorTable
@typeparam TableItem
5 changes: 2 additions & 3 deletions src/BlazorTable/Components/EmptyDataTemplate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ namespace BlazorTable
/// <summary>
/// Child content for empty dataset
/// </summary>
/// <typeparam name="TableItem"></typeparam>
public partial class EmptyDataTemplate<TableItem>
public partial class EmptyDataTemplate
{
/// <summary>
/// Parent table
/// </summary>
[CascadingParameter(Name = "Table")]
public ITable<TableItem> Table { get; set; }
public ITable Table { get; set; }

/// <summary>
/// Content to show
Expand Down
1 change: 0 additions & 1 deletion src/BlazorTable/Components/Pager.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@namespace BlazorTable
@typeparam TableItem

@if (AlwaysShow || (Table.TotalPages >= 1))
{
Expand Down
8 changes: 5 additions & 3 deletions src/BlazorTable/Components/Pager.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ namespace BlazorTable
/// <summary>
/// BlazorTable Pager
/// </summary>
/// <typeparam name="TableItem"></typeparam>
public partial class Pager<TableItem>
public partial class Pager
{
/// <summary>
/// Parent table
/// </summary>
[CascadingParameter(Name = "Table")]
public ITable<TableItem> Table { get; set; }
public ITable Table { get; set; }

/// <summary>
/// Always show Pager, otherwise only show if TotalPages > 1
Expand Down
7 changes: 5 additions & 2 deletions src/BlazorTable/Components/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public partial class Table<TableItem> : ITable<TableItem>
{
private const int DEFAULT_PAGE_SIZE = 10;

/// <summary>
/// Captures additional attributes to apply to table
/// </summary>
[Parameter(CaptureUnmatchedValues = true)]
public IReadOnlyDictionary<string, object> UnknownParameters { get; set; }

Expand All @@ -30,7 +33,7 @@ public partial class Table<TableItem> : ITable<TableItem>
/// Table Body Class
/// </summary>
[Parameter]
public string TableBodyClass { get; set; } = "";
public string TableBodyClass { get; set; } = string.Empty;

/// <summary>
/// Expression to set Row Class
Expand Down Expand Up @@ -287,7 +290,7 @@ private string RowClass(TableItem item)
/// Set the template to use for empty data
/// </summary>
/// <param name="emptyDataTemplate"></param>
public void SetEmptyDataTemplate(EmptyDataTemplate<TableItem> emptyDataTemplate)
public void SetEmptyDataTemplate(EmptyDataTemplate emptyDataTemplate)
{
_emptyDataTemplate = emptyDataTemplate?.Template;
}
Expand Down
47 changes: 9 additions & 38 deletions src/BlazorTable/Interfaces/ITable.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace BlazorTable
{
/// <summary>
/// BlazorTable Interface
/// BlazorTable interface (non-generic)
/// </summary>
/// <typeparam name="TableItem"></typeparam>
public interface ITable<TableItem>
/// <remarks>
/// This base interface does not require a row type
/// </remarks>
public interface ITable
{
/// <summary>
/// Page Size
Expand Down Expand Up @@ -66,11 +69,6 @@ public interface ITable<TableItem>
/// </summary>
void ToggleEditMode();

/// <summary>
/// List of All Available Columns
/// </summary>
List<IColumn<TableItem>> Columns { get; }

/// <summary>
/// Table Element CSS
/// </summary>
Expand All @@ -86,23 +84,6 @@ public interface ITable<TableItem>
/// </summary>
string TableHeadClass { get; set; }

/// <summary>
/// Optional: expression to use for row class
/// </summary>
Expression<Func<TableItem, string>> TableRowClass { get; set; }

/// <summary>
/// Adds a Column to the Table
/// </summary>
/// <param name="column"></param>
void AddColumn(IColumn<TableItem> column);

/// <summary>
/// Removes a Column from the Table
/// </summary>
/// <param name="column"></param>
void RemoveColumn(IColumn<TableItem> column);

/// <summary>
/// Redraws Table without Getting Data
/// </summary>
Expand All @@ -113,21 +94,11 @@ public interface ITable<TableItem>
/// </summary>
void Update();

/// <summary>
/// IQueryable data source to display in the table
/// </summary>
IQueryable<TableItem> ItemsQueryable { get; set; }

/// <summary>
/// Collection to display in the table
/// </summary>
IEnumerable<TableItem> Items { get; set; }

/// <summary>
/// Set the EmptyDataTemplate for the table
/// </summary>
/// <param name="template"></param>
void SetEmptyDataTemplate(EmptyDataTemplate<TableItem> template);
void SetEmptyDataTemplate(EmptyDataTemplate template);

}
}
}
49 changes: 49 additions & 0 deletions src/BlazorTable/Interfaces/ITableT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace BlazorTable
{
/// <summary>
/// BlazorTable Interface (type-specific)
/// </summary>
/// <typeparam name="TableItem">The row data type</typeparam>
/// <remarks>
/// All row-type specific methods are defined in this interface
/// </remarks>
public interface ITable<TableItem> : ITable
{
/// <summary>
/// List of All Available Columns
/// </summary>
List<IColumn<TableItem>> Columns { get; }

/// <summary>
/// Optional: expression to use for row class
/// </summary>
Expression<Func<TableItem, string>> TableRowClass { get; set; }

/// <summary>
/// Adds a Column to the Table
/// </summary>
/// <param name="column"></param>
void AddColumn(IColumn<TableItem> column);

/// <summary>
/// Removes a Column from the Table
/// </summary>
/// <param name="column"></param>
void RemoveColumn(IColumn<TableItem> column);

/// <summary>
/// IQueryable data source to display in the table
/// </summary>
IQueryable<TableItem> ItemsQueryable { get; set; }

/// <summary>
/// Collection to display in the table
/// </summary>
IEnumerable<TableItem> Items { get; set; }
}
}

0 comments on commit 7933d5c

Please sign in to comment.