-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from csu-chhs/pagination-component
Add pagination component
- Loading branch information
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
CsuChhs.Blazor/Components/Common/PaginationComponent.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<nav aria-label="Page navigation example"> | ||
<ul class="pagination justify-content-center"> | ||
<li class="page-item"> | ||
<a class="page-link" href="#" aria-label="Previous" @onclick:preventDefault @onclick="() => GoToPageClick(_previousPage)"> | ||
<span aria-hidden="true">«</span> | ||
</a> | ||
</li> | ||
@{ | ||
var x = 0; | ||
|
||
while (x < PageCount) | ||
{ | ||
x++; | ||
int pageIndex = x; | ||
<li class="page-item @(x == ActivePage ? "active" : "")"> | ||
<a class="page-link" href="#" @onclick:preventDefault @onclick="() => GoToPageClick(pageIndex)">@x</a> | ||
</li> | ||
} | ||
} | ||
<li class="page-item"> | ||
<a class="page-link" href="#" aria-label="Next" @onclick:preventDefault @onclick="() => GoToPageClick(_nextPage)"> | ||
<span aria-hidden="true">»</span> | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
|
||
|
||
@code { | ||
[Parameter] | ||
public int PageCount { get; set; } | ||
|
||
[Parameter] | ||
public int ActivePage { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<int> PageClick { get; set; } | ||
|
||
private int _previousPage = 1; | ||
private int _nextPage = 1; | ||
|
||
protected override Task OnParametersSetAsync() | ||
{ | ||
if (ActivePage > 1) | ||
{ | ||
_previousPage = ActivePage - 1; | ||
} | ||
|
||
if (ActivePage < PageCount) | ||
{ | ||
_nextPage = ActivePage + 1; | ||
} | ||
|
||
return base.OnParametersSetAsync(); | ||
} | ||
|
||
private async Task GoToPageClick(int page) | ||
{ | ||
await InvokeAsync(() => PageClick.InvokeAsync(page)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters