LANCommander/LANCommander.Server/UI/Components/DataTable/DataColumn.cs

48 lines
1.4 KiB
C#
Raw Normal View History

2024-12-12 17:35:52 -06:00
using AntDesign.TableModels;
using Microsoft.AspNetCore.Components;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
using System.Reflection;
namespace LANCommander.Server.UI.Components
{
public class DataColumn<TData> : AntDesign.Column<TData>
{
2025-01-16 00:35:01 -06:00
[Parameter]
public string Include { get; set; } = default!;
2025-01-28 00:46:37 -06:00
[Parameter]
public bool Hide { get; set; }
2025-01-16 00:35:01 -06:00
2024-12-12 17:35:52 -06:00
[CascadingParameter]
public Dictionary<int, bool> ColumnVisibility { get; set; } = default!;
2025-01-16 00:35:01 -06:00
[CascadingParameter]
public List<string> Includes { get; set; } = default!;
2024-12-12 17:35:52 -06:00
protected override void OnParametersSet()
{
2025-01-28 00:46:37 -06:00
if (!ColumnVisibility.ContainsKey(ColIndex))
ColumnVisibility.Add(ColIndex, !Hide);
2024-12-14 20:11:59 -06:00
ClassMapper.If("column-hidden", () => ColumnVisibility.ContainsKey(ColIndex) && !ColumnVisibility[ColIndex]);
2024-12-14 20:11:59 -06:00
StateHasChanged();
2024-12-12 17:35:52 -06:00
if (!String.IsNullOrWhiteSpace(Include))
2025-01-16 00:35:01 -06:00
{
var includes = Include.Split(',');
foreach (var include in includes)
{
if (!String.IsNullOrWhiteSpace(include) && !Includes.Contains(include))
Includes.Add(include);
}
2025-01-16 00:35:01 -06:00
}
2024-12-12 17:35:52 -06:00
base.OnParametersSet();
}
}
}