mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-03 12:37:40 +08:00
fix(module: table): ReloadData()
can't invoke OnChange
(#2071)
* fix(module: table): optimized query API for EF * fix table ReloadData() can't invoke OnChange
This commit is contained in:
parent
961a5ca02b
commit
26d880f8ed
@ -214,9 +214,7 @@ namespace AntDesign
|
||||
|
||||
FlushCache();
|
||||
|
||||
this.InternalReload();
|
||||
|
||||
StateHasChanged();
|
||||
this.ReloadAndInvokeChange();
|
||||
}
|
||||
|
||||
public QueryModel GetQueryModel() => BuildQueryModel();
|
||||
@ -281,6 +279,7 @@ namespace AntDesign
|
||||
private QueryModel<TItem> InternalReload()
|
||||
{
|
||||
var queryModel = BuildQueryModel();
|
||||
_currentQueryModel = queryModel;
|
||||
|
||||
if (ServerSide)
|
||||
{
|
||||
@ -291,25 +290,10 @@ namespace AntDesign
|
||||
{
|
||||
if (_dataSource != null)
|
||||
{
|
||||
var query = _dataSource.AsQueryable();
|
||||
foreach (var sort in queryModel.SortModel.OrderBy(x => x.Priority))
|
||||
{
|
||||
query = sort.SortList(query);
|
||||
}
|
||||
|
||||
foreach (var filter in queryModel.FilterModel)
|
||||
{
|
||||
query = filter.FilterList(query);
|
||||
}
|
||||
var query = queryModel.ExecuteQuery(_dataSource.AsQueryable());
|
||||
|
||||
_total = query.Count();
|
||||
|
||||
query = query.Skip((PageIndex - 1) * PageSize).Take(PageSize);
|
||||
queryModel.SetQueryableLambda(query);
|
||||
|
||||
_currentQueryModel = queryModel;
|
||||
|
||||
_showItems = query;
|
||||
_showItems = queryModel.CurrentPagedRecords(query);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -10,6 +10,8 @@ namespace AntDesign.TableModels
|
||||
|
||||
public int PageSize { get; }
|
||||
|
||||
public int OffsetRecords => (PageIndex - 1) * PageSize;
|
||||
|
||||
public IList<ITableSortModel> SortModel { get; private set; }
|
||||
|
||||
public IList<ITableFilterModel> FilterModel { get; private set; }
|
||||
@ -31,9 +33,6 @@ namespace AntDesign.TableModels
|
||||
|
||||
public class QueryModel<TItem> : QueryModel
|
||||
{
|
||||
[JsonIgnore]
|
||||
public IQueryable<TItem> QueryableLambda { get; private set; }
|
||||
|
||||
internal QueryModel(int pageIndex, int pageSize) : base(pageIndex, pageSize)
|
||||
{
|
||||
}
|
||||
@ -48,9 +47,21 @@ namespace AntDesign.TableModels
|
||||
FilterModel.Add(model);
|
||||
}
|
||||
|
||||
internal void SetQueryableLambda(IQueryable<TItem> query)
|
||||
public IQueryable<TItem> ExecuteQuery(IQueryable<TItem> query)
|
||||
{
|
||||
this.QueryableLambda = query;
|
||||
foreach (var sort in SortModel.OrderBy(x => x.Priority))
|
||||
{
|
||||
query = sort.SortList(query);
|
||||
}
|
||||
|
||||
foreach (var filter in FilterModel)
|
||||
{
|
||||
query = filter.FilterList(query);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public IQueryable<TItem> CurrentPagedRecords(IQueryable<TItem> query) => query.Skip(OffsetRecords).Take(PageSize);
|
||||
}
|
||||
}
|
||||
|
24
components/table/TableModels/QueryableExtensions.cs
Normal file
24
components/table/TableModels/QueryableExtensions.cs
Normal file
@ -0,0 +1,24 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AntDesign.TableModels
|
||||
{
|
||||
public static class QueryableExtensions
|
||||
{
|
||||
public static IQueryable<TItem> ExecuteTableQuery<TItem>(this IQueryable<TItem> source, QueryModel<TItem> queryModel)
|
||||
{
|
||||
return queryModel.ExecuteQuery(source);
|
||||
}
|
||||
|
||||
public static IQueryable<TItem> CurrentPagedRecords<TItem>(this IQueryable<TItem> source, QueryModel<TItem> queryModel)
|
||||
{
|
||||
return queryModel.CurrentPagedRecords(source);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user