diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesExport.razor b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesExport.razor index 85c9537248ae6dd44ad02bc101654eea53d732d7..c9521718a175b8b9b57713e113be994113109014 100644 --- a/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesExport.razor +++ b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesExport.razor @@ -1,8 +1,4 @@ @page "/tables/export" -@inherits TablesBaseEdit -@using Microsoft.Extensions.DependencyInjection -@using Foo = BootstrapBlazor.Shared.Pages.Components.Foo -@inject NugetVersionService VersionManager

Table 表格

@@ -72,24 +68,3 @@ - -@code{ - public Task ExportAsync(IEnumerable Items) - { - return Task.FromResult(true); - } - - /// - /// 获得/设置 版本号字符串 - /// - private string Version { get; set; } = "fetching"; - - /// - /// OnInitializedAsync 方法 - /// - /// - protected override async Task OnInitializedAsync() - { - Version = await VersionManager.GetVersionAsync("bootstrapblazor.tableexport"); - } -} diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesExport.razor.cs b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesExport.razor.cs new file mode 100644 index 0000000000000000000000000000000000000000..ece594a0748efc56b0d84270c3ba0aa44aa2a0d9 --- /dev/null +++ b/src/BootstrapBlazor.Shared/Pages/Samples/Table/TablesExport.razor.cs @@ -0,0 +1,82 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using BootstrapBlazor.Components; +using BootstrapBlazor.Shared.Pages.Components; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Threading.Tasks; + +namespace BootstrapBlazor.Shared.Pages.Table +{ + /// + /// Table 组件数据导出示例 + /// + public partial class TablesExport + { + private static readonly ConcurrentDictionary, string, SortOrder, IEnumerable>> SortLambdaCache = new(); + + /// + /// 获得/设置 版本号字符串 + /// + private string Version { get; set; } = "fetching"; + + private static IEnumerable PageItemsSource => new int[] { 4, 10, 20 }; + + [NotNull] + private List? Items { get; set; } + + [Inject] + [NotNull] + private IStringLocalizer? Localizer { get; set; } + + [Inject] + [NotNull] + private NugetVersionService? VersionManager { get; set; } + + /// + /// OnInitialized 方法 + /// + protected override void OnInitialized() + { + base.OnInitialized(); + + Items = Foo.GenerateFoo(Localizer); + } + + private Task> OnQueryAsync(QueryPageOptions options) + { + IEnumerable items = Items; + + // 设置记录总数 + var total = items.Count(); + + // 内存分页 + items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList(); + + return Task.FromResult(new QueryData() + { + Items = items, + TotalCount = total + }); + } + + private static Task ExportAsync(IEnumerable Items) => Task.FromResult(true); + + /// + /// OnInitializedAsync 方法 + /// + /// + protected override async Task OnInitializedAsync() + { + Version = await VersionManager.GetVersionAsync("bootstrapblazor.tableexport"); + } + } +} diff --git a/src/BootstrapBlazor.Shared/docs.json b/src/BootstrapBlazor.Shared/docs.json index 6dea99bddbd3ab68dc47005a6f172bca7307c72b..a2e5ae1c313645d454fbb71c5db6936e36a66b1f 100644 --- a/src/BootstrapBlazor.Shared/docs.json +++ b/src/BootstrapBlazor.Shared/docs.json @@ -14,7 +14,7 @@ "edit": "Table/TablesEdit;Table/TablesBaseEdit", "editdialogs": "EditDialogs", "editorforms": "EditorForms", - "export": "Table/TablesExport;Table/TablesBaseEdit", + "export": "Table/TablesExport", "filter": "Table/TablesFilter", "fix-column": "Table/TablesFixedColumn", "footer": "Table/TablesFooter;Table/TablesBaseQuery",