2020-06-05 16:06:23 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-09-22 22:07:56 +08:00
|
|
|
|
using AntDesign.Internal;
|
2022-01-18 10:06:29 +08:00
|
|
|
|
using AntDesign.TableModels;
|
2020-06-05 16:06:23 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
2020-06-19 23:06:33 +08:00
|
|
|
|
public partial class Selection : ColumnBase, ISelectionColumn
|
2020-06-05 16:06:23 +08:00
|
|
|
|
{
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[Parameter] public string Type { get; set; } = "checkbox";
|
2020-06-05 16:06:23 +08:00
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[Parameter] public bool Disabled { get; set; }
|
2020-06-05 16:06:23 +08:00
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
[Parameter] public string Key { get; set; }
|
2020-06-05 16:06:23 +08:00
|
|
|
|
|
2020-11-09 22:17:27 +08:00
|
|
|
|
[Parameter] public bool CheckStrictly { get; set; }
|
|
|
|
|
|
2022-03-09 12:18:55 +08:00
|
|
|
|
[Parameter]
|
|
|
|
|
public virtual RenderFragment<CellData> CellRender { get; set; }
|
|
|
|
|
|
2022-01-10 15:55:00 +08:00
|
|
|
|
//private bool _checked;
|
2020-06-05 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
private bool Indeterminate => IsHeader
|
2022-01-10 15:55:00 +08:00
|
|
|
|
&& !Table.AllSelected
|
|
|
|
|
&& Table.AnySelected;
|
2020-06-05 16:06:23 +08:00
|
|
|
|
|
2020-06-19 23:06:33 +08:00
|
|
|
|
public IList<ISelectionColumn> RowSelections { get; set; } = new List<ISelectionColumn>();
|
2020-06-05 16:06:23 +08:00
|
|
|
|
|
2021-09-22 22:07:56 +08:00
|
|
|
|
//private int[] _selectedIndexes;
|
2020-07-10 17:57:20 +08:00
|
|
|
|
|
2022-09-24 13:13:07 +08:00
|
|
|
|
private bool IsHeaderDisabled => RowSelections.All(x => x.Disabled);
|
|
|
|
|
|
2022-09-22 11:51:40 +08:00
|
|
|
|
private void OnCheckedChange(bool selected)
|
2022-01-10 15:55:00 +08:00
|
|
|
|
{
|
|
|
|
|
if (IsHeader)
|
|
|
|
|
{
|
|
|
|
|
if (selected)
|
|
|
|
|
{
|
|
|
|
|
Table.SelectAll();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Table.UnselectAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (IsBody)
|
|
|
|
|
{
|
|
|
|
|
if (Type == "radio")
|
|
|
|
|
{
|
|
|
|
|
Table.SetSelection(new[] { Key });
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RowData.Selected = selected;
|
|
|
|
|
Table.Selection.StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 16:06:23 +08:00
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
2020-06-19 23:06:33 +08:00
|
|
|
|
base.OnInitialized();
|
|
|
|
|
|
2020-07-10 17:57:20 +08:00
|
|
|
|
if (Table == null)
|
2020-06-05 16:06:23 +08:00
|
|
|
|
{
|
2020-07-10 17:57:20 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IsHeader)
|
|
|
|
|
{
|
|
|
|
|
Table.Selection = this;
|
2021-08-28 14:10:39 +08:00
|
|
|
|
Context.HeaderColumnInitialed(this);
|
2020-07-10 17:57:20 +08:00
|
|
|
|
}
|
2021-01-22 09:56:51 +08:00
|
|
|
|
else if (IsBody)
|
2020-07-10 17:57:20 +08:00
|
|
|
|
{
|
|
|
|
|
Table?.Selection?.RowSelections.Add(this);
|
2020-06-05 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
base.OnParametersSet();
|
2021-06-15 18:22:07 +08:00
|
|
|
|
//if (IsHeader && Type == "radio" && RowSelections.Count(x => x.Checked) > 1)
|
|
|
|
|
//{
|
|
|
|
|
// var first = RowSelections.FirstOrDefault(x => x.Checked);
|
|
|
|
|
// if (first != null)
|
|
|
|
|
// {
|
|
|
|
|
// Table?.Selection.RowSelections.Where(x => x.ColIndex != first.ColIndex).ForEach(x => x.RowData.SetSelected(false));
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2020-06-05 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 17:57:20 +08:00
|
|
|
|
void ISelectionColumn.StateHasChanged()
|
2020-06-05 16:06:23 +08:00
|
|
|
|
{
|
2021-09-22 22:07:56 +08:00
|
|
|
|
if (IsHeader && Type == "checkbox")
|
2020-06-05 16:06:23 +08:00
|
|
|
|
{
|
2020-07-10 17:57:20 +08:00
|
|
|
|
StateHasChanged();
|
2020-06-05 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-01 23:45:48 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!IsHeader)
|
|
|
|
|
{
|
2023-01-19 12:03:34 +08:00
|
|
|
|
Table?.Selection?.RowSelections?.Remove(this);
|
2020-08-01 23:45:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
}
|
2020-06-05 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|