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

Commit

Permalink
Added DefaultSortColumn and DefaultSortDescending to Column
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic committed Jan 8, 2020
1 parent e4cfd0d commit 54a0890
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
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 @@ -9,7 +9,7 @@
<br />
<br />
<Table TableItem="PersonData" Items="data" PageSize="15" @ref="Table" ColumnReorder="true">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" />
<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>
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 @@ -9,7 +9,7 @@
<br />
<br />
<Table TableItem="PersonData" Items="data" PageSize="15" @ref="Table" ColumnReorder="true">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true">
<EditTemplate>
<input type="number" @bind-value="@context.id" class="form-control form-control-sm" />
</EditTemplate>
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 @@ -13,7 +13,7 @@
<br />

<Table TableItem="PersonData" Items="data" PageSize="15" ColumnReorder="true" TableRowClass="@(x => x.RowClass)">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" />
<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>
Expand Down
22 changes: 22 additions & 0 deletions src/BlazorTable/Components/Column.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ public string Title
/// </summary>
public Expression<Func<TableItem, bool>> Filter { get; set; }

/// <summary>
/// True if this is the default Sort Column
/// </summary>
[Parameter]
public bool? DefaultSortColumn { get; set; }

/// <summary>
/// Direction of default sorting
/// </summary>
[Parameter]
public bool? DefaultSortDescending { get; set; }

/// <summary>
/// True if this is the current Sort Column
/// </summary>
Expand Down Expand Up @@ -129,6 +141,16 @@ public string Title
protected override void OnInitialized()
{
Table.AddColumn(this);

if (DefaultSortDescending.HasValue)
{
this.SortDescending = DefaultSortDescending.Value;
}

if (DefaultSortColumn.HasValue)
{
this.SortColumn = DefaultSortColumn.Value;
}
}

protected override void OnParametersSet()
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorTable/Components/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
@if (column.SortColumn)
{
if (column.SortDescending)
{<span>&#11014;</span> }
{ <span>&#11014;</span> }
else
{ <span>&#11015;</span>}
{ <span>&#11015;</span> }
}

@if (column.Filterable)
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable/Components/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,6 @@ private string RowClass(TableItem item)
/// <summary>
/// Save compiled TableRowClass property to avoid repeated Compile() calls
/// </summary>
private Func<TableItem, string> _tableRowClassCompiled = null;
private Func<TableItem, string> _tableRowClassCompiled;
}
}
10 changes: 10 additions & 0 deletions src/BlazorTable/Interfaces/IColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ public interface IColumn<TableItem>
/// </summary>
string Class { get; set; }

/// <summary>
/// True if this is the default Sort Column
/// </summary>
bool? DefaultSortColumn { get; set; }

/// <summary>
/// Direction of default sorting
/// </summary>
bool? DefaultSortDescending { get; set; }

/// <summary>
/// Default render if no Template specified
/// </summary>
Expand Down

0 comments on commit 54a0890

Please sign in to comment.