Skip to content

Commit 220feba

Browse files
ArgoZhangdensen2014lambert leeh2ls
authored
feat: table support CollapsedTopSearch parameter (#359)
Co-authored-by: alex chow <zhouchuanglin@gmail.com> Co-authored-by: lambert lee <1708416@qq.com> Co-authored-by: lambert lee <lish@live.cn>
1 parent 22cc0ea commit 220feba

5 files changed

Lines changed: 64 additions & 36 deletions

File tree

src/BootstrapBlazor/Components/Table/Table.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@typeparam TItem
33
@inherits BootstrapModuleComponentBase
44

5-
<div @attributes="@AdditionalAttributes" class="@ClassName" style="@StyleString" id="@Id" @ref="TableElement">
5+
<div @attributes="@AdditionalAttributes" class="@ClassName" style="@StyleString" id="@Id">
66
<CascadingValue Value="this" IsFixed="true">
77
@TableColumns?.Invoke(new TItem())
88
</CascadingValue>
@@ -842,7 +842,7 @@ RenderFragment<TItem> RenderRowExtendButtons => item =>
842842
</td>;
843843

844844
RenderFragment RenderSearch =>
845-
@<Card IsCollapsible="true" HeaderText="@SearchModalTitle">
845+
@<Card IsCollapsible="true" HeaderText="@SearchModalTitle" Collapsed="CollapsedTopSearch">
846846
<HeaderTemplate>
847847
@if (ShowSearchText)
848848
{

src/BootstrapBlazor/Components/Table/Table.razor.FixHeader.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ namespace BootstrapBlazor.Components;
133133

134134
private static string? GetColWidthString(int? width) => width.HasValue ? $"width: {width.Value}px;" : null;
135135

136+
/// <summary>
137+
/// 获得/设置 Table 高度 默认为 null
138+
/// </summary>
139+
/// <remarks>开启固定表头功能时生效 <see cref="IsFixedHeader"/></remarks>
140+
[Parameter]
141+
public int? Height { get; set; }
142+
143+
/// <summary>
144+
/// 获得/设置 固定表头 默认 false
145+
/// </summary>
146+
/// <remarks>固定表头时设置 <see cref="Height"/> 即可出现滚动条,未设置时尝试自适应</remarks>
147+
[Parameter]
148+
public bool IsFixedHeader { get; set; }
149+
150+
/// <summary>
151+
/// 获得/设置 多表头模板
152+
/// </summary>
153+
[Parameter]
154+
public RenderFragment? MultiHeaderTemplate { get; set; }
155+
136156
/// <summary>
137157
/// 获得/设置 列拷贝 Tooltip 文字
138158
/// </summary>

test/UnitTest/Components/TableDialogTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ public async Task EditAsync_Ok()
127127
{
128128
itemsChanged = true;
129129
});
130+
pb.Add(a => a.EditFooterTemplate, foo => builder => builder.AddContent(0, "test_edit_footer"));
130131
});
131132

132133
// Add 弹窗
133134
await cut.InvokeAsync(() => table.Instance.AddAsync());
135+
cut.Contains("test_edit_footer");
134136

135137
// 编辑弹窗逻辑
136138
input = cut.Find(".modal-body form input.form-control");

test/UnitTest/Components/TableTest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,46 @@ public async Task ShowTopSearch_Ok()
443443
await cut.InvokeAsync(() => searchButton.Click());
444444
}
445445

446+
[Fact]
447+
public void CollapsedTopSearch_Ok()
448+
{
449+
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
450+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
451+
{
452+
pb.AddChildContent<Table<Foo>>(pb =>
453+
{
454+
pb.Add(a => a.ShowSearch, true);
455+
pb.Add(a => a.CollapsedTopSearch, true);
456+
pb.Add(a => a.SearchMode, SearchMode.Top);
457+
pb.Add(a => a.OnQueryAsync, OnQueryAsync(localizer));
458+
pb.Add(a => a.TableColumns, foo => builder =>
459+
{
460+
builder.OpenComponent<TableColumn<Foo, string>>(0);
461+
builder.AddAttribute(1, "Field", "Name");
462+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
463+
builder.AddAttribute(3, "Searchable", true);
464+
builder.CloseComponent();
465+
});
466+
pb.Add(a => a.TableColumns, foo => builder =>
467+
{
468+
builder.OpenComponent<TableColumn<Foo, int>>(0);
469+
builder.AddAttribute(1, "Field", foo.Count);
470+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Count", typeof(int)));
471+
builder.AddAttribute(3, "Searchable", true);
472+
builder.CloseComponent();
473+
});
474+
});
475+
});
476+
cut.DoesNotContain("card-body collapse show");
477+
478+
var table = cut.FindComponent<Table<Foo>>();
479+
table.SetParametersAndRender(pb =>
480+
{
481+
pb.Add(a => a.CollapsedTopSearch, false);
482+
});
483+
cut.Contains("card-body collapse show");
484+
}
485+
446486
[Fact]
447487
public void ShowToolbar_Ok()
448488
{

0 commit comments

Comments
 (0)