Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<TableColumn @bind-Field="@context.DateTime" Width="120" FormatString="yyyy-MM-dd" Align="Alignment.Center" />
<TableColumn @bind-Field="@context.Name" Width="100" />
<TableColumn @bind-Field="@context.Address" />
<TableColumn @bind-Field="@context.Count" Formatter="@IntFormatter" Width="60" Align="Alignment.Right" />
<TableColumn @bind-Field="@context.Count" Width="60" Align="Alignment.Right" />
</TableColumns>
</Table>
</DemoBlock>
Expand All @@ -165,7 +165,7 @@
<TableColumn @bind-Field="@context.DateTime" Width="120" FormatString="yyyy-MM-dd" />
<TableColumn @bind-Field="@context.Name" Width="100" />
<TableColumn @bind-Field="@context.Address" />
<TableColumn @bind-Field="@context.Count" Formatter="@IntFormatter" />
<TableColumn @bind-Field="@context.Count" FormatString="0.00" />
</TableColumns>
</Table>
</DemoBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@ protected override void OnInitialized()

private static bool ShowCheckbox(Foo foo) => foo.Complete;

/// <summary>
/// IntFormatter
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
private static Task<string> IntFormatter(object? d)
{
var ret = "";
if (d is TableColumnContext<Foo, object?> data && data.Value != null)
{
var val = (int)data.Value;
ret = val.ToString("0.00");
}
return Task.FromResult(ret);
}

private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
{
IEnumerable<Foo> items = Items;
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/Locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -5036,7 +5036,7 @@
"FormatterTitle": "Custom column data format",
"FormatterIntro": "Format the cell value by specifying the <code>FormatString</code> or <code>Formatter</code> callback delegate when the column is bound",
"FormatterP1": "In this example the column <code>DateTime</code> values ​​are formatted according to <code>FormatString</code> to <code>yyyy-MM-dd</code> year month day format",
"FormatterP2": "In this example the column <code>Count</code> value is formatted according to <code>Formatter</code> to <code>0.00</code> with two decimal places",
"FormatterP2": "In this example the column <code>Count</code> value is formatted according to <code>FormatString</code> to <code>0.00</code> with two decimal places",
"AlignTitle": "Column data alignment",
"AlignIntro": "Set the alignment by specifying the <code>Align</code> attribute when the column is bound",
"AlignP1": "In this example the column <code>DateTime</code> is set to center alignment <code>Alignment.Center</code>",
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor.Server/Locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -5034,9 +5034,9 @@
"DisabledTitle": "选择框列",
"DisabledIntro": "<code>RowTemplate</code> 内部组件 <code>TableCell</code> 设置 <code>Checkbox</code> 并设置相关数据绑定即可,本示例中通过数据绑定将选择框组件与值进行绑定",
"FormatterTitle": "自定义列数据格式",
"FormatterIntro": "列绑定时通过指定 <code>FormatString</code> 或者 <code>Formatter</code> 回调委托来实现单元格数值格式化",
"FormatterIntro": "列绑定时通过指定 <code>FormatString</code> 实现单元格数值格式化。<b>注意</b> 列属性 <code>Formatter</code> 回调方法不支持,仅当列渲染为 <code>Display<code> 时生效",
"FormatterP1": "本例中列 <code>DateTime</code> 值根据 <code>FormatString</code> 将值格式化为 <code>yyyy-MM-dd</code> 年月日格式",
"FormatterP2": "本例中列 <code>Count</code> 值根据 <code>Formatter</code> 将值格式化为 <code>0.00</code> 保留两位小数格式",
"FormatterP2": "本例中列 <code>Count</code> 值根据 <code>FormatString</code> 将值格式化为 <code>0.00</code> 保留两位小数格式",
"AlignTitle": "列数据对齐方式",
"AlignIntro": "列绑定时通过指定 <code>Align</code> 属性设置对齐方式",
"AlignP1": "本例中列 <code>DateTime</code> 列设置为居中对齐 <code>Alignment.Center</code>",
Expand Down
9 changes: 2 additions & 7 deletions src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static List<IFilterAction> ToSearches(this IEnumerable<ITableColumn> colu
return searches;
}

internal static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem item) => async builder =>
internal static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem item) => builder =>
{
var val = col.GetItemValue(item);
if (col.Lookup != null && val != null)
Expand All @@ -191,12 +191,7 @@ internal static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem i
else
{
string? content;
if (col.Formatter != null)
{
// 格式化回调委托
content = await col.Formatter(new TableColumnContext<TItem, object?>(item, val));
}
else if (!string.IsNullOrEmpty(col.FormatString))
if (!string.IsNullOrEmpty(col.FormatString))
{
// 格式化字符串
content = Utility.Format(val, col.FormatString);
Expand Down
Loading