Skip to content

Commit 18bfd5a

Browse files
authored
feat(ISearchFormItemMetadata): add RenderContent method (#7785)
* feat(ISearchFormItemMetadata): add RenderFragment parameter * refactor: 精简代码 * feat: 支持自定义搜索 UI * doc: 资源文件排序 * refactor: 更改基类名称 * feat: 增加 RenderContent 自定义渲染方法 * feat(ISearchFormItemMetadata): add RenderContent method * test: 增加单元测试 * chore: bump version 10.4.2 * doc: 更新示例 * doc: 增加注释 * refactor: 增加 SearchForm 参数
1 parent 518b85b commit 18bfd5a

File tree

18 files changed

+130
-77
lines changed

18 files changed

+130
-77
lines changed

src/BootstrapBlazor.Server/Components/Samples/Table/TablesSearch.razor

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,48 +34,6 @@
3434
</Table>
3535
</DemoBlock>
3636

37-
<DemoBlock Title="@Localizer["SearchTableTitle"]"
38-
Introduction="@Localizer["SearchTableIntro"]"
39-
Name="SearchTable">
40-
<section ignore>
41-
<ul class="ul-demo mb-3">
42-
<li>@((MarkupString)Localizer["SearchTableLi1"].Value)</li>
43-
<li>@((MarkupString)Localizer["SearchTableLi2"].Value)</li>
44-
<li>@((MarkupString)Localizer["SearchTableLi3"].Value)</li>
45-
</ul>
46-
@((MarkupString)Localizer["AutoHeightIntro"].Value)
47-
</section>
48-
<div style="height: 600px;">
49-
<Table TItem="Foo"
50-
IsPagination="true" PageItemsSource="new int[] {10, 20}"
51-
IsStriped="true" IsBordered="true" ShowMoreButton="true"
52-
ShowToolbar="true" ShowSearch="true" ShowCardView="true" IsMultipleSelect="true" ShowExtendButtons="true"
53-
AddModalTitle="@Localizer["AddModelTitle"]" EditModalTitle="@Localizer["EditModelTitle"]"
54-
SearchModel="@SearchModel" SearchMode="SearchMode.Top" ShowEmpty="true"
55-
OnQueryAsync="@OnSearchModelQueryAsync" OnResetSearchAsync="@OnResetSearchAsync"
56-
OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
57-
<TableColumns>
58-
<TableColumn @bind-Field="@context.DateTime" Width="180" />
59-
<TableColumn @bind-Field="@context.Name" />
60-
<TableColumn @bind-Field="@context.Address" />
61-
<TableColumn @bind-Field="@context.Education" />
62-
</TableColumns>
63-
<SearchTemplate>
64-
<GroupBox Title="@Localizer["SearchTableGroupBoxText"]">
65-
<div class="row g-3 form-inline">
66-
<div class="col-12 col-sm-6">
67-
<BootstrapInput @bind-Value="@context.Name" PlaceHolder="@Localizer["NamePlaceholder"]" maxlength="50" ShowLabel="true" DisplayText="@FooLocalizer[nameof(context.Name)]" />
68-
</div>
69-
<div class="col-12 col-sm-6">
70-
<BootstrapInput @bind-Value="@context.Address" PlaceHolder="@Localizer["AddressPlaceholder"]" maxlength="500" ShowLabel="true" DisplayText="@FooLocalizer[nameof(context.Address)]" />
71-
</div>
72-
</div>
73-
</GroupBox>
74-
</SearchTemplate>
75-
</Table>
76-
</div>
77-
</DemoBlock>
78-
7937
<DemoBlock Title="@Localizer["AutoGenerateSearchTitle"]"
8038
Introduction="@Localizer["AutoGenerateSearchIntro"]"
8139
Name="AutoGenerateSearch">
@@ -124,6 +82,48 @@
12482
</Table>
12583
</DemoBlock>
12684

85+
<DemoBlock Title="@Localizer["SearchTableTitle"]"
86+
Introduction="@Localizer["SearchTableIntro"]"
87+
Name="SearchTable">
88+
<section ignore>
89+
<ul class="ul-demo mb-3">
90+
<li>@((MarkupString)Localizer["SearchTableLi1"].Value)</li>
91+
<li>@((MarkupString)Localizer["SearchTableLi2"].Value)</li>
92+
<li>@((MarkupString)Localizer["SearchTableLi3"].Value)</li>
93+
</ul>
94+
@((MarkupString)Localizer["AutoHeightIntro"].Value)
95+
</section>
96+
<div style="height: 600px;">
97+
<Table TItem="Foo"
98+
IsPagination="true" PageItemsSource="new int[] {10, 20}"
99+
IsStriped="true" IsBordered="true" ShowMoreButton="true"
100+
ShowToolbar="true" ShowSearch="true" ShowCardView="true" IsMultipleSelect="true" ShowExtendButtons="true"
101+
AddModalTitle="@Localizer["AddModelTitle"]" EditModalTitle="@Localizer["EditModelTitle"]"
102+
SearchModel="@SearchModel" SearchMode="SearchMode.Top" ShowEmpty="true"
103+
OnQueryAsync="@OnSearchModelQueryAsync" OnResetSearchAsync="@OnResetSearchAsync"
104+
OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
105+
<TableColumns>
106+
<TableColumn @bind-Field="@context.DateTime" Width="180" />
107+
<TableColumn @bind-Field="@context.Name" />
108+
<TableColumn @bind-Field="@context.Address" />
109+
<TableColumn @bind-Field="@context.Education" />
110+
</TableColumns>
111+
<SearchTemplate>
112+
<GroupBox Title="@Localizer["SearchTableGroupBoxText"]">
113+
<div class="row g-3 form-inline">
114+
<div class="col-12 col-sm-6">
115+
<BootstrapInput @bind-Value="@context.Name" PlaceHolder="@Localizer["NamePlaceholder"]" maxlength="50" ShowLabel="true" DisplayText="@FooLocalizer[nameof(context.Name)]" />
116+
</div>
117+
<div class="col-12 col-sm-6">
118+
<BootstrapInput @bind-Value="@context.Address" PlaceHolder="@Localizer["AddressPlaceholder"]" maxlength="500" ShowLabel="true" DisplayText="@FooLocalizer[nameof(context.Address)]" />
119+
</div>
120+
</div>
121+
</GroupBox>
122+
</SearchTemplate>
123+
</Table>
124+
</div>
125+
</DemoBlock>
126+
127127
<DemoBlock Title="@Localizer["CustomColSearchTitle"]"
128128
Introduction="@Localizer["CustomColSearchIntro"]"
129129
Name="CustomColSearch">

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5066,7 +5066,7 @@
50665066
"NamePlaceholder": "Please enter your name within 50 characters",
50675067
"SearchFormDesc": "When <code>UseSearchForm</code> is enabled and <code>SearchItems</code> is not provided, it will default to using <code>TableColumn</code> with <code>Searchable=\"true\"</code>. You can customize the metadata through the <code>SearchFormItemMetadata</code> property in <code>TableColumn</code>",
50685068
"SearchFormIntro": "Enable the search form feature by setting <code>UseSearchForm=\"true\"</code>, and configure the search items within the form using <code>SearchItems</code>, suitable for scenarios with custom complex search conditions",
5069-
"SearchFormTips": "Enabling <code>UseSearchForm</code> will prevent <code>SearchTemplate</code>, <code>CustomerSearchModel</code>, and <code>CustomerSearchTemplate</code> from taking effect.",
5069+
"SearchFormTips": "Enabling <code>UseSearchForm</code> will prevent <code>SearchModel</code> <code>SearchTemplate</code>, <code>CustomerSearchModel</code>, and <code>CustomerSearchTemplate</code> from taking effect.",
50705070
"SearchFormTitle": "Search Form",
50715071
"SearchTableGroupBoxText": "Search Criteria",
50725072
"SearchTableIntro": "Set <code>ShowSearch</code> to display the query component, customize the search UI by setting the <code>SearchTemplate</code> template",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5065,8 +5065,8 @@
50655065
"EditModelTitle": "编辑测试数据窗口",
50665066
"NamePlaceholder": "请输入姓名,50字以内",
50675067
"SearchFormDesc": "使用 <code>UseSearchForm</code> 开启搜索表单时未提供 <code>SearchItems</code> 默认尝试使用设置 <code>Searchable=\"true\"</code> 的 <code>TableColumn</code> 进行构建,可以通过 <code>TableColumn</code> 中的 <code>SearchFormItemMetadata</code> 属性定制化元数据",
5068-
"SearchFormTips": "开启 <code>UseSearchForm</code> 后 <code>SearchTemplate</code> <code>CustomerSearchModel</code> <code>CustomerSearchTemplate</code> 均不生效",
50695068
"SearchFormIntro": "通过设置 <code>UseSearchForm=\"true\"</code> 开启搜索表单功能,通过 <code>SearchItems</code> 配置搜索表单内搜索项,适用于自定义复杂搜索条件的场景",
5069+
"SearchFormTips": "开启 <code>UseSearchForm</code> 后 <code>SearchModel</code> <code>SearchTemplate</code> <code>CustomerSearchModel</code> <code>CustomerSearchTemplate</code> 均不生效",
50705070
"SearchFormTitle": "搜索表单",
50715071
"SearchTableGroupBoxText": "搜索条件",
50725072
"SearchTableIntro": "设置 <code>ShowSearch</code> 显示查询组件,通过设置 <code>SearchTemplate</code> 模板自定义搜索 UI",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>10.4.2-beta02</Version>
4+
<Version>10.4.2</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Dialog/SearchDialog.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
@if (UseSearchForm)
66
{
7-
<SearchForm Items="SearchItems" RowType="RowType" ItemsPerRow="ItemsPerRow" LabelAlign="LabelAlign" ShowLabel="ShowLabel" ShowUnsetGroupItemsOnTop="ShowUnsetGroupItemsOnTop"
8-
SearchFormLocalizerOptions="SearchFormLocalizerOptions" OnChanged="OnSearchFormFilterChanged">
7+
<SearchForm Items="SearchItems" RowType="RowType" ItemsPerRow="ItemsPerRow"
8+
LabelAlign="LabelAlign" ShowLabel="ShowLabel" ShowUnsetGroupItemsOnTop="ShowUnsetGroupItemsOnTop"
9+
SearchFormLocalizerOptions="SearchFormLocalizerOptions"
10+
OnChanged="OnSearchFormFilterChanged">
911
<Buttons>
1012
@RenderButtons
1113
</Buttons>

src/BootstrapBlazor/Components/SearchForm/SearchForm.razor.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,26 +145,18 @@ private RenderFragment AutoGenerateTemplate(ISearchItem item)
145145
if (OnChanged != null)
146146
{
147147
var filter = Items.ToFilter();
148-
await OnChanged.Invoke(filter);
148+
await OnChanged(filter);
149149
}
150150
};
151151

152-
return item.CreateSearchItemComponentByMetadata();
152+
return item.Metadata.RenderContent() ?? item.CreateSearchItemComponentByMetadata();
153153
}
154154

