diff --git a/src/Masa.Blazor/Components/DataTable/Row/ItemColProps.cs b/src/Masa.Blazor/Components/DataTable/Row/ItemColProps.cs index 075471fa7b..99698d55c3 100644 --- a/src/Masa.Blazor/Components/DataTable/Row/ItemColProps.cs +++ b/src/Masa.Blazor/Components/DataTable/Row/ItemColProps.cs @@ -1,16 +1,38 @@ namespace Masa.Blazor; -public class ItemColProps +public class ItemColProps(DataTableHeader header, TItem item) { - public DataTableHeader Header { get; set; } + public DataTableHeader Header { get; } = header; - public object? Value => Header.ItemValue.Invoke(Item); + public TItem Item { get; } = item; - public TItem Item { get; set; } - - public ItemColProps(DataTableHeader header, TItem item) + /// + /// The value of current cell. + /// It's recommended to use + /// to render cell content as it has better compatibility. + /// + public object? Value { - Header = header; - Item = item; + get + { + if (Header.CellRender is not null) + { + var render = Header.CellRender.Invoke(Item); + if (render.IsT0) + { + return render.AsT0; + } + + return render.AsT1; + } + + return Header.ItemValue.Invoke(Item); + } } + + /// + /// The render fragment of current cell. + /// + public RenderFragment ValueContent + => Value as RenderFragment ?? (RenderFragment)(builder => builder.AddContent(0, Value)); } \ No newline at end of file diff --git a/src/Masa.Blazor/Components/DataTable/Row/MDataTableRow.razor b/src/Masa.Blazor/Components/DataTable/Row/MDataTableRow.razor index a97d4f1379..c079398dbd 100644 --- a/src/Masa.Blazor/Components/DataTable/Row/MDataTableRow.razor +++ b/src/Masa.Blazor/Components/DataTable/Row/MDataTableRow.razor @@ -11,27 +11,13 @@ - @{ - if (HasSlot(props)) - { - @SlotContent(props) - } - else if (header.CellRender is not null) - { - var cell = header.CellRender(Item); - if (cell.IsT0) - { - @cell.AsT0 - } - else - { - @cell.AsT1 - } - } - else - { - @props.Value - } + @if (HasSlot(props)) + { + @SlotContent(props) + } + else + { + @props.ValueContent } }