using Microsoft.AspNetCore.Components; using MudBlazor; namespace Lantean.QBTMud.Models { public class ColumnDefinition { public ColumnDefinition(string header, Func sortSelector, Func? formatter = null, string? tdClass = null, int? width = null) { Header = header; SortSelector = sortSelector; Formatter = formatter; Class = tdClass; Width = width; RowTemplate = (context) => (builder) => builder.AddContent(1, context.GetValue()); } public ColumnDefinition(string header, Func sortSelector, RenderFragment> rowTemplate, Func? formatter = null, string? tdClass = null, int? width = null) { Header = header; SortSelector = sortSelector; RowTemplate = rowTemplate; Formatter = formatter; Class = tdClass; Width = width; } public string Id => Header.ToLowerInvariant().Replace(' ', '_'); public string Header { get; set; } public Func SortSelector { get; set; } public RenderFragment> RowTemplate { get; set; } public bool IconOnly { get; set; } public int? Width { get; set; } public Func? Formatter { get; set; } public string? Class { get; set; } public Func? ClassFunc { get; set; } public bool Enabled { get; set; } = true; public SortDirection InitialDirection { get; set; } = SortDirection.None; public RowContext GetRowContext(T data) { return new RowContext(Header, data, Formatter is null ? SortSelector : Formatter); } } }