
Transfer
Demo
You can customize the list title copy, button copy, rendering function of data items, check status copy at the bottom of the list, content area at the bottom of the list, and so on.
Demo
In cases where there is a lot of data, you can search and filter the data.
Demo
When component data changes, the bidirectional binding bind-Value
values change synchronously
Demo
Transfer
component is a generic component that supports three binding types string
IEnumerable<string>
IEnumerable<SelectedItem>
in this case bidirectional binding TheSelectValue
type is IEnumerable<SelectedItem>
When component data changes, the bidirectional binding bind-Value
values change synchronously
Demo
The Transfer
component built into the ValidateForm
component turns on client authentication, in this case the component bidirectional binding Model.Hobby
type is IEnumerable<string>
When you set the IsDisabled
property value to true
, the component suppresses input
Demo
By setting the OnSetItemClass
callback method styles options based on the values of SelectedItem
Demo
Attributes
Event
@page "/transfers"
@inject IStringLocalizer<Transfers> Localizer
<h3>Transfer</h3>
<DemoBlock Title="Basic usage" Introduction="" Name="Normal">
<Transfer TValue="string" Items="@Items" OnSelectedItemsChanged="@OnSelectedItemsChanged" />
<BlockLogger @ref="Trace" class="mt-3" />
</DemoBlock>
<DemoBlock Title="Customizable" Introduction="You can customize the list title copy, button copy, rendering function of data items, check status copy at the bottom of the list, content area at the bottom of the list, and so on." Name="Customer">
<Transfer TValue="string" Items="@Items1"
LeftPanelText="The list on the left" RightPanelText="The list on the right"
LeftButtonText="To the left" RightButtonText="To the Right" />
</DemoBlock>
<DemoBlock Title="Searchable" Introduction="In cases where there is a lot of data, you can search and filter the data." Name="Search">
<Transfer TValue="string" Items="@Items2"
LeftPanelText="The list on the left" RightPanelText="The list on the right"
LeftButtonText="To the left" RightButtonText="To the Right"
LeftPannelSearchPlaceHolderString="Please enter" RightPannelSearchPlaceHolderString="Please enter"
ShowSearch="true" />
</DemoBlock>
<DemoBlock Title="Two-way binding" Introduction="When component data changes, the bidirectional binding <code>bind-Value</code> values change synchronously" Name="Bind">
<p><code>Transfer</code> component is a generic component that supports three binding types <code>string</code> <code>IEnumerable<string></code> <code>IEnumerable<SelectedItem></code> in this case bidirectional binding The<code>SelectValue</code> type is <code>IEnumerable<SelectedItem></code></p>
<Transfer Items="@Items3" @bind-Value="@SelectedValue" />
<div class="my-3">Value:@string.Join(";", SelectedValue.Select(i => i.Text))</div>
<Button Text="Add" OnClick="@OnAddItem" />
</DemoBlock>
<DemoBlock Title="Client Validation" Introduction="When component data changes, the bidirectional binding <code>bind-Value</code> values change synchronously" Name="Validate">
<p>The <code>Transfer</code> component built into the <code>ValidateForm</code> component turns on client authentication, in this case the component bidirectional binding <code>Model.Hobby</code> type is <code>IEnumerable<string></code></p>
<ValidateForm Model="@Model">
<div class="row g-3">
<div class="col-12">
<Transfer Items="@Items5" @bind-Value="@Model.Hobby" />
</div>
<div class="col-12">
<Button ButtonType="ButtonType.Submit">Submit</Button>
</div>
</div>
</ValidateForm>
<div class="mt-3">Hobby: @string.Join(",", Model.Hobby)</div>
</DemoBlock>
<DemoBlock Title="Disable" Introduction="When you set the <code>IsDisabled</code> property value to <code>true</code>, the component suppresses input" Name="Disable">
<Transfer TValue="string" Items="@Items4" IsDisabled="true"
LeftPanelText="The list on the left" RightPanelText="The list on the right"
LeftButtonText="To the left" RightButtonText="To the Right"
LeftPannelSearchPlaceHolderString="Please enter" RightPannelSearchPlaceHolderString="Please enter"
ShowSearch="true" />
</DemoBlock>
<DemoBlock Title="Set the Item style" Introduction="By setting the <code>OnSetItemClass</code> callback method styles options based on the</code> values of <code>SelectedItem" Name="ItemClass">
<Transfer TValue="string" Items="@Items4" OnSetItemClass="SetItemClass" />
</DemoBlock>
<AttributeTable Items="@GetAttributes()" />
<EventTable Items="@GetEvents()" />
// 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.Common;
using BootstrapBlazor.Shared.Components;
using Microsoft.AspNetCore.Components;
namespace BootstrapBlazor.Shared.Samples;
/// <summary>
///
/// </summary>
public sealed partial class Transfers : ComponentBase
{
/// <summary>
///
/// </summary>
[NotNull]
private IEnumerable<SelectedItem>? Items { get; set; }
[NotNull]
private IEnumerable<SelectedItem>? Items1 { get; set; }
[NotNull]
private IEnumerable<SelectedItem>? Items2 { get; set; }
[NotNull]
private List<SelectedItem>? Items3 { get; set; }
[NotNull]
private IEnumerable<SelectedItem>? Items4 { get; set; }
[NotNull]
private IEnumerable<SelectedItem>? Items5 { get; set; }
[NotNull]
private BlockLogger? Trace { get; set; }
private IEnumerable<SelectedItem> SelectedValue { get; set; } = Enumerable.Empty<SelectedItem>();
private Foo Model { get; set; } = new();
/// <summary>
/// OnInitializedAsync 方法
/// </summary>
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
// 模拟异步加载数据源
await Task.Delay(100);
Items = Enumerable.Range(1, 15).Select(i => new SelectedItem()
{
Text = $"{Localizer["Data"]} {i:d2}",
Value = i.ToString()
});
Items1 = Enumerable.Range(1, 15).Select(i => new SelectedItem()
{
Text = $"{Localizer["Data"]} {i:d2}",
Value = i.ToString()
});
Items2 = Enumerable.Range(1, 15).Select(i => new SelectedItem()
{
Text = $"{Localizer["Data"]} {i:d2}",
Value = i.ToString()
});
Items3 = Enumerable.Range(1, 15).Select(i => new SelectedItem()
{
Text = $"{Localizer["Backup"]} {i:d2}",
Value = i.ToString()
}).ToList();
var v = SelectedValue.ToList();
v.AddRange(Items3.Take(2));
v.AddRange(Items3.Skip(4).Take(1));
SelectedValue = v;
Items4 = Enumerable.Range(1, 15).Select(i => new SelectedItem()
{
Text = $"{Localizer["Data"]} {i:d2}",
Value = i.ToString()
});
Items5 = Enumerable.Range(1, 15).Select(i => new SelectedItem()
{
Text = $"{Localizer["Data"]} {i:d2}",
Value = i.ToString()
});
}
private void OnAddItem()
{
var count = Items3.Count + 1;
Items3.Add(new SelectedItem(count.ToString(), $"{Localizer["Backup"]} {count:d2}"));
}
/// <summary>
///
/// </summary>
/// <param name="items"></param>
private Task OnSelectedItemsChanged(IEnumerable<SelectedItem> items)
{
Trace?.Log(string.Join(" ", items.Select(i => i.Text)));
return Task.CompletedTask;
}
private static string? SetItemClass(SelectedItem item) => item.Value switch
{
"2" => "bg-success text-white",
"4" => "bg-info text-white",
"6" => "bg-primary text-white",
"8" => "bg-warning text-white",
_ => null
};
/// <summary>
/// 获得属性方法
/// </summary>
/// <returns></returns>
private IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
{
// TODO: 移动到数据库中
new AttributeItem() {
Name = "Items",
Description = Localizer["Items"],
Type = "IEnumerable<SelectedItem>",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "LeftButtonText",
Description = Localizer["LeftButtonTextAttr"],
Type = "string",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "LeftPanelText",
Description = Localizer["LeftPanelTextAttr"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["LeftPanelDefaultValue"]!
},
new AttributeItem() {
Name = "RightButtonText",
Description = Localizer["RightButtonTextAttr"],
Type = "string",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "RightPanelText",
Description = Localizer["RightPanelTextAttr"],
Type = "string",
ValueList = " — ",
DefaultValue = Localizer["RightPanelTextDefaultValue"]!
},
new AttributeItem() {
Name = "ShowSearch",
Description = "",
Type = "boolean",
ValueList = " — ",
DefaultValue = "false"
},
new AttributeItem() {
Name = "LeftPannelSearchPlaceHolderString",
Description = Localizer["LeftPannelSearchPlaceHolderString"],
Type = "string",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "RightPannelSearchPlaceHolderString",
Description = Localizer["RightPannelSearchPlaceHolderString"],
Type = "string",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "IsDisabled",
Description = Localizer["IsDisabled"],
Type = "boolean",
ValueList = "true / false",
DefaultValue = "false"
}
};
/// <summary>
/// 获得事件方法
/// </summary>
/// <returns></returns>
private IEnumerable<EventItem> GetEvents() => new EventItem[]
{
new EventItem()
{
Name = "OnItemsChanged",
Description = Localizer["OnItemsChanged"],
Type = "Action<IEnumerable<SelectedItem>>"
},
new EventItem()
{
Name = "OnSetItemClass",
Description = Localizer["OnSetItemClass"],
Type = "Func<SelectedItem, string?>"
}
};
}