2020-05-30 01:46:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq.Expressions;
|
2020-09-01 17:23:31 +08:00
|
|
|
|
using AntDesign.Core.Reflection;
|
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
|
|
|
|
|
{
|
2020-06-19 23:06:33 +08:00
|
|
|
|
public partial class Column<TData> : ColumnBase, IFieldColumn
|
2020-05-30 01:46:41 +08:00
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
2020-06-05 16:06:23 +08:00
|
|
|
|
public EventCallback<TData> FieldChanged { get; set; }
|
2020-05-30 01:46:41 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-06-05 16:06:23 +08:00
|
|
|
|
public Expression<Func<TData>> FieldExpression { get; set; }
|
2020-05-30 01:46:41 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-06-05 16:06:23 +08:00
|
|
|
|
public RenderFragment<TData> CellRender { get; set; }
|
2020-06-02 19:15:15 +08:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
2020-06-19 23:06:33 +08:00
|
|
|
|
public TData Field { get; set; }
|
2020-05-30 01:46:41 +08:00
|
|
|
|
|
2020-07-05 00:09:53 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string Format { get; set; }
|
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public bool Sortable { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Sort { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public bool ShowSorterTooltip { get; set; } = true;
|
|
|
|
|
|
2020-09-01 17:23:31 +08:00
|
|
|
|
private PropertyReflector? _propertyReflector;
|
2020-05-30 01:46:41 +08:00
|
|
|
|
|
2020-09-01 17:23:31 +08:00
|
|
|
|
public string DisplayName => _propertyReflector?.DisplayName;
|
2020-05-30 01:46:41 +08:00
|
|
|
|
|
2020-09-01 17:23:31 +08:00
|
|
|
|
public string FieldName => _propertyReflector?.PropertyName;
|
2020-05-30 01:46:41 +08:00
|
|
|
|
|
2020-07-08 16:12:49 +08:00
|
|
|
|
public ITableSortModel SortModel { get; private set; }
|
|
|
|
|
|
2020-05-30 01:46:41 +08:00
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
2020-06-19 23:06:33 +08:00
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
2020-05-30 01:46:41 +08:00
|
|
|
|
if (FieldExpression != null)
|
|
|
|
|
{
|
2020-09-01 17:23:31 +08:00
|
|
|
|
_propertyReflector = PropertyReflector.Create(FieldExpression);
|
2020-07-08 16:12:49 +08:00
|
|
|
|
if (Sortable)
|
|
|
|
|
{
|
2020-09-01 17:23:31 +08:00
|
|
|
|
SortModel = new SortModel<TData>(_propertyReflector.Value.PropertyInfo, 1, Sort);
|
2020-07-08 16:12:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClassMapper
|
|
|
|
|
.If("ant-table-column-has-sorters", () => Sortable)
|
|
|
|
|
.If($"ant-table-column-sort", () => Sortable && SortModel.SortType.IsIn(SortType.Ascending, SortType.Descending));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandelHeaderClick()
|
|
|
|
|
{
|
|
|
|
|
if (Sortable)
|
|
|
|
|
{
|
|
|
|
|
SortModel.SwitchSortType();
|
|
|
|
|
Table.ReloadAndInvokeChange();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string SorterTooltip
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var next = SortModel.NextType();
|
|
|
|
|
if (next == SortType.None)
|
|
|
|
|
{
|
2020-09-07 22:46:50 +08:00
|
|
|
|
return Table.Locale.CancelSort;
|
2020-07-08 16:12:49 +08:00
|
|
|
|
}
|
|
|
|
|
else if (next == SortType.Ascending)
|
|
|
|
|
{
|
2020-09-07 22:46:50 +08:00
|
|
|
|
return Table.Locale.TriggerAsc;
|
2020-07-08 16:12:49 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-07 22:46:50 +08:00
|
|
|
|
return Table.Locale.TriggerDesc;
|
2020-07-08 16:12:49 +08:00
|
|
|
|
}
|
2020-05-30 01:46:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-09 22:17:27 +08:00
|
|
|
|
|
|
|
|
|
private void ToggleTreeNode()
|
|
|
|
|
{
|
|
|
|
|
RowData.Expanded = !RowData.Expanded;
|
|
|
|
|
Table?.Refresh();
|
|
|
|
|
}
|
2020-05-30 01:46:41 +08:00
|
|
|
|
}
|
2020-06-05 16:06:23 +08:00
|
|
|
|
}
|