groceries/Groceries/Components/TablePaginator.razor
James Chapman 47d13ba922
All checks were successful
Docker Image CI / build (push) Successful in 3m45s
Add support for adding 'loose' items to transactions
2024-10-12 02:36:38 +01:00

43 lines
1.1 KiB
Plaintext

@inject NavigationManager Navigation
<footer class="table__paginator">
<span>
Showing @FirstItem to @LastItem of @State.TotalItemCount results
</span>
<nav>
@if (State.CurrentPage == 1)
{
<span class="link link--disabled">Previous</span>
}
else
{
<a class="link" href="@GetUriForPage(State.CurrentPage - 1)">Previous</a>
}
@if (State.CurrentPage == State.LastPage)
{
<span class="link link--disabled">Next</span>
}
else
{
<a class="link" href="@GetUriForPage(State.CurrentPage + 1)">Next</a>
}
</nav>
</footer>
@code {
[Parameter, EditorRequired]
public required PaginationState State { get; set; }
private int FirstItem => State.TotalItemCount > 0 ? State.Offset + 1 : 0;
private int LastItem => State.Offset + State.ItemCount;
protected override void OnParametersSet()
{
State.ItemCountChanged += (_, _) => StateHasChanged();
}
private string GetUriForPage(int page)
=> Navigation.GetUriWithQueryParameter("page", page);
}