Skip to content

Commit

Permalink
doc(Table): update search of Table sample code (#2552)
Browse files Browse the repository at this point in the history
* refactor: 更新搜索示例代码

* refactor: 精简代码

* doc: 更新示例代码
  • Loading branch information
ArgoZhang authored Dec 11, 2023
1 parent 3594f80 commit 2ecdeca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
var total = items.Count();

// 内存分页
items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();
items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems);
return Task.FromResult(new QueryData<Foo>()
{
Items = items,
TotalCount = total,
IsSorted = isSorted,
IsFiltered = options.Filters.Any(),
IsSearch = options.CustomerSearches.Any() || !string.IsNullOrEmpty(options.SearchText),
IsAdvanceSearch = options.AdvanceSearches.Any()
IsFiltered = options.Filters.Count > 0,
IsSearch = options.CustomerSearches.Count > 0 || !string.IsNullOrEmpty(options.SearchText),
IsAdvanceSearch = options.CustomerSearches.Count > 0 && string.IsNullOrEmpty(options.SearchText),
});
}
}
14 changes: 7 additions & 7 deletions src/BootstrapBlazor/Components/Table/Table.razor.Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class Table<TItem>
/// 获得/设置 被选中数据集合
/// </summary>
[Parameter]
public List<TItem> SelectedRows { get; set; } = new List<TItem>();
public List<TItem> SelectedRows { get; set; } = [];

/// <summary>
/// 获得/设置 选中行变化回调方法
Expand Down Expand Up @@ -475,22 +475,22 @@ void ProcessData()
var searched = queryData.IsSearch;

// 外部未处理 SearchText 模糊查询
if (!searched && queryOption.Searches.Any())
if (!searched && queryOption.Searches.Count > 0)
{
QueryItems = QueryItems.Where(queryOption.Searches.GetFilterFunc<TItem>(FilterLogic.Or));
TotalCount = QueryItems.Count();
}

// 外部未处理自定义高级搜索 内部进行高级自定义搜索过滤
if (!IsAdvanceSearch && queryOption.CustomerSearches.Any())
if (!IsAdvanceSearch && queryOption.CustomerSearches.Count> 0)
{
QueryItems = QueryItems.Where(queryOption.CustomerSearches.GetFilterFunc<TItem>());
TotalCount = QueryItems.Count();
IsAdvanceSearch = true;
}

// 外部未过滤,内部自行过滤
if (!filtered && queryOption.Filters.Any())
if (!filtered && queryOption.Filters.Count > 0)
{
QueryItems = QueryItems.Where(queryOption.Filters.GetFilterFunc<TItem>());
TotalCount = QueryItems.Count();
Expand All @@ -505,7 +505,7 @@ void ProcessData()
var invoker = Utility.GetSortFunc<TItem>();
QueryItems = invoker(QueryItems, queryOption.SortName, queryOption.SortOrder);
}
else if (queryOption.SortList.Any())
else if (queryOption.SortList.Count > 0)
{
var invoker = Utility.GetSortListFunc<TItem>();
QueryItems = invoker(QueryItems, queryOption.SortList);
Expand All @@ -521,7 +521,7 @@ async Task ProcessTreeData()
treeNodes.AddRange(await TreeNodeConverter(QueryItems));
}

if (treeNodes.Any())
if (treeNodes.Count > 0)
{
await CheckExpand(treeNodes);
}
Expand Down Expand Up @@ -581,7 +581,7 @@ private QueryPageOptions BuildQueryPageOptions()

private void ResetSelectedRows(IEnumerable<TItem> items)
{
if (SelectedRows.Any())
if (SelectedRows.Count > 0)
{
SelectedRows = items.Where(i => SelectedRows.Any(row => Equals(i, row))).ToList();
}
Expand Down

0 comments on commit 2ecdeca

Please sign in to comment.