Skip to content

Commit 4a57e83

Browse files
committed
refactor: Tooltip 支持异步 Lookup
1 parent 5232b64 commit 4a57e83

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ protected RenderFragment GetValue(ITableColumn col, TItem item) => builder =>
12961296
}
12971297
else
12981298
{
1299-
builder.AddContent(20, col.RenderValue(item));
1299+
builder.AddContent(20, col.RenderValue(item, LookupService));
13001300
}
13011301
};
13021302
#endregion

src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,20 @@ public static List<IFilterAction> ToSearches(this IEnumerable<ITableColumn> colu
172172
return searches;
173173
}
174174

175-
internal static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem item) => builder =>
175+
/// <summary>
176+
/// 当前单元格方法
177+
/// </summary>
178+
/// <typeparam name="TItem"></typeparam>
179+
/// <param name="col"></param>
180+
/// <param name="item"></param>
181+
/// <param name="lookupService"></param>
182+
/// <returns></returns>
183+
public static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem item, ILookupService lookupService) => builder =>
176184
{
177185
var val = col.GetItemValue(item);
178186
if (col.IsLookup() && val != null)
179187
{
180-
builder.AddContent(10, col.RenderTooltip(val.ToString(), item));
188+
builder.AddContent(10, col.RenderTooltip(val.ToString(), item, lookupService));
181189
}
182190
else if (val is bool v1)
183191
{
@@ -213,7 +221,7 @@ internal static RenderFragment RenderValue<TItem>(this ITableColumn col, TItem i
213221
{
214222
content = val?.ToString();
215223
}
216-
builder.AddContent(30, col.RenderTooltip(content, item));
224+
builder.AddContent(30, col.RenderTooltip(content, item, lookupService));
217225
}
218226
}
219227
};
@@ -238,7 +246,7 @@ internal static RenderFragment RenderColor<TItem>(this ITableColumn col, TItem i
238246
builder.CloseElement();
239247
};
240248

241-
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item) => pb =>
249+
private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string? text, TItem item, ILookupService lookupService) => pb =>
242250
{
243251
if (col.GetShowTips())
244252
{
@@ -249,9 +257,13 @@ private static RenderFragment RenderTooltip<TItem>(this ITableColumn col, string
249257
{
250258
pb.AddAttribute(10, nameof(Tooltip.GetTitleCallback), new Func<Task<string?>>(() => col.GetTooltipTextCallback(item)));
251259
}
252-
else if(col.IsLookup())
260+
else if (col.IsLookup())
253261
{
254-
262+
pb.AddAttribute(10, nameof(Tooltip.GetTitleCallback), new Func<Task<string?>>(async () =>
263+
{
264+
var lookup = await col.GetLookupService(lookupService).GetItemsAsync(col.LookupServiceKey, col.LookupServiceData);
265+
return lookup?.FirstOrDefault(l => l.Value.Equals(text, col.LookupStringComparison))?.Text ?? text;
266+
}));
255267
}
256268
else
257269
{

0 commit comments

Comments
 (0)