/// <summary> /// 调用 OnQuery 回调方法获得数据源 /// </summary> protected async Task QueryData() { // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I29YK1 // TODO: 选中行目前不支持跨页 // 原因是选中行实例无法在翻页后保持 SelectedItems.Clear(); QueryData <TItem>?queryData = null; var queryOption = new QueryPageOptions() { PageIndex = PageIndex, PageItems = PageItems, SearchText = SearchText, SortOrder = SortOrder, SortName = SortName, Filters = Filters.Values, Searchs = GetSearchs(), SearchModel = SearchModel }; if (OnQueryAsync != null) { queryData = await OnQueryAsync(queryOption); } else if (UseInjectDataService) { queryData = await GetDataService().QueryAsync(queryOption); } if (queryData != null) { Items = queryData.Items; TotalCount = queryData.TotalCount; IsFiltered = queryData.IsFiltered; IsSorted = queryData.IsSorted; IsSearch = queryData.IsSearch; // 外部未过滤,内部自行过滤 if (!IsFiltered && Filters.Any()) { Items = Items.Where(Filters.Values.GetFilterFunc <TItem>()); TotalCount = Items.Count(); } // 外部未处理排序,内部自行排序 if (!IsSorted && SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(SortName)) { var invoker = SortLambdaCache.GetOrAdd(typeof(TItem), key => Items.GetSortLambda().Compile()); Items = invoker(Items, SortName, SortOrder); } } if (!IsRendered && SelectedRows != null) { SelectedItems.AddRange(Items.Where(i => SelectedRows.Contains(i))); } }
/// <summary> /// 调用 OnQuery 回调方法获得数据源 /// </summary> protected async Task QueryData() { // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I29YK1 // 选中行目前不支持跨页 原因是选中行实例无法在翻页后保持 SelectedItems.Clear(); QueryData <TItem>?queryData = null; var queryOption = new QueryPageOptions() { IsPage = IsPagination, PageIndex = PageIndex, PageItems = PageItems, SearchText = SearchText, SortOrder = SortOrder, SortName = SortName, Filters = Filters.Values, Searchs = GetSearchs(), SearchModel = SearchModel }; if (OnQueryAsync != null) { queryData = await OnQueryAsync(queryOption); } else if (UseInjectDataService) { queryData = await GetDataService().QueryAsync(queryOption); } if (queryData != null) { Items = queryData.Items; if (IsTree) { KeySet.Clear(); if (TableTreeNode <TItem> .HasKey) { CheckExpandKeys(TreeRows); } if (KeySet.Count > 0) { TreeRows = new List <TableTreeNode <TItem> >(); foreach (var item in Items) { 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 = Items.Select(item => new TableTreeNode <TItem>(item) { HasChildren = CheckTreeChildren(item) }).ToList(); } } TotalCount = queryData.TotalCount; IsFiltered = queryData.IsFiltered; IsSorted = queryData.IsSorted; IsSearch = queryData.IsSearch; // 外部未过滤,内部自行过滤 if (!IsFiltered && Filters.Any()) { Items = Items.Where(Filters.Values.GetFilterFunc <TItem>()); TotalCount = Items.Count(); } // 外部未处理排序,内部自行排序 if (!IsSorted && SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(SortName)) { var invoker = SortLambdaCache.GetOrAdd(typeof(TItem), key => LambdaExtensions.GetSortLambda <TItem>().Compile()); Items = invoker(Items, SortName, SortOrder); } } if (SelectedRows != null) { SelectedItems.AddRange(Items.Where(i => SelectedRows.Contains(i))); } }