Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@
<div>@((MarkupString)Localizer["SearchFormDesc"].Value)</div>
</section>
<Table TItem="Foo"
IsPagination="true" PageItemsSource="@PageItemsSource" SearchMode="SearchMode.Top"
IsStriped="true" IsBordered="true"
ShowSearch="true" UseSearchForm="true"
ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true"
OnQueryAsync="@OnQueryAsync" OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
IsPagination="true" PageItemsSource="@PageItemsSource" SearchMode="SearchMode.Top"
IsStriped="true" IsBordered="true"
ShowSearch="true" UseSearchForm="true"
ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true"
OnQueryAsync="@OnQueryAsync" OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
<TableColumns>
<TableColumn @bind-Field="@context.DateTime" Width="180" Searchable="true" />
<TableColumn @bind-Field="@context.Name" Searchable="true" SearchFormItemMetaData="_nameSearchFormItemMetaData" />
Expand Down
8 changes: 4 additions & 4 deletions src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -5063,6 +5063,9 @@
"DisplayText4": "Display Search",
"EditModelTitle": "Edit Test Data Window",
"NamePlaceholder": "Please enter your name within 50 characters",
"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>",
"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",
"SearchFormTitle": "Search Form",
"SearchTableGroupBoxText": "Search Criteria",
"SearchTableIntro": "Set <code>ShowSearch</code> to display the query component, customize the search UI by setting the <code>SearchTemplate</code> template",
"SearchTableLi1": "Enable no data display function by setting <code>ShowEmpty=\"true\"</code>",
Expand All @@ -5076,10 +5079,7 @@
"SelectedItemValue1": "Name1",
"SelectedItemValue2": "Name2",
"TablesSearchDesc": "Commonly used for single table maintenance, simple addition, deletion, modification, search, sorting, filtering, search and other common functions can be realized through attribute configuration, and very complex can be realized through the advanced usage of <code>Template</code> business needs functions",
"TablesSearchTitle": "Table Search",
"SearchFormTitle": "Search Form",
"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",
"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>"
"TablesSearchTitle": "Table Search"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesSelection": {
"TablesSelectionCountText": "Count:{0}",
Expand Down
8 changes: 4 additions & 4 deletions src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -5063,6 +5063,9 @@
"DisplayText4": "显示搜索",
"EditModelTitle": "编辑测试数据窗口",
"NamePlaceholder": "请输入姓名,50字以内",
"SearchFormDesc": "使用 <code>UseSearchForm</code> 开启搜索表单时未提供 <code>SearchItems</code> 默认尝试使用设置 <code>Searchable=\"true\"</code> 的 <code>TableColumn</code> 进行构建,可以通过 <code>TableColumn</code> 中的 <code>SearchFormItemMetaData</code> 属性定制化元数据",
"SearchFormIntro": "通过设置 <code>UseSearchForm=\"true\"</code> 开启搜索表单功能,通过 <code>SearchItems</code> 配置搜索表单内搜索项,适用于自定义复杂搜索条件的场景",
"SearchFormTitle": "搜索表单",
"SearchTableGroupBoxText": "搜索条件",
"SearchTableIntro": "设置 <code>ShowSearch</code> 显示查询组件,通过设置 <code>SearchTemplate</code> 模板自定义搜索 UI",
"SearchTableLi1": "通过设置 <code>ShowEmpty=\"true\"</code> 开启无数据显示功能",
Expand All @@ -5076,10 +5079,7 @@
"SelectedItemValue1": "姓名1",
"SelectedItemValue2": "姓名2",
"TablesSearchDesc": "常用于单表维护,通过属性配置实现简单的增、删、改、查、排序、过滤、搜索等常用功能,通过 <code>Template</code> 的高级用法能实现非常复杂的业务需求功能",
"TablesSearchTitle": "Table 表格",
"SearchFormTitle": "搜索表单",
"SearchFormIntro": "通过设置 <code>UseSearchForm=\"true\"</code> 开启搜索表单功能,通过 <code>SearchItems</code> 配置搜索表单内搜索项,适用于自定义复杂搜索条件的场景",
"SearchFormDesc": "使用 <code>UseSearchForm</code> 开启搜索表单时未提供 <code>SearchItems</code> 默认尝试使用设置 <code>Searchable=\"true\"</code> 的 <code>TableColumn</code> 进行构建,可以通过 <code>TableColumn</code> 中的 <code>SearchFormItemMetaData</code> 属性定制化元数据"
"TablesSearchTitle": "Table 表格"
},
"BootstrapBlazor.Server.Components.Samples.Table.TablesSelection": {
"TablesSelectionCountText": "选中的行数:{0}",
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>10.4.1-beta02</Version>
<Version>10.4.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ public partial class Table<TItem>
[NotNull]
private IStringLocalizer<Table<TItem>>? Localizer { get; set; }

[Inject]
[NotNull]
private IStringLocalizer<SearchFormLocalizerOptions>? SearchFormLocalizer { get; set; }

private void OnInitLocalization()
{
AddButtonText ??= Localizer[nameof(AddButtonText)];
Expand Down
28 changes: 23 additions & 5 deletions src/BootstrapBlazor/Components/Table/Table.razor.Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public partial class Table<TItem>
public bool ShowSearchButton { get; set; } = true;

/// <summary>
/// <para lang="zh">获得/设置 是否显示高级搜索按钮,默认值为 true</para>
/// <para lang="en">Gets or sets Whether to show advanced search button. Default true. <see cref="ShowSearch" /></para>
/// <para lang="zh">获得/设置 是否显示高级搜索按钮,默认值为 true 设置 <see cref="SearchMode.Popup" /> 时生效</para>
/// <para lang="en">Gets or sets Whether to show advanced search button. Default true. Effective when <see cref="SearchMode"/> is set to Popup</para>
/// </summary>
[Parameter]
public bool ShowAdvancedSearch { get; set; } = true;
Expand Down Expand Up @@ -128,6 +128,13 @@ public partial class Table<TItem>
[Parameter]
public IEnumerable<ISearchItem>? SearchItems { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 搜索表单本地化配置项</para>
/// <para lang="en">Gets or sets Search Form Localization Options</para>
/// </summary>
[Parameter]
public SearchFormLocalizerOptions? SearchFormLocalizerOptions { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 每行显示组件数量 默认为 2</para>
/// <para lang="en">Gets or sets Items per row. Default 2</para>
Expand Down Expand Up @@ -163,8 +170,19 @@ private IEnumerable<ISearchItem> SearchFormItems
{
get
{
// TODO: 增加多语言支持
_searchItems ??= SearchItems ?? GetSearchColumns().Select(i => i.ParseSearchItem()).ToList();
if (SearchFormLocalizerOptions is null)
Comment thread
ArgoZhang marked this conversation as resolved.
{
SearchFormLocalizerOptions = new SearchFormLocalizerOptions()
{
SelectAllText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.SelectAllText)],
BooleanAllText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanAllText)],
BooleanTrueText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanTrueText)],
BooleanFalseText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.BooleanFalseText)],
NumberStartValueLabelText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.NumberStartValueLabelText)],
NumberEndValueLabelText = SearchFormLocalizer[nameof(Components.SearchFormLocalizerOptions.NumberEndValueLabelText)]
Comment thread
ArgoZhang marked this conversation as resolved.
};
}
_searchItems ??= SearchItems ?? GetSearchColumns().Select(i => i.ParseSearchItem(SearchFormLocalizerOptions.Value)).ToList();
return _searchItems;
}
}
Expand Down Expand Up @@ -315,7 +333,7 @@ protected IEnumerable<IFilterAction> GetCustomerSearches()
protected List<IFilterAction> GetAdvanceSearches()
{
var searches = new List<IFilterAction>();
if (ShowAdvancedSearch && CustomerSearchModel == null && UseSearchForm == false)
if (ShowAdvancedSearch && SearchMode == SearchMode.Popup && CustomerSearchModel == null)
Comment thread
ArgoZhang marked this conversation as resolved.
{
var callback = GetAdvancedSearchFilterCallback ?? new Func<PropertyInfo, TItem, List<SearchFilterAction>?>((p, model) =>
{
Expand Down
23 changes: 10 additions & 13 deletions src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public static class IEditItemExtensions
/// <para lang="en">Convert ITableColumn to ISearchItem</para>
/// </summary>
/// <param name="column"></param>
/// <param name="options"></param>
/// <returns></returns>
public static ISearchItem ParseSearchItem(this ITableColumn column)
public static ISearchItem ParseSearchItem(this ITableColumn column, SearchFormLocalizerOptions options)
{
var item = new SearchItem(column.GetFieldName(), column.PropertyType, column.GetDisplayName())
{
Expand All @@ -28,13 +29,13 @@ public static ISearchItem ParseSearchItem(this ITableColumn column)
GroupName = column.GroupName,
GroupOrder = column.GroupOrder,
Order = column.Order,
MetaData = column.BuildSearchMetaData()
MetaData = column.BuildSearchMetaData(options)
};
Comment thread
ArgoZhang marked this conversation as resolved.

return item;
}

private static ISearchFormItemMetaData BuildSearchMetaData(this ITableColumn column)
private static ISearchFormItemMetaData BuildSearchMetaData(this ITableColumn column, SearchFormLocalizerOptions options)
{
// 自定义搜索项逻辑
if (column.SearchFormItemMetaData is not null)
Expand All @@ -61,38 +62,34 @@ private static ISearchFormItemMetaData BuildSearchMetaData(this ITableColumn col
}
else if (type.IsEnum)
{
// TODO: 缺少本地化工作
metaData = new SelectSearchMetaData()
{
Items = type.ToSelectList(new SelectedItem() { Value = "", Text = "全选" }),
Items = type.ToSelectList(new SelectedItem() { Value = "", Text = options.SelectAllText }),
};
}
else if (fieldType.IsNumberWithDotSeparator())
{
// TODO: 缺少本地化工作
metaData = new NumberSearchMetaData()
{
StartValueLabelText = "开始数量",
EndValueLabelText = "截止数量",
StartValueLabelText = options.NumberStartValueLabelText,
EndValueLabelText = options.NumberEndValueLabelText,
ValueType = type
};
}
else if (fieldType.IsBoolean())
{
// TODO: 缺少本地化工作
metaData = new SelectSearchMetaData()
{
Items = new List<SelectedItem>()
{
new SelectedItem() { Value = "", Text = "全部" },
new SelectedItem() { Value = "True", Text = "完成" },
new SelectedItem() { Value = "False", Text = "未完成" }
new SelectedItem() { Value = "", Text = options.BooleanAllText },
new SelectedItem() { Value = "True", Text = options.BooleanTrueText },
new SelectedItem() { Value = "False", Text = options.BooleanFalseText }
}
};
}
else if (fieldType.IsDateTime())
{
// TODO: 缺少默认值设置
metaData = new DateTimeRangeSearchMetaData();
}
else
Expand Down
8 changes: 8 additions & 0 deletions src/BootstrapBlazor/Locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,13 @@
},
"BootstrapBlazor.Components.CardUpload": {
"DeleteConfirmContent": "Are you sure you want to delete the current data?"
},
"BootstrapBlazor.Components.SearchFormLocalizerOptions": {
"SelectAllText": "All",
"BooleanAllText": "All",
"BooleanTrueText": "True",
"BooleanFalseText": "False",
"NumberStartValueLabelText": "Start",
"NumberEndValueLabelText": "End"
}
}
8 changes: 8 additions & 0 deletions src/BootstrapBlazor/Locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,13 @@
},
"BootstrapBlazor.Components.CardUpload": {
"DeleteConfirmContent": "确定删除当前数据吗?"
},
"BootstrapBlazor.Components.SearchFormLocalizerOptions": {
"SelectAllText": "全部",
"BooleanAllText": "全部",
"BooleanTrueText": "是",
"BooleanFalseText": "否",
"NumberStartValueLabelText": "开始数量",
"NumberEndValueLabelText": "截止数量"
}
}
49 changes: 49 additions & 0 deletions src/BootstrapBlazor/Options/SearchFormLocalizerOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone

namespace BootstrapBlazor.Components;

/// <summary>
/// <para lang="zh">搜索表单项本地化配置类</para>
/// <para lang="en">Search form item localization configuration class</para>
/// </summary>
public readonly record struct SearchFormLocalizerOptions
{
/// <summary>
/// <para lang="zh">全选文本</para>
/// <para lang="en">Select all text</para>
/// </summary>
public string SelectAllText { get; init; }

/// <summary>
/// <para lang="zh">布尔值全部文本</para>
/// <para lang="en">Boolean all text</para>
/// </summary>
public string BooleanAllText { get; init; }

/// <summary>
/// <para lang="zh">布尔值为真文本</para>
/// <para lang="en">Boolean true text</para>
/// </summary>
public string BooleanTrueText { get; init; }

/// <summary>
/// <para lang="zh">布尔值为假文本</para>
/// <para lang="en">Boolean false text</para>
/// </summary>
public string BooleanFalseText { get; init; }

/// <summary>
/// <para lang="zh">数字起始值标签文本</para>
/// <para lang="en">Number start value label text</para>
/// </summary>
public string NumberStartValueLabelText { get; init; }

/// <summary>
/// <para lang="zh">数字结束值标签文本</para>
/// <para lang="en">Number end value label text</para>
/// </summary>
public string NumberEndValueLabelText { get; init; }
Comment thread
ArgoZhang marked this conversation as resolved.
}
Loading