mirror of
https://github.com/dotnetcore/BootstrapBlazor.git
synced 2025-12-20 10:26:41 +08:00
!2300 fix(#I4Q0DK): throw exception use Item as data source
* chore: bump version to 6.2.6 * fix: 修复移除 UseInjectDataService 导致使用 Items 时报错问题 * doc: 更新介绍文档修复资源文件错误
This commit is contained in:
@@ -2661,7 +2661,7 @@
|
||||
"LearnLi4": "Exercise-Configure the development environment",
|
||||
"LearnLi5": "Blazor Components",
|
||||
"LearnLi6": "Exercise-Add Components",
|
||||
"LeanrnLi7": "Data binding and events",
|
||||
"LearnLi7": "Data binding and events",
|
||||
"LearnLi8": "Exercise-Data binding and Events",
|
||||
"Summarize": "Summarize",
|
||||
"ProjectsShow": "Exhibition",
|
||||
|
||||
@@ -2664,7 +2664,7 @@
|
||||
"LearnLi4": "练习 - 配置开发环境",
|
||||
"LearnLi5": "Blazor 组件",
|
||||
"LearnLi6": "练习 - 添加组件",
|
||||
"LeanrnLi7": "数据绑定和事件",
|
||||
"LearnLi7": "数据绑定和事件",
|
||||
"LearnLi8": "练习 - 数据绑定和事件",
|
||||
"Summarize": "总结",
|
||||
"ProjectsShow": "作品展示",
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
<a target="_blank" href="https://docs.microsoft.com/zh-cn/learn/modules/build-blazor-webassembly-visual-studio-code/4-blazor-components?WT.mc_id=DT-MVP-5004174">@Localizer["LearnLi5"]</a>
|
||||
</li>
|
||||
<li class="learn-item">
|
||||
<a target="_blank" href="https://docs.microsoft.com/zh-cn/learn/modules/build-blazor-webassembly-visual-studio-code/5-exercise-add-component?WT.mc_id=DT-MVP-5004174">@Localizer["Learn6"]</a>
|
||||
<a target="_blank" href="https://docs.microsoft.com/zh-cn/learn/modules/build-blazor-webassembly-visual-studio-code/5-exercise-add-component?WT.mc_id=DT-MVP-5004174">@Localizer["LearnLi6"]</a>
|
||||
</li>
|
||||
<li class="learn-item">
|
||||
<a target="_blank" href="https://docs.microsoft.com/zh-cn/learn/modules/build-blazor-webassembly-visual-studio-code/6-csharp-razor-binding?WT.mc_id=DT-MVP-5004174">@Localizer["LeanrnLi7"]</a>
|
||||
<a target="_blank" href="https://docs.microsoft.com/zh-cn/learn/modules/build-blazor-webassembly-visual-studio-code/6-csharp-razor-binding?WT.mc_id=DT-MVP-5004174">@Localizer["LearnLi7"]</a>
|
||||
</li>
|
||||
<li class="learn-item">
|
||||
<a target="_blank" href="https://docs.microsoft.com/zh-cn/learn/modules/build-blazor-webassembly-visual-studio-code/7-exercise-razor-binding?WT.mc_id=DT-MVP-5004174">@Localizer["LearnLi8"]</a>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>6.2.5</Version>
|
||||
<Version>6.2.6</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
|
||||
@@ -419,12 +419,20 @@ public partial class Table<TItem>
|
||||
/// </summary>
|
||||
protected async Task QueryData()
|
||||
{
|
||||
if (OnQueryAsync == null && DynamicContext != null && typeof(TItem).IsAssignableTo(typeof(IDynamicObject)))
|
||||
if (Items == null)
|
||||
{
|
||||
QueryItems = DynamicContext.GetItems().Cast<TItem>();
|
||||
TotalCount = QueryItems.Count();
|
||||
if (OnQueryAsync == null && DynamicContext != null && typeof(TItem).IsAssignableTo(typeof(IDynamicObject)))
|
||||
{
|
||||
QueryItems = DynamicContext.GetItems().Cast<TItem>();
|
||||
TotalCount = QueryItems.Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
await OnQuery();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
async Task OnQuery()
|
||||
{
|
||||
QueryData<TItem>? queryData = null;
|
||||
var queryOption = new QueryPageOptions()
|
||||
@@ -459,86 +467,96 @@ public partial class Table<TItem>
|
||||
TotalCount = queryData.TotalCount;
|
||||
IsAdvanceSearch = queryData.IsAdvanceSearch;
|
||||
|
||||
var filtered = queryData.IsFiltered;
|
||||
var sorted = queryData.IsSorted;
|
||||
var searched = queryData.IsSearch;
|
||||
|
||||
// 分页情况下内部不做处理防止页码错乱
|
||||
if (!queryOption.IsPage)
|
||||
{
|
||||
// 外部未处理 SearchText 模糊查询
|
||||
if (!searched && queryOption.Searchs.Any())
|
||||
{
|
||||
QueryItems = QueryItems.Where(queryOption.Searchs.GetFilterFunc<TItem>(FilterLogic.Or));
|
||||
TotalCount = QueryItems.Count();
|
||||
}
|
||||
|
||||
// 外部未处理自定义高级搜索 内部进行高级自定义搜索过滤
|
||||
if (!IsAdvanceSearch && queryOption.CustomerSearchs.Any())
|
||||
{
|
||||
QueryItems = QueryItems.Where(queryOption.CustomerSearchs.GetFilterFunc<TItem>());
|
||||
TotalCount = QueryItems.Count();
|
||||
IsAdvanceSearch = true;
|
||||
}
|
||||
|
||||
// 外部未过滤,内部自行过滤
|
||||
if (!filtered && queryOption.Filters.Any())
|
||||
{
|
||||
QueryItems = QueryItems.Where(queryOption.Filters.GetFilterFunc<TItem>());
|
||||
TotalCount = QueryItems.Count();
|
||||
}
|
||||
|
||||
// 外部未处理排序,内部自行排序
|
||||
// 先处理列头排序 再处理默认多列排序
|
||||
if (!sorted)
|
||||
{
|
||||
if (queryOption.SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(queryOption.SortName))
|
||||
{
|
||||
var invoker = Utility.GetSortFunc<TItem>();
|
||||
QueryItems = invoker(QueryItems, queryOption.SortName, queryOption.SortOrder);
|
||||
}
|
||||
else if (queryOption.SortList != null && queryOption.SortList.Any())
|
||||
{
|
||||
var invoker = Utility.GetSortListFunc<TItem>();
|
||||
QueryItems = invoker(QueryItems, queryOption.SortList);
|
||||
}
|
||||
}
|
||||
ProcessPageData(queryData, queryOption);
|
||||
}
|
||||
|
||||
if (IsTree)
|
||||
{
|
||||
KeySet.Clear();
|
||||
if (TableTreeNode<TItem>.HasKey)
|
||||
{
|
||||
CheckExpandKeys(TreeRows);
|
||||
}
|
||||
if (KeySet.Count > 0)
|
||||
{
|
||||
TreeRows = new List<TableTreeNode<TItem>>();
|
||||
foreach (var item in QueryItems)
|
||||
{
|
||||
var node = new TableTreeNode<TItem>(item)
|
||||
{
|
||||
HasChildren = CheckTreeChildren(item),
|
||||
};
|
||||
node.IsExpand = node.HasChildren && node.Key != null && KeySet.Contains(node.Key);
|
||||
if (node.IsExpand)
|
||||
{
|
||||
await RestoreIsExpand(node);
|
||||
}
|
||||
TreeRows.Add(node);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TreeRows = QueryItems.Select(item => new TableTreeNode<TItem>(item)
|
||||
{
|
||||
HasChildren = CheckTreeChildren(item)
|
||||
}).ToList();
|
||||
}
|
||||
await ProcessTreeData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessPageData(QueryData<TItem> queryData, QueryPageOptions queryOption)
|
||||
{
|
||||
var filtered = queryData.IsFiltered;
|
||||
var sorted = queryData.IsSorted;
|
||||
var searched = queryData.IsSearch;
|
||||
|
||||
// 外部未处理 SearchText 模糊查询
|
||||
if (!searched && queryOption.Searchs.Any())
|
||||
{
|
||||
QueryItems = QueryItems.Where(queryOption.Searchs.GetFilterFunc<TItem>(FilterLogic.Or));
|
||||
TotalCount = QueryItems.Count();
|
||||
}
|
||||
|
||||
// 外部未处理自定义高级搜索 内部进行高级自定义搜索过滤
|
||||
if (!IsAdvanceSearch && queryOption.CustomerSearchs.Any())
|
||||
{
|
||||
QueryItems = QueryItems.Where(queryOption.CustomerSearchs.GetFilterFunc<TItem>());
|
||||
TotalCount = QueryItems.Count();
|
||||
IsAdvanceSearch = true;
|
||||
}
|
||||
|
||||
// 外部未过滤,内部自行过滤
|
||||
if (!filtered && queryOption.Filters.Any())
|
||||
{
|
||||
QueryItems = QueryItems.Where(queryOption.Filters.GetFilterFunc<TItem>());
|
||||
TotalCount = QueryItems.Count();
|
||||
}
|
||||
|
||||
// 外部未处理排序,内部自行排序
|
||||
// 先处理列头排序 再处理默认多列排序
|
||||
if (!sorted)
|
||||
{
|
||||
if (queryOption.SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(queryOption.SortName))
|
||||
{
|
||||
var invoker = Utility.GetSortFunc<TItem>();
|
||||
QueryItems = invoker(QueryItems, queryOption.SortName, queryOption.SortOrder);
|
||||
}
|
||||
else if (queryOption.SortList != null && queryOption.SortList.Any())
|
||||
{
|
||||
var invoker = Utility.GetSortListFunc<TItem>();
|
||||
QueryItems = invoker(QueryItems, queryOption.SortList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async Task ProcessTreeData()
|
||||
{
|
||||
KeySet.Clear();
|
||||
if (TableTreeNode<TItem>.HasKey)
|
||||
{
|
||||
CheckExpandKeys(TreeRows);
|
||||
}
|
||||
if (KeySet.Count > 0)
|
||||
{
|
||||
TreeRows = new List<TableTreeNode<TItem>>();
|
||||
foreach (var item in QueryItems)
|
||||
{
|
||||
var node = new TableTreeNode<TItem>(item)
|
||||
{
|
||||
HasChildren = CheckTreeChildren(item),
|
||||
};
|
||||
node.IsExpand = node.HasChildren && node.Key != null && KeySet.Contains(node.Key);
|
||||
if (node.IsExpand)
|
||||
{
|
||||
await RestoreIsExpand(node);
|
||||
}
|
||||
TreeRows.Add(node);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TreeRows = QueryItems.Select(item => new TableTreeNode<TItem>(item)
|
||||
{
|
||||
HasChildren = CheckTreeChildren(item)
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<object> KeySet { get; } = new();
|
||||
|
||||
Reference in New Issue
Block a user