!1229 docs(#I3E6RM): update Table Column sample code

* docs: 更新列示例文档
* chore: update nuget package source
* chore: update eidtorconfig file
pull/1229/MERGE
Argo 4 years ago
parent a03d6d4869
commit 3610c1e89f

@ -64,8 +64,8 @@ dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
dotnet_prefer_inferred_tuple_names = true:suggestion
dotnet_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="cnblogs" value="https://nuget.cnblogs.com/v3/index.json" />
<add key="azure" value="https://nuget.cdn.azure.cn/v3/index.json" />
<add key="cnblogs" value="https://nuget.cnblogs.com/v3/index.json" />
<add key="huawei" value="https://repo.huaweicloud.com/repository/nuget/v3/index.json" />
</packageSources>
</configuration>

@ -1,65 +0,0 @@
// 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 System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BootstrapBlazor.Shared.Pages
{
/// <summary>
///
/// </summary>
public abstract class TablesBaseColumn : TablesBaseQuery
{
/// <summary>
///
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
protected Task<string> IntFormatter(object? d)
{
var data = (int?)d;
return Task.FromResult(data?.ToString("0.00") ?? "");
}
/// <summary>
///
/// </summary>
/// <param name="items"></param>
protected Task CustomerButton(IEnumerable<Foo> items)
{
var cate = ToastCategory.Information;
var title = "自定义按钮处理方法";
var content = $"通过不同的函数区分按钮处理逻辑,参数 Items 为 Table 组件中选中的行数据集合,当前选择数据 {items.Count()} 条";
ToastService?.Show(new ToastOption()
{
Category = cate,
Title = title,
Content = content
});
return Task.CompletedTask;
}
/// <summary>
///
/// </summary>
/// <param name="item"></param>
protected Task OnRowButtonClick(Foo item)
{
var cate = ToastCategory.Success;
var title = "行内按钮处理方法";
var content = "通过不同的函数区分按钮处理逻辑,参数 Item 为当前行数据";
ToastService?.Show(new ToastOption()
{
Category = cate,
Title = title,
Content = content
});
return Task.CompletedTask;
}
}
}

@ -1,6 +1,4 @@
@using Foo = BootstrapBlazor.Shared.Pages.Components.Foo
@inherits TablesBaseColumn
@page "/tables/column"
@page "/tables/column"
<h3>Table 表格</h3>

@ -0,0 +1,129 @@
// 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.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
{
/// <summary>
/// Table 组件列属性示例代码
/// </summary>
public partial class TablesColumn
{
private static readonly ConcurrentDictionary<Type, Func<IEnumerable<Foo>, string, SortOrder, IEnumerable<Foo>>> SortLambdaCache = new();
[NotNull]
private List<Foo>? Items { get; set; }
[Inject]
[NotNull]
private IStringLocalizer<Foo>? Localizer { get; set; }
[Inject]
[NotNull]
private ToastService? ToastService { get; set; }
private static IEnumerable<int> PageItemsSource => new int[] { 4, 10, 20 };
/// <summary>
/// OnInitialized 方法
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();
Items = Foo.GenerateFoo(Localizer);
}
/// <summary>
///
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
protected static Task<string> IntFormatter(object? d)
{
var data = (int?)d;
return Task.FromResult(data?.ToString("0.00") ?? "");
}
private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
{
IEnumerable<Foo> items = Items;
// 过滤
var isFiltered = false;
if (options.Filters.Any())
{
items = items.Where(options.Filters.GetFilterFunc<Foo>());
isFiltered = true;
}
// 排序
var isSorted = false;
if (!string.IsNullOrEmpty(options.SortName))
{
var invoker = SortLambdaCache.GetOrAdd(typeof(Foo), key => LambdaExtensions.GetSortLambda<Foo>().Compile());
items = invoker(items, options.SortName, options.SortOrder);
isSorted = true;
}
// 设置记录总数
var total = items.Count();
// 内存分页
items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();
return Task.FromResult(new QueryData<Foo>()
{
Items = items,
TotalCount = total,
IsSorted = isSorted,
IsFiltered = isFiltered,
IsSearch = true
});
}
/// <summary>
///
/// </summary>
/// <param name="items"></param>
protected async Task CustomerButton(IEnumerable<Foo> items)
{
var cate = ToastCategory.Information;
var title = "自定义按钮处理方法";
var content = $"通过不同的函数区分按钮处理逻辑,参数 Items 为 Table 组件中选中的行数据集合,当前选择数据 {items.Count()} 条";
await ToastService.Show(new ToastOption()
{
Category = cate,
Title = title,
Content = content
});
}
/// <summary>
///
/// </summary>
/// <param name="item"></param>
protected async Task OnRowButtonClick(Foo item)
{
var cate = ToastCategory.Success;
var title = "行内按钮处理方法";
var content = "通过不同的函数区分按钮处理逻辑,参数 Item 为当前行数据";
await ToastService.Show(new ToastOption()
{
Category = cate,
Title = title,
Content = content
});
}
}
}
Loading…
Cancel
Save