155155
private SearchFormLocalizerOptions? _options;
156156

157157
private SearchFormLocalizerOptions GetSearchOptions()
158158
{
159-
_options ??= SearchFormLocalizerOptions ?? new SearchFormLocalizerOptions()
160-
{
161-
SelectAllText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.SelectAllText)],
162-
BooleanAllText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanAllText)],
163-
BooleanTrueText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanTrueText)],
164-
BooleanFalseText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanFalseText)],
165-
NumberStartValueLabelText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.NumberStartValueLabelText)],
166-
NumberEndValueLabelText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.NumberEndValueLabelText)]
167-
};
159+
_options ??= SearchFormLocalizerOptions ?? SearchFormLocalizer.GetSearchFormLocalizerOptions();
168160

169161
return _options.Value;
170162
}

src/BootstrapBlazor/Components/Searches/DateTimeRangeSearchMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace BootstrapBlazor.Components;
99
/// <para lang="zh">时间区间搜索元数据类</para>
1010
/// <para lang="en">DateTime range search meta data class</para>
1111
/// </summary>
12-
public class DateTimeRangeSearchMetadata : SearchMetadataBase
12+
public class DateTimeRangeSearchMetadata : SearchFormItemMetadataBase
1313
{
1414
/// <summary>
1515
/// <para lang="zh">获得/设置 搜索值</para>

src/BootstrapBlazor/Components/Searches/DateTimeSearchMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace BootstrapBlazor.Components;
99
/// <para lang="zh">时间搜索元数据类</para>
1010
/// <para lang="en">DateTime search meta data class</para>
1111
/// </summary>
12-
public class DateTimeSearchMetadata : SearchMetadataBase
12+
public class DateTimeSearchMetadata : SearchFormItemMetadataBase
1313
{
1414
/// <summary>
1515
/// <para lang="zh">获得/设置 搜索值</para>

src/BootstrapBlazor/Components/Searches/ISearchFormItemMetadata.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ public interface ISearchFormItemMetadata
5858
/// <para lang="en">Reset method</para>
5959
/// </summary>
6060
void Reset();
61+
62+
/// <summary>
63+
/// <para lang="zh">渲染自定义内容方法</para>
64+
/// <para lang="en">Render custom content method</para>
65+
/// </summary>
66+
/// <returns></returns>
67+
RenderFragment? RenderContent();
6168
}

src/BootstrapBlazor/Components/Searches/MultipleSelectSearchMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace BootstrapBlazor.Components;
1212
public class MultipleSelectSearchMetadata : SelectSearchMetadata
1313
{
1414
/// <summary>
15-
/// <inheritdoc cref="SearchMetadataBase.GetFilter(string)"/>
15+
/// <inheritdoc cref="SearchFormItemMetadataBase.GetFilter(string)"/>
1616
/// </summary>
1717
public override FilterKeyValueAction? GetFilter(string fieldName)
1818
{

0 commit comments

Comments
 (0)