!3543 fix(#I61VIJ): can't restore the page items when page count great than total count

* chore: bump version 7.0.4-beta01
* test: 修复失败的单元测试
* test: 更新单元测试
* doc: 更新示例
* fix: 修复 Table 组件设置页码过大时导致分页栏不显示问题
* fix: 修复 Pagination 页码总数过大时导致自身不显示无法复原问题
This commit is contained in:
Argo 2022-11-18 07:26:12 +00:00
parent 4f495ab0db
commit 0d12e3c73b
10 changed files with 60 additions and 59 deletions

View File

@ -9,7 +9,7 @@ namespace BootstrapBlazor.Shared.Samples.Table;
/// </summary>
public partial class TablesPages
{
private static IEnumerable<int> PageItemsSource => new int[] { 4, 10, 20 };
private static IEnumerable<int> PageItemsSource => new int[] { 4, 10, 20, 40, 80, 100 };
[NotNull]
private List<Foo>? Items { get; set; }

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<Version>7.0.3</Version>
<Version>7.0.4-beta01</Version>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">

View File

@ -39,14 +39,14 @@
@if (FooterTemplate != null || Pageable)
{
<div class="listview-footer">
@if (Pageable)
{
<Pagination PageCount="@PageCount" PageIndex="@PageIndex" OnPageLinkClick="@OnPageLinkClick"></Pagination>
}
else
@if (FooterTemplate != null)
{
@FooterTemplate
}
else if (Pageable)
{
<Pagination PageCount="@PageCount" PageIndex="@PageIndex" OnPageLinkClick="@OnPageLinkClick"></Pagination>
}
</div>
}
</div>

View File

@ -2,7 +2,7 @@
@inherits BootstrapComponentBase
<nav @attributes="AdditionalAttributes" class="@ClassString">
@if(ShowPageInfo)
@if (ShowPageInfo)
{
if (PageInfoTemplate != null)
{
@ -13,47 +13,50 @@
<div class="page-info">@PageInfoText</div>
}
}
<ul class="@PaginationClassString">
<PaginationItem OnClick="MovePrev" Index="1">
<i class="@PrevPageIcon"></i>
</PaginationItem>
<PaginationItem OnClick="OnClick" Index="1" IsActive="InternalPageIndex == 1" />
@if (InternalPageCount > MaxPageLinkCount)
{
@if (StartPageIndex != 2)
{
<PaginationItem OnClick="MovePrev" Index="MaxPageLinkCount" class="prev-link">
<i class="@PrevEllipsisPageIcon"></i>
</PaginationItem>
}
}
@for (int i = StartPageIndex; i <= EndPageIndex; i++)
{
<PaginationItem @key="i" OnClick="OnClick" Index="i" IsActive="InternalPageIndex == i" />
}
@if (InternalPageCount > MaxPageLinkCount)
{
@if (EndPageIndex != InternalPageCount - 1)
{
<PaginationItem OnClick="MoveNext" Index="MaxPageLinkCount" class="next-link">
<i class="@NextEllipsisPageIcon"></i>
</PaginationItem>
}
}
<PaginationItem OnClick="OnClick" Index="InternalPageCount" IsActive="InternalPageIndex == InternalPageCount" />
<PaginationItem OnClick="MoveNext" Index="1">
<i class="@NextPageIcon"></i>
</PaginationItem>
</ul>
@if (ShowGotoNavigator)
@if (PageCount > 1)
{
if (GotoTemplate != null)
<ul class="@PaginationClassString">
<PaginationItem OnClick="MovePrev" Index="1">
<i class="@PrevPageIcon"></i>
</PaginationItem>
<PaginationItem OnClick="OnClick" Index="1" IsActive="InternalPageIndex == 1" />
@if (InternalPageCount > MaxPageLinkCount)
{
@if (StartPageIndex != 2)
{
<PaginationItem OnClick="MovePrev" Index="MaxPageLinkCount" class="prev-link">
<i class="@PrevEllipsisPageIcon"></i>
</PaginationItem>
}
}
@for (int i = StartPageIndex; i <= EndPageIndex; i++)
{
<PaginationItem @key="i" OnClick="OnClick" Index="i" IsActive="InternalPageIndex == i" />
}
@if (InternalPageCount > MaxPageLinkCount)
{
@if (EndPageIndex != InternalPageCount - 1)
{
<PaginationItem OnClick="MoveNext" Index="MaxPageLinkCount" class="next-link">
<i class="@NextEllipsisPageIcon"></i>
</PaginationItem>
}
}
<PaginationItem OnClick="OnClick" Index="InternalPageCount" IsActive="InternalPageIndex == InternalPageCount" />
<PaginationItem OnClick="MoveNext" Index="1">
<i class="@NextPageIcon"></i>
</PaginationItem>
</ul>
@if (ShowGotoNavigator)
{
@GotoTemplate
}
else
{
<GotoNavigator Index="InternalPageIndex" GotoText="@GotoNavigatorLabelText" OnNavigation="OnGoto" />
if (GotoTemplate != null)
{
@GotoTemplate
}
else
{
<GotoNavigator Index="InternalPageIndex" GotoText="@GotoNavigatorLabelText" OnNavigation="OnGoto" />
}
}
}
</nav>

View File

@ -20,7 +20,6 @@ public partial class Pagination
/// 获得 组件 样式
/// </summary>
protected string? ClassString => CssBuilder.Default("nav nav-pages")
.AddClass("d-none", InternalPageCount == 1)
.AddClassFromAttributes(AdditionalAttributes)
.Build();

View File

@ -154,7 +154,7 @@
</div>
}
@if (ShowTopPagination && PageCount > 1 && IsPagination)
@if (ShowTopPagination && IsPagination)
{
@RenderPagination
}
@ -257,7 +257,7 @@
}
</div>
@if (!ShowTopPagination && PageCount > 1 && IsPagination)
@if (!ShowTopPagination && IsPagination)
{
@RenderPagination
}
@ -903,9 +903,7 @@ RenderFragment RenderPageInfo =>
</div>;
RenderFragment RenderPagination =>
@<div class="table-pagination">
<Pagination PageCount="@PageCount" PageIndex="@PageIndex" OnPageLinkClick="@OnPageLinkClick"
@<Pagination PageCount="@PageCount" PageIndex="@PageIndex" OnPageLinkClick="@OnPageLinkClick"
ShowGotoNavigator="ShowGotoNavigator" GotoTemplate="GotoTemplate!" GotoNavigatorLabelText="@GotoNavigatorLabelText"
ShowPageInfo="ShowPageInfo" PageInfoTemplate="InternalPageInfoTemplate" />
</div>;
ShowPageInfo="ShowPageInfo" PageInfoTemplate="InternalPageInfoTemplate" />;
}

