2020-11-08 23:29:05 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-05-30 01:46:41 +08:00
|
|
|
|
using System.Linq;
|
2020-06-02 19:15:15 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2021-01-09 23:57:31 +08:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-10-25 18:31:31 +08:00
|
|
|
|
using AntDesign.Core.HashCodes;
|
2021-01-09 23:57:31 +08:00
|
|
|
|
using AntDesign.JsInterop;
|
2020-07-08 16:12:49 +08:00
|
|
|
|
using AntDesign.TableModels;
|
2020-05-30 01:46:41 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
2021-01-09 23:57:31 +08:00
|
|
|
|
public partial class Table<TItem> : AntDomComponentBase, ITable, IAsyncDisposable
|
2020-05-30 01:46:41 +08:00
|
|
|
|
{
|
2020-06-05 16:06:23 +08:00
|
|
|
|
private static readonly TItem _fieldModel = (TItem)RuntimeHelpers.GetUninitializedObject(typeof(TItem));
|
2020-11-08 23:29:05 +08:00
|
|
|
|
private static readonly EventCallbackFactory _callbackFactory = new EventCallbackFactory();
|
2020-06-05 16:06:23 +08:00
|
|
|
|
|
2020-10-25 18:31:31 +08:00
|
|
|
|
private bool _shouldRender = true;
|
2021-01-09 23:57:31 +08:00
|
|
|
|
private int _parametersHashCode;
|
2020-10-25 18:31:31 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderMode RenderMode { get; set; } = RenderMode.Always;
|
|
|
|
|
|
2020-05-30 01:46:41 +08:00
|
|
|
|
[Parameter]
|
2020-06-19 23:06:33 +08:00
|
|
|
|
public IEnumerable<TItem> DataSource
|
|
|
|
|
{
|
|
|
|
|
get => _dataSource;
|
|
|
|
|
set
|
|
|
|
|
{
|
2020-10-30 22:40:19 +08:00
|
|
|
|
_waitingReload = true;
|
2020-07-10 17:57:20 +08:00
|
|
|
|
_dataSourceCount = value?.Count() ?? 0;
|
2020-07-02 20:30:01 +08:00
|
|
|
|
_dataSource = value ?? Enumerable.Empty<TItem>();
|
2020-06-19 23:06:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-30 01:46:41 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment<TItem> ChildContent { get; set; }
|
|
|
|
|
|
2020-11-09 22:17:27 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment<TItem> RowTemplate { get; set; }
|
|
|
|
|
|
2020-11-08 23:29:05 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment<RowData<TItem>> ExpandTemplate { get; set; }
|
2021-07-02 13:45:24 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool DefaultExpandAllRows { get; set; }
|
2020-11-08 23:29:05 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<RowData<TItem>, bool> RowExpandable { get; set; } = _ => true;
|
|
|
|
|
|
2020-11-09 22:17:27 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<TItem, IEnumerable<TItem>> TreeChildren { get; set; } = _ => Enumerable.Empty<TItem>();
|
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<QueryModel<TItem>> OnChange { get; set; }
|
|
|
|
|
|
2020-11-18 17:10:35 +08:00
|
|
|
|
[Parameter]
|
2021-03-01 23:47:16 +08:00
|
|
|
|
public Func<RowData<TItem>, Dictionary<string, object>> OnRow { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<Dictionary<string, object>> OnHeaderRow { get; set; }
|
2020-11-18 17:10:35 +08:00
|
|
|
|
|
2020-06-02 19:15:15 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Loading { get; set; }
|
|
|
|
|
|
2020-07-02 20:30:01 +08:00
|
|
|
|
[Parameter]
|
2020-09-16 13:58:16 +08:00
|
|
|
|
public string Title { get; set; }
|
2020-07-02 20:30:01 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-09-16 13:58:16 +08:00
|
|
|
|
public RenderFragment TitleTemplate { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Footer { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public RenderFragment FooterTemplate { get; set; }
|
2020-07-02 20:30:01 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-06-29 15:52:28 +08:00
|
|
|
|
public TableSize Size { get; set; }
|
|
|
|
|
|
2020-09-07 22:46:50 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public TableLocale Locale { get; set; } = LocaleProvider.CurrentLocale.Table;
|
|
|
|
|
|
2020-07-02 20:30:01 +08:00
|
|
|
|
[Parameter]
|
2020-06-29 15:52:28 +08:00
|
|
|
|
public bool Bordered { get; set; } = false;
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string ScrollX { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string ScrollY { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int ScrollBarWidth { get; set; } = 17;
|
|
|
|
|
|
2020-11-09 22:17:27 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public int IndentSize { get; set; } = 15;
|
|
|
|
|
|
2021-01-21 14:56:20 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public int ExpandIconColumnIndex { get; set; }
|
2021-02-01 23:42:54 +08:00
|
|
|
|
|
2021-01-24 13:56:27 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<RowData<TItem>, string> RowClassName { get; set; } = _ => "";
|
2021-02-01 23:42:54 +08:00
|
|
|
|
|
2021-01-24 13:56:27 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public Func<RowData<TItem>, string> ExpandedRowClassName { get; set; } = _ => "";
|
2021-01-21 14:56:20 +08:00
|
|
|
|
|
2021-03-05 23:58:38 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<RowData<TItem>> OnExpand { get; set; }
|
|
|
|
|
|
2021-01-24 13:52:57 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public SortDirection[] SortDirections { get; set; } = SortDirection.Preset.Default;
|
|
|
|
|
|
2021-02-22 11:29:56 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string TableLayout { get; set; }
|
|
|
|
|
|
2021-03-04 17:31:48 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<RowData<TItem>> OnRowClick { get; set; }
|
|
|
|
|
|
2021-07-21 01:27:14 +08:00
|
|
|
|
private bool _remoteDataSource;
|
|
|
|
|
private bool _hasRemoteDataSourceAttribute;
|
|
|
|
|
|
2021-06-15 16:13:06 +08:00
|
|
|
|
[Parameter]
|
2021-07-21 01:27:14 +08:00
|
|
|
|
public bool RemoteDataSource
|
|
|
|
|
{
|
|
|
|
|
get => _remoteDataSource;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_remoteDataSource = value;
|
|
|
|
|
_hasRemoteDataSourceAttribute = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-15 16:13:06 +08:00
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
[Inject]
|
|
|
|
|
public DomEventService DomEventService { get; set; }
|
|
|
|
|
|
|
|
|
|
public ColumnContext ColumnContext { get; set; }
|
2020-06-19 23:06:33 +08:00
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
private IEnumerable<TItem> _showItems;
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
private IEnumerable<TItem> _dataSource;
|
2020-07-02 20:30:01 +08:00
|
|
|
|
|
2021-03-08 19:18:56 +08:00
|
|
|
|
private IList<SummaryRow> _summaryRows;
|
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
private bool _waitingReload;
|
|
|
|
|
private bool _waitingReloadAndInvokeChange;
|
|
|
|
|
private bool _treeMode;
|
|
|
|
|
|
|
|
|
|
private bool _hasFixLeft;
|
|
|
|
|
private bool _hasFixRight;
|
|
|
|
|
private bool _pingRight;
|
|
|
|
|
private bool _pingLeft;
|
2021-01-21 14:56:20 +08:00
|
|
|
|
private int _treeExpandIconColumnIndex;
|
2021-03-12 17:02:11 +08:00
|
|
|
|
private ClassMapper _wrapperClassMapper = new ClassMapper();
|
2021-02-22 11:29:56 +08:00
|
|
|
|
private string TableLayoutStyle => TableLayout == null ? "" : $"table-layout: {TableLayout};";
|
2021-01-09 23:57:31 +08:00
|
|
|
|
|
|
|
|
|
private ElementReference _tableHeaderRef;
|
|
|
|
|
private ElementReference _tableBodyRef;
|
2020-08-01 23:45:48 +08:00
|
|
|
|
|
2021-07-21 01:27:14 +08:00
|
|
|
|
private bool ServerSide => _hasRemoteDataSourceAttribute ? RemoteDataSource : Total > _dataSourceCount;
|
|
|
|
|
|
2020-11-09 22:17:27 +08:00
|
|
|
|
bool ITable.TreeMode => _treeMode;
|
|
|
|
|
int ITable.IndentSize => IndentSize;
|
2021-01-09 23:57:31 +08:00
|
|
|
|
string ITable.ScrollX => ScrollX;
|
|
|
|
|
string ITable.ScrollY => ScrollY;
|
|
|
|
|
int ITable.ScrollBarWidth => ScrollBarWidth;
|
2021-04-01 12:50:30 +08:00
|
|
|
|
int ITable.ExpandIconColumnIndex => ExpandIconColumnIndex + (_selection != null && _selection.ColIndex <= ExpandIconColumnIndex ? 1 : 0);
|
2021-01-21 14:56:20 +08:00
|
|
|
|
int ITable.TreeExpandIconColumnIndex => _treeExpandIconColumnIndex;
|
|
|
|
|
bool ITable.HasExpandTemplate => ExpandTemplate != null;
|
2021-03-05 23:58:38 +08:00
|
|
|
|
|
2021-01-24 13:52:57 +08:00
|
|
|
|
SortDirection[] ITable.SortDirections => SortDirections;
|
2021-01-09 23:57:31 +08:00
|
|
|
|
|
2021-03-05 23:58:38 +08:00
|
|
|
|
void ITable.OnExpandChange(int cacheKey)
|
|
|
|
|
{
|
|
|
|
|
if (OnExpand.HasDelegate && _dataSourceCache.TryGetValue(cacheKey, out var currentRowData))
|
|
|
|
|
{
|
|
|
|
|
OnExpand.InvokeAsync(currentRowData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 19:18:56 +08:00
|
|
|
|
void ITable.AddSummaryRow(SummaryRow summaryRow)
|
|
|
|
|
{
|
|
|
|
|
_summaryRows ??= new List<SummaryRow>();
|
|
|
|
|
_summaryRows.Add(summaryRow);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
public void ReloadData()
|
|
|
|
|
{
|
2020-07-10 17:57:20 +08:00
|
|
|
|
PageIndex = 1;
|
|
|
|
|
|
|
|
|
|
FlushCache();
|
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
this.Reload();
|
|
|
|
|
}
|
2020-06-19 23:06:33 +08:00
|
|
|
|
|
2021-03-04 20:49:54 +08:00
|
|
|
|
public QueryModel GetQueryModel() => BuildQueryModel();
|
|
|
|
|
|
|
|
|
|
private QueryModel<TItem> BuildQueryModel()
|
|
|
|
|
{
|
|
|
|
|
var queryModel = new QueryModel<TItem>(PageIndex, PageSize);
|
|
|
|
|
|
|
|
|
|
foreach (var col in ColumnContext.HeaderColumns)
|
|
|
|
|
{
|
|
|
|
|
if (col is IFieldColumn fieldColumn)
|
|
|
|
|
{
|
|
|
|
|
if (fieldColumn.SortModel != null)
|
|
|
|
|
{
|
|
|
|
|
queryModel.AddSortModel(fieldColumn.SortModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fieldColumn.FilterModel != null)
|
|
|
|
|
{
|
|
|
|
|
queryModel.AddFilterModel(fieldColumn.FilterModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return queryModel;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
void ITable.Refresh()
|
2020-06-19 23:06:33 +08:00
|
|
|
|
{
|
2020-11-09 22:17:27 +08:00
|
|
|
|
_shouldRender = true;
|
2020-07-08 16:12:49 +08:00
|
|
|
|
StateHasChanged();
|
2020-06-19 23:06:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
void ITable.ReloadAndInvokeChange()
|
2020-06-19 23:06:33 +08:00
|
|
|
|
{
|
2020-07-08 16:12:49 +08:00
|
|
|
|
ReloadAndInvokeChange();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-24 13:52:57 +08:00
|
|
|
|
void ITable.ColumnSorterChange(IFieldColumn column)
|
|
|
|
|
{
|
|
|
|
|
foreach (var col in ColumnContext.HeaderColumns)
|
|
|
|
|
{
|
2021-02-01 23:17:54 +08:00
|
|
|
|
if (col.ColIndex != column.ColIndex && col is IFieldColumn fieldCol && fieldCol.SorterMultiple <= 0 && fieldCol.Sortable)
|
2021-01-24 13:52:57 +08:00
|
|
|
|
{
|
|
|
|
|
fieldCol.ClearSorter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReloadAndInvokeChange();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
private void ReloadAndInvokeChange()
|
|
|
|
|
{
|
|
|
|
|
var queryModel = this.Reload();
|
|
|
|
|
if (OnChange.HasDelegate)
|
2020-06-19 23:06:33 +08:00
|
|
|
|
{
|
2020-07-08 16:12:49 +08:00
|
|
|
|
OnChange.InvokeAsync(queryModel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private QueryModel<TItem> Reload()
|
|
|
|
|
{
|
2021-03-04 20:49:54 +08:00
|
|
|
|
var queryModel = BuildQueryModel();
|
2020-09-01 17:23:31 +08:00
|
|
|
|
|
2021-07-21 01:27:14 +08:00
|
|
|
|
if (ServerSide)
|
2020-07-08 16:12:49 +08:00
|
|
|
|
{
|
|
|
|
|
_showItems = _dataSource;
|
2021-07-21 01:27:14 +08:00
|
|
|
|
_total = Total;
|
2020-07-08 16:12:49 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-05 20:27:52 +08:00
|
|
|
|
if (_dataSource != null)
|
2020-06-19 23:06:33 +08:00
|
|
|
|
{
|
2020-09-05 20:27:52 +08:00
|
|
|
|
var query = _dataSource.AsQueryable();
|
2021-02-27 23:55:48 +08:00
|
|
|
|
foreach (var sort in queryModel.SortModel.OrderBy(x => x.Priority))
|
2020-09-05 20:27:52 +08:00
|
|
|
|
{
|
2021-01-24 13:52:57 +08:00
|
|
|
|
query = sort.SortList(query);
|
2020-09-05 20:27:52 +08:00
|
|
|
|
}
|
2020-05-30 01:46:41 +08:00
|
|
|
|
|
2021-02-27 23:55:48 +08:00
|
|
|
|
foreach (var filter in queryModel.FilterModel)
|
|
|
|
|
{
|
|
|
|
|
query = filter.FilterList(query);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 01:27:14 +08:00
|
|
|
|
_total = query.Count();
|
2021-06-15 16:13:06 +08:00
|
|
|
|
|
2020-09-05 20:27:52 +08:00
|
|
|
|
query = query.Skip((PageIndex - 1) * PageSize).Take(PageSize);
|
|
|
|
|
queryModel.SetQueryableLambda(query);
|
2020-07-08 16:12:49 +08:00
|
|
|
|
|
2020-09-05 20:27:52 +08:00
|
|
|
|
_showItems = query;
|
2021-07-21 01:27:14 +08:00
|
|
|
|
if (_total != Total)
|
2021-06-15 16:13:06 +08:00
|
|
|
|
{
|
|
|
|
|
if (TotalChanged.HasDelegate) TotalChanged.InvokeAsync(_total);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_showItems = Enumerable.Empty<TItem>();
|
2021-07-21 01:27:14 +08:00
|
|
|
|
_total = 0;
|
|
|
|
|
if (_total != Total)
|
2021-06-15 16:13:06 +08:00
|
|
|
|
{
|
|
|
|
|
if (TotalChanged.HasDelegate) TotalChanged.InvokeAsync(_total);
|
|
|
|
|
}
|
2020-09-05 20:27:52 +08:00
|
|
|
|
}
|
2020-06-19 23:06:33 +08:00
|
|
|
|
}
|
2020-06-05 16:06:23 +08:00
|
|
|
|
|
2021-03-02 00:46:03 +08:00
|
|
|
|
_treeMode = TreeChildren != null && (_showItems?.Any(x => TreeChildren(x)?.Any() == true) == true);
|
2021-01-21 14:56:20 +08:00
|
|
|
|
if (_treeMode)
|
|
|
|
|
{
|
2021-04-01 12:50:30 +08:00
|
|
|
|
_treeExpandIconColumnIndex = ExpandIconColumnIndex + (_selection != null && _selection.ColIndex <= ExpandIconColumnIndex ? 1 : 0);
|
2021-01-21 14:56:20 +08:00
|
|
|
|
}
|
2021-04-04 02:40:23 +08:00
|
|
|
|
_waitingReload = false;
|
2020-05-30 01:46:41 +08:00
|
|
|
|
StateHasChanged();
|
2020-07-08 16:12:49 +08:00
|
|
|
|
|
|
|
|
|
return queryModel;
|
2020-05-30 01:46:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
private void SetClass()
|
|
|
|
|
{
|
|
|
|
|
string prefixCls = "ant-table";
|
|
|
|
|
ClassMapper.Add(prefixCls)
|
|
|
|
|
.If($"{prefixCls}-fixed-header", () => ScrollY != null)
|
2020-06-29 15:52:28 +08:00
|
|
|
|
.If($"{prefixCls}-bordered", () => Bordered)
|
|
|
|
|
.If($"{prefixCls}-small", () => Size == TableSize.Small)
|
|
|
|
|
.If($"{prefixCls}-middle", () => Size == TableSize.Middle)
|
2021-01-09 23:57:31 +08:00
|
|
|
|
.If($"{prefixCls}-fixed-column {prefixCls}-scroll-horizontal", () => ScrollX != null)
|
|
|
|
|
.If($"{prefixCls}-has-fix-left", () => _hasFixLeft)
|
|
|
|
|
.If($"{prefixCls}-has-fix-right", () => _hasFixRight)
|
|
|
|
|
.If($"{prefixCls}-ping-left", () => _pingLeft)
|
|
|
|
|
.If($"{prefixCls}-ping-right", () => _pingRight)
|
2021-03-12 17:02:11 +08:00
|
|
|
|
.If($"{prefixCls}-rtl", () => RTL)
|
2020-06-19 23:06:33 +08:00
|
|
|
|
;
|
2021-03-12 17:02:11 +08:00
|
|
|
|
|
|
|
|
|
_wrapperClassMapper
|
|
|
|
|
.Add($"{prefixCls}-wrapper")
|
|
|
|
|
.If($"{prefixCls}-wrapper-rtl", () => RTL);
|
2020-06-19 23:06:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
2020-11-09 22:17:27 +08:00
|
|
|
|
if (RowTemplate != null)
|
|
|
|
|
{
|
|
|
|
|
ChildContent = RowTemplate;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
this.ColumnContext = new ColumnContext(this);
|
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
SetClass();
|
2020-07-10 17:57:20 +08:00
|
|
|
|
|
2021-02-22 11:29:56 +08:00
|
|
|
|
if (ScrollX != null || ScrollY != null)
|
|
|
|
|
{
|
|
|
|
|
TableLayout = "fixed";
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 17:57:20 +08:00
|
|
|
|
InitializePagination();
|
|
|
|
|
|
|
|
|
|
FlushCache();
|
2020-06-19 23:06:33 +08:00
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
ReloadAndInvokeChange();
|
2020-06-05 16:06:23 +08:00
|
|
|
|
}
|
2020-07-10 17:57:20 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
base.OnAfterRender(firstRender);
|
|
|
|
|
|
|
|
|
|
if (!firstRender)
|
|
|
|
|
{
|
|
|
|
|
this.FinishLoadPage();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-25 18:31:31 +08:00
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
|
|
|
|
|
|
|
|
if (firstRender)
|
|
|
|
|
{
|
2021-01-25 12:53:19 +08:00
|
|
|
|
DomEventService.AddEventListener("window", "beforeunload", Reloading, false);
|
2021-01-09 23:57:31 +08:00
|
|
|
|
if (ScrollX != null)
|
|
|
|
|
{
|
|
|
|
|
await SetScrollPositionClassName();
|
|
|
|
|
|
|
|
|
|
DomEventService.AddEventListener("window", "resize", OnResize, false);
|
|
|
|
|
DomEventService.AddEventListener(_tableBodyRef, "scroll", OnScroll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ScrollY != null && ScrollX != null)
|
|
|
|
|
{
|
|
|
|
|
await JsInvokeAsync(JSInteropConstants.BindTableHeaderAndBodyScroll, _tableBodyRef, _tableHeaderRef);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 18:31:31 +08:00
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
base.OnParametersSet();
|
|
|
|
|
|
2021-06-15 16:13:06 +08:00
|
|
|
|
if (_waitingReloadAndInvokeChange)
|
|
|
|
|
{
|
|
|
|
|
_waitingReloadAndInvokeChange = false;
|
|
|
|
|
_waitingReload = false;
|
|
|
|
|
|
|
|
|
|
ReloadAndInvokeChange();
|
|
|
|
|
}
|
|
|
|
|
else if (_waitingReload)
|
|
|
|
|
{
|
|
|
|
|
_waitingReload = false;
|
|
|
|
|
Reload();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 18:31:31 +08:00
|
|
|
|
if (this.RenderMode == RenderMode.ParametersHashCodeChanged)
|
|
|
|
|
{
|
|
|
|
|
var hashCode = this.GetParametersHashCode();
|
|
|
|
|
this._shouldRender = this._parametersHashCode != hashCode;
|
|
|
|
|
this._parametersHashCode = hashCode;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this._shouldRender = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 02:40:23 +08:00
|
|
|
|
protected override bool ShouldRender()
|
|
|
|
|
{
|
|
|
|
|
return this._shouldRender;
|
|
|
|
|
}
|
2020-11-08 23:29:05 +08:00
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
void ITable.HasFixLeft() => _hasFixLeft = true;
|
|
|
|
|
|
|
|
|
|
void ITable.HasFixRight() => _hasFixRight = true;
|
|
|
|
|
|
2021-04-17 18:52:15 +08:00
|
|
|
|
void ITable.TableLayoutIsFixed()
|
|
|
|
|
{
|
|
|
|
|
TableLayout = "fixed";
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2021-01-10 21:44:25 +08:00
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
private async void OnResize(JsonElement _) => await SetScrollPositionClassName();
|
|
|
|
|
|
|
|
|
|
private async void OnScroll(JsonElement _) => await SetScrollPositionClassName();
|
|
|
|
|
|
|
|
|
|
private async Task SetScrollPositionClassName(bool clear = false)
|
|
|
|
|
{
|
2021-02-01 23:42:54 +08:00
|
|
|
|
if (_isReloading)
|
2021-01-25 12:53:19 +08:00
|
|
|
|
return;
|
2021-02-01 23:42:54 +08:00
|
|
|
|
|
2021-04-17 22:14:01 +08:00
|
|
|
|
var element = await JsInvokeAsync<HtmlElement>(JSInteropConstants.GetDomInfo, _tableBodyRef);
|
|
|
|
|
var scrollWidth = element.ScrollWidth;
|
|
|
|
|
var scrollLeft = element.ScrollLeft;
|
|
|
|
|
var clientWidth = element.ClientWidth;
|
2021-01-09 23:57:31 +08:00
|
|
|
|
|
|
|
|
|
var beforePingLeft = _pingLeft;
|
|
|
|
|
var beforePingRight = _pingRight;
|
|
|
|
|
|
|
|
|
|
if ((scrollWidth == clientWidth && scrollWidth != 0) || clear)
|
|
|
|
|
{
|
|
|
|
|
_pingLeft = false;
|
|
|
|
|
_pingRight = false;
|
|
|
|
|
}
|
|
|
|
|
else if (scrollLeft == 0)
|
|
|
|
|
{
|
|
|
|
|
_pingLeft = false;
|
|
|
|
|
_pingRight = true;
|
|
|
|
|
}
|
2021-02-01 23:42:54 +08:00
|
|
|
|
// allow the gap between 1 px, it's magic ✨
|
|
|
|
|
else if (Math.Abs(scrollWidth - (scrollLeft + clientWidth)) < 1)
|
2021-01-09 23:57:31 +08:00
|
|
|
|
{
|
|
|
|
|
_pingRight = false;
|
|
|
|
|
_pingLeft = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_pingLeft = true;
|
|
|
|
|
_pingRight = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-04 21:02:47 +08:00
|
|
|
|
if (beforePingLeft != _pingLeft || beforePingRight != _pingRight)
|
|
|
|
|
{
|
|
|
|
|
_shouldRender = true;
|
|
|
|
|
}
|
2021-04-17 18:52:15 +08:00
|
|
|
|
|
2021-01-09 23:57:31 +08:00
|
|
|
|
if (!clear)
|
|
|
|
|
{
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>("window", "resize", OnResize);
|
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>(_tableBodyRef, "scroll", OnScroll);
|
2021-02-01 23:42:54 +08:00
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>("window", "beforeunload", Reloading);
|
2021-01-09 23:57:31 +08:00
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async ValueTask DisposeAsync()
|
|
|
|
|
{
|
2021-01-25 12:53:19 +08:00
|
|
|
|
if (!_isReloading)
|
2021-01-09 23:57:31 +08:00
|
|
|
|
{
|
2021-01-25 12:53:19 +08:00
|
|
|
|
if (ScrollY != null && ScrollX != null)
|
|
|
|
|
{
|
|
|
|
|
await JsInvokeAsync(JSInteropConstants.UnbindTableHeaderAndBodyScroll, _tableBodyRef);
|
|
|
|
|
}
|
2021-01-09 23:57:31 +08:00
|
|
|
|
}
|
2021-01-25 12:53:19 +08:00
|
|
|
|
DomEventService.RemoveEventListerner<JsonElement>("window", "beforeunload", Reloading);
|
2021-01-09 23:57:31 +08:00
|
|
|
|
}
|
2021-01-21 14:56:20 +08:00
|
|
|
|
|
|
|
|
|
bool ITable.RowExpandable(RowData rowData)
|
|
|
|
|
{
|
|
|
|
|
return RowExpandable(rowData as RowData<TItem>);
|
|
|
|
|
}
|
2021-01-25 12:53:19 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-02-01 23:42:54 +08:00
|
|
|
|
/// Indicates that a page is being refreshed
|
2021-01-25 12:53:19 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
private bool _isReloading;
|
2021-02-01 23:42:54 +08:00
|
|
|
|
|
2021-01-25 12:53:19 +08:00
|
|
|
|
private void Reloading(JsonElement jsonElement)
|
|
|
|
|
{
|
|
|
|
|
_isReloading = true;
|
|
|
|
|
}
|
2020-05-30 01:46:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|