diff --git a/src/BootstrapBlazor.Shared/Samples/Table/TablesFooter.razor b/src/BootstrapBlazor.Shared/Samples/Table/TablesFooter.razor index 70b025218..b183115d7 100644 --- a/src/BootstrapBlazor.Shared/Samples/Table/TablesFooter.razor +++ b/src/BootstrapBlazor.Shared/Samples/Table/TablesFooter.razor @@ -60,11 +60,11 @@ diff --git a/src/BootstrapBlazor.Shared/Samples/Table/TablesFooter.razor.cs b/src/BootstrapBlazor.Shared/Samples/Table/TablesFooter.razor.cs index bbd6f94aa..578dfbd63 100644 --- a/src/BootstrapBlazor.Shared/Samples/Table/TablesFooter.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Table/TablesFooter.razor.cs @@ -73,4 +73,8 @@ public sealed partial class TablesFooter IsSearch = true }); } + + private static double GetAverage(IEnumerable items) => items.Any() ? items.Average(i => i.Count) : 0; + + private static int GetSum(IEnumerable items) => items.Any() ? items.Sum(i => i.Count) : 0; } diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 289dc7be7..48c26d66f 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 6.2.0 + 6.2.1 diff --git a/src/BootstrapBlazor/Components/Empty/Empty.razor b/src/BootstrapBlazor/Components/Empty/Empty.razor index 6700581a2..0802c6718 100644 --- a/src/BootstrapBlazor/Components/Empty/Empty.razor +++ b/src/BootstrapBlazor/Components/Empty/Empty.razor @@ -2,23 +2,26 @@ @inherits BootstrapComponentBase
- @if (!string.IsNullOrEmpty(Image)) - { -
- -
- } - @if (!string.IsNullOrEmpty(Text)) - { -
- @Text -
- } @if (Template != null) {
@Template
} - @ChildContent + else + { + @if (!string.IsNullOrEmpty(Image)) + { +
+ +
+ } + @if (!string.IsNullOrEmpty(Text)) + { +
+ @Text +
+ } + @ChildContent + }
diff --git a/src/BootstrapBlazor/Components/Table/Table.razor b/src/BootstrapBlazor/Components/Table/Table.razor index 00194e9d7..a917ad80f 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor +++ b/src/BootstrapBlazor/Components/Table/Table.razor @@ -335,7 +335,7 @@ { - + diff --git a/src/BootstrapBlazor/Components/Table/TableFooterCell.razor.cs b/src/BootstrapBlazor/Components/Table/TableFooterCell.razor.cs index 01e2c8eec..2aa5fa5bb 100644 --- a/src/BootstrapBlazor/Components/Table/TableFooterCell.razor.cs +++ b/src/BootstrapBlazor/Components/Table/TableFooterCell.razor.cs @@ -59,7 +59,7 @@ public partial class TableFooterCell [CascadingParameter(Name = "TableFooterContext")] private object? DataSource { get; set; } - private string? GetText() => Text ?? GetCountValue() ?? GetAggegateValue(); + private string? GetText() => Text ?? (GetCount(DataSource) == 0 ? "0" : (GetCountValue() ?? GetAggegateValue())); /// /// 解析 Count Aggregate @@ -209,5 +209,28 @@ public partial class TableFooterCell return mi?.MakeGenericMethod(modelType); } - private static int CreateCountMethod(IEnumerable source) => Enumerable.Count(source); + private static int CreateCountMethod(IEnumerable source) => source.Count(); + + private static int GetCount(object? source) + { + var ret = 0; + if (source != null) + { + // 绑定数据源类型 + var type = source.GetType(); + + // 数据源泛型 TModel 类型 + var modelType = type.GenericTypeArguments[0]; + + var mi = typeof(TableFooterCell).GetMethod(nameof(CreateCountMethod), BindingFlags.NonPublic | BindingFlags.Static) + ?.MakeGenericMethod(modelType); + + if (mi != null) + { + var v = mi.Invoke(null, new object[] { source })?.ToString(); + _ = int.TryParse(v, out ret); + } + } + return ret; + } }