mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-05 05:29:47 +08:00
!2288 doc(#I4PNVD): update SearchTemplate sample code for table
* doc: 修复 SearchTemplate 模板查询示例
This commit is contained in:
parent
4b42220450
commit
f7682ee0ab
@ -20,10 +20,10 @@
|
||||
ShowToolbar="true" ShowSearch="true" IsMultipleSelect="true" ShowExtendButtons="true"
|
||||
AddModalTitle="增加测试数据窗口" EditModalTitle="编辑测试数据窗口"
|
||||
SearchModel="@SearchModel" ShowEmpty="true" SearchMode="SearchMode.Top"
|
||||
OnQueryAsync="@OnQueryAsync" OnResetSearchAsync="@OnResetSearchAsync"
|
||||
OnQueryAsync="@OnSearchModelQueryAsync" OnResetSearchAsync="@OnResetSearchAsync"
|
||||
OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
|
||||
<TableColumns>
|
||||
<TableColumn @bind-Field="@context.DateTime" Width="180" Filterable="true" />
|
||||
<TableColumn @bind-Field="@context.DateTime" Width="180" />
|
||||
<TableColumn @bind-Field="@context.Name" />
|
||||
<TableColumn @bind-Field="@context.Address" />
|
||||
<TableColumn @bind-Field="@context.Education" />
|
||||
@ -35,7 +35,7 @@
|
||||
<BootstrapInput @bind-Value="@context.Name" placeholder="请输入姓名,50字以内" maxlength="50" ShowLabel="true" DisplayText="@Localizer[nameof(context.Name)]" />
|
||||
</div>
|
||||
<div class="col-12 col-sm-6">
|
||||
<BootstrapInput @bind-Value="@context.Address" placeholder="请输入地址,50字以内" maxlength="50" ShowLabel="true" DisplayText="@Localizer[nameof(context.Address)]" />
|
||||
<BootstrapInput @bind-Value="@context.Address" placeholder="请输入地址,500字以内" maxlength="500" ShowLabel="true" DisplayText="@Localizer[nameof(context.Address)]" />
|
||||
</div>
|
||||
</div>
|
||||
</GroupBox>
|
||||
@ -103,11 +103,11 @@
|
||||
<SearchTemplate Context="model">
|
||||
@{
|
||||
var items = new List<SelectedItem>()
|
||||
{
|
||||
new SelectedItem { Text = "请选择 ...", Value = "" },
|
||||
new SelectedItem { Text = "姓名1", Value = "姓名1" },
|
||||
new SelectedItem { Text = "姓名2", Value = "姓名2" },
|
||||
};
|
||||
{
|
||||
new SelectedItem { Text = "请选择 ...", Value = "" },
|
||||
new SelectedItem { Text = "姓名1", Value = "姓名1" },
|
||||
new SelectedItem { Text = "姓名2", Value = "姓名2" },
|
||||
};
|
||||
<div class="col-12 col-sm-6">
|
||||
<Select Items="items" @bind-Value="@model!.Name" ShowLabel="true" DisplayText="姓名" />
|
||||
</div>
|
||||
|
@ -101,14 +101,56 @@ public sealed partial class TablesSearch
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task<QueryData<Foo>> OnSearchModelQueryAsync(QueryPageOptions options)
|
||||
{
|
||||
// 自定义了 SearchModel
|
||||
IEnumerable<Foo> items = Items;
|
||||
|
||||
// 设置记录总数
|
||||
var total = items.Count();
|
||||
|
||||
if (!string.IsNullOrEmpty(SearchModel.Name))
|
||||
{
|
||||
items = items.Where(i => i.Name == SearchModel.Name);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(SearchModel.Address))
|
||||
{
|
||||
items = items.Where(i => i.Address == SearchModel.Address);
|
||||
}
|
||||
|
||||
// 内存分页
|
||||
items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();
|
||||
|
||||
return Task.FromResult(new QueryData<Foo>()
|
||||
{
|
||||
Items = items,
|
||||
TotalCount = total,
|
||||
IsSorted = true,
|
||||
IsFiltered = true,
|
||||
IsSearch = true,
|
||||
IsAdvanceSearch = true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
|
||||
{
|
||||
IEnumerable<Foo> items = Items;
|
||||
|
||||
// CustomerSearchModel 过滤条件已经内置到 Searchs 无需额外代码处理
|
||||
var isAdvanceSearch = false;
|
||||
// 处理高级搜索
|
||||
if (options.AdvanceSearchs.Any())
|
||||
{
|
||||
items = items.Where(options.AdvanceSearchs.GetFilterFunc<Foo>());
|
||||
isAdvanceSearch = true;
|
||||
}
|
||||
|
||||
// 处理 自定义 高级搜索 CustomerSearchModel 过滤条件
|
||||
if (options.CustomerSearchs.Any())
|
||||
{
|
||||
items = items.Where(options.CustomerSearchs.GetFilterFunc<Foo>());
|
||||
isAdvanceSearch = true;
|
||||
}
|
||||
|
||||
// 处理 Searchable=true 列与 SeachText 模糊搜索
|
||||
@ -146,7 +188,8 @@ public sealed partial class TablesSearch
|
||||
TotalCount = total,
|
||||
IsSorted = isSorted,
|
||||
IsFiltered = isFiltered,
|
||||
IsSearch = options.CustomerSearchs.Any()
|
||||
IsSearch = options.CustomerSearchs.Any(),
|
||||
IsAdvanceSearch = isAdvanceSearch
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user