-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 (DataTable): ItemColContent and CellRender cannot be used together
- Loading branch information
Showing
2 changed files
with
37 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
namespace Masa.Blazor; | ||
|
||
public class ItemColProps<TItem> | ||
public class ItemColProps<TItem>(DataTableHeader<TItem> header, TItem item) | ||
{ | ||
public DataTableHeader<TItem> Header { get; set; } | ||
public DataTableHeader<TItem> Header { get; } = header; | ||
|
||
public object? Value => Header.ItemValue.Invoke(Item); | ||
public TItem Item { get; } = item; | ||
|
||
public TItem Item { get; set; } | ||
|
||
public ItemColProps(DataTableHeader<TItem> header, TItem item) | ||
/// <summary> | ||
/// The value of current cell. | ||
/// It's recommended to use <see cref="ValueContent"/> | ||
/// to render cell content as it has better compatibility. | ||
/// </summary> | ||
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); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The render fragment of current cell. | ||
/// </summary> | ||
public RenderFragment ValueContent | ||
=> Value as RenderFragment ?? (RenderFragment)(builder => builder.AddContent(0, Value)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters