Skip to content

Commit

Permalink
Merge pull request #10 from csu-chhs/pagination-component
Browse files Browse the repository at this point in the history
Add pagination component
  • Loading branch information
dstegelman authored Mar 27, 2024
2 parents b30845e + b8361e1 commit 9e3cde5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CsuChhs.Blazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsuChhs.Blazor", "CsuChhs.Blazor\CsuChhs.Blazor.csproj", "{B211D13D-D3C8-483E-8958-7A9F6E7D93AE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CsuChhs.Blazor", "CsuChhs.Blazor\CsuChhs.Blazor.csproj", "{B211D13D-D3C8-483E-8958-7A9F6E7D93AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
62 changes: 62 additions & 0 deletions CsuChhs.Blazor/Components/Common/PaginationComponent.razor
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">&laquo;</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">&raquo;</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));
}

}
6 changes: 3 additions & 3 deletions CsuChhs.Blazor/CsuChhs.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>CHHS Application Development Team</Authors>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<PackageProjectUrl>https://github.com/csu-chhs/CsuChhs.Blazor</PackageProjectUrl>
<Company>College of Health and Human Sciences</Company>
<PackageId>CsuChhs.Blazor</PackageId>
Expand All @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CsuChhs.WebComponents" Version="1.0.3" />
<PackageReference Include="CsuChhs.WebComponents" Version="1.0.*" />
<PackageReference Include="Humanizer.Core" Version="2.14.*" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.*" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.*" />
Expand Down

0 comments on commit 9e3cde5

Please sign in to comment.