View File

@ -118,7 +118,6 @@ public partial class Table<TItem>
}
else if (!string.IsNullOrEmpty(PageInfoText))
{
// <div class="page-info">@PageInfoText</div>
builder.OpenElement(1, "div");
builder.AddAttribute(2, "class", "page-info");
builder.AddContent(3, PageInfoText);

View File

@ -89,7 +89,7 @@ export class Table extends BlazorComponent {
if (search) {
searchHeight = getHeight(search)
}
const pagination = this._element.querySelector('.table-pagination')
const pagination = this._element.querySelector('.nav-pages')
let paginationHeight = 0
if (pagination) {
paginationHeight = getHeight(pagination)

View File

@ -51,7 +51,7 @@ public class ListViewTest : BootstrapBlazorTestBase
}
[Fact]
public async Task Pageable_Ok()
public void Pageable_Ok()
{
var items = Enumerable.Range(1, 6).Select(i => new Product()
{
@ -63,10 +63,12 @@ public class ListViewTest : BootstrapBlazorTestBase
{
pb.Add(a => a.OnQueryAsync, Query);
pb.Add(a => a.Pageable, true);
pb.Add(a => a.PageItems, 2);
});
var pages = cut.FindAll(".page-link");
await cut.InvokeAsync(() => pages[2].Click());
Assert.Equal(5, pages.Count);
cut.InvokeAsync(() => pages[2].Click());
Task<QueryData<Product>> Query(QueryPageOptions option) => Task.FromResult(new QueryData<Product>()
{

View File

@ -622,7 +622,7 @@ public class TableTest : TableTestBase
});
var table = cut.FindComponent<Table<Foo>>();
table.Contains("table-pagination");
table.Contains("nav nav-pages");
}
[Fact]