logoEnterprise-level component library based on Bootstrap and Blazor
gitee
version
license
download
repo
commit
build
coverage

Table Column

Used to display multiple pieces of data with similar structures, data can be sorted, filtered, compared or other custom operations.

Add column header display name by setting Text

Demo

The fields in the table component TableColumns template are automatically displayed according to the DisplayName tag value of the bound model. If you want to customize the display name, please set Text property

Loading...

Add the first column of the table by setting IsMultipleSelect=true to select the column

Demo
Loading...

By setting ShowCheckboxText=true the display text in the first column of the table is select

Demo
Loading...

RowTemplate internal component TableCell set Checkbox and set related data binding. In this example, data binding will select The box component is bound to the value

Demo
Loading...

By setting the TableColumn Width property, the column width is controlled, and the inline button operation column width is controlled by the ExtendButtonColumnWidth property

Demo

Continue the previous example in this example, implement four custom function buttons, and extend them to the row. When each button is clicked, there is a corresponding callback delegate method. TableToolbarButton uses It is the way of Delegate to complete the data exchange. When the toolbar button is clicked, set the OnClick delegate method to obtain the selected row data set in the table

Continue the previous example in this example, implement four custom function buttons, and extend them to the row. When each button is clicked, there is a corresponding callback delegate method. TableToolbarButton uses It is the way of Delegate to complete the data exchange. When the toolbar button is clicked, set the OnClick delegate method to obtain the selected row data set in the table

Control whether the button is displayed by setting the button IsShow parameter

Loading...

Customize the Template template of the TableColumn column to implement any UI

Demo

In this example, the column DateTime value is displayed in different colors depending on whether the Complete value is true

In this example, the column Complete is displayed as a Checkbox component according to the value of Complete

Template template comes with Context associated context, its value is of type TableColumnContext

  • Value is the data value of the currently bound column
  • Row is the data value of the row where the currently bound column is located
Loading...

Format the cell value by specifying the FormatString or Formatter callback delegate when the column is bound

Demo

In this example the column DateTime values ​​are formatted according to FormatString to yyyy-MM-dd year month day format

In this example the column Count value is formatted according to Formatter to 0.00 with two decimal places

Loading...

Set the alignment by specifying the Align attribute when the column is bound

Demo

In this example the column DateTime is set to center alignment Alignment.Center

In this example the column Count is set to right-align Alignment.Right

Loading...

Set whether to display at different widths by specifying the ShownWithBreakPoint attribute

Demo

ShownWithBreakPoint enumeration value:

  • None is displayed if not set
  • Small is displayed when the screen is greater than or equal to 576px
  • Medium is displayed when the screen is greater than or equal to 768px
  • Large is displayed when the screen is greater than or equal to 992px
  • ExtraLarge is displayed when the screen is greater than or equal to 1200px

In this example, the Count column is set to BreakPoint.Large, that is, the screen will only be displayed when it is larger than 992px

Note:

Because the Table component supports mobile adaptation by default, the card mode is used for small screens. In this example, the explicit setting uses RenderMode="TableRenderMode. Table" mode

Loading...

Set whether the column is displayed by specifying the ShowColumnList attribute

Demo

ShowColumnList The default value is false, and if it is explicitly specified as true, the corresponding column adjustment button will appear in the toolbar

TableColumn adds the Visiable property, its default value is true, this column will not be displayed when the display is set to false

In this example, the quantity column is not displayed by setting Visible, and it can be displayed through the column control button

Trigger the OnColumnVisibleChanged callback when switch the column state Show/Hide

Call the instancel method ResetVisibleColumns of Table for set the multiple columns visible value

Loading...

Set table columns to allow resizing by specifying AllowResizing

Demo

Column resizing can only be done when the screen is too small and the scroll bar appears

Loading...

Set ShowCopyColumn show the icon for copy entire column data

Demo

可以通过设置 ShowCopyColumnTooltip CopyColumnTooltipText CopyColumnCopiedTooltipText 等设置微调拷贝列数据图标的 Tooltip 相关参数

Loading...

By specifying Template set the last column to display as a custom button

Demo
Loading...

By specifying the AutoGenerateColumns property value as true, enable the function of automatically generating column information based on the binding model

Demo

In this example, by setting the value of AutoGenerateColumns to true, the automatic column generation function is enabled. All attributes of the bound model entity class are all generated by default. code>AutoGenerateColumnAttribute tag class for function settings, such as:

  • Ignore means ignore this property, i.e. not generate
  • Readonly means read only
  • For more attributes, see Source code
In this example the date column is formatted through the [AutoGenerateColumn(Order = 1, FormatString = "yyyy-MM-dd")] tag; Set the template column in the code to customize the Complete column and use the Switch component to render; through the [AutoGenerateColumn(Order = 10)] tag in the Order set the display order

Loading...

By specifying OnColumnCreating callback, make secondary data changes to the column collection

Demo
Loading...

Custom rendering of columns by showing template Template

Demo
Loading...
@page "/tables/column"
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption

<h3>@ColumnLocalizer["Title"]</h3>

<h4>@ColumnLocalizer["H4"]</h4>

<DemoBlock Title="@ColumnLocalizer["ColumnTextTitle"]" Introduction="@ColumnLocalizer["ColumnTextIntro"]" Name="ColumnText">
    <p>@((MarkupString)ColumnLocalizer["ColumnTextDesc"].Value)</p>
    <Table TItem="Foo" Items="@Items.Take(3)">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Text="@ColumnLocalizer["CustomColText1"]" Width="180" />
            <TableColumn @bind-Field="@context.Name" Text="@ColumnLocalizer["CustomColText2"]" />
            <TableColumn @bind-Field="@context.Address" Text="@ColumnLocalizer["CustomColText3"]" />
            <TableColumn @bind-Field="@context.Complete" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["SelectTitle"]" Introduction="@ColumnLocalizer["SelectIntro"]" Name="Select">
    <Table TItem="Foo" Items="@Items.Take(3)" IsMultipleSelect="true">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Complete" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["ShowCheckboxTitle"]" Introduction="@ColumnLocalizer["ShowCheckboxIntro"]" Name="ShowCheckbox">
    <Table TItem="Foo" Items="@Items.Take(3)" IsMultipleSelect="true" ShowCheckboxText="true">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Complete" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["DisabledTitle"]" Introduction="@ColumnLocalizer["DisabledIntro"]" Name="Disabled">
    <Table TItem="Foo" Items="@Items.Take(3)">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" />
            <TableColumn @bind-Field="@context.Complete">
                <Template Context="value">
                    <Checkbox Value="@value.Value" IsDisabled="true"></Checkbox>
                </Template>
            </TableColumn>
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["WidthTitle"]" Introduction="@ColumnLocalizer["WidthIntro"]" Name="Width">
    <p>@((MarkupString)ColumnLocalizer["WidthP1"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["WidthP1"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["WidthP3"].Value)</p>
    <Table TItem="Foo" @ref="TableRows"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true"
           ShowToolbar="true" ShowDefaultButtons="false" ShowSearch="false" IsMultipleSelect="true"
           ShowExtendButtons="true" ExtendButtonColumnWidth="240"
           OnQueryAsync="@OnQueryAsync">
        <TableToolbarTemplate>
            <TableToolbarButton TItem="Foo" Color="Color.Primary" Icon="fa-fw fa-solid fa-pen-to-square" IsEnableWhenSelectedOneRow="true" Text="@ColumnLocalizer["WidthButtonText1"]" OnClickCallback="@CustomerButton" />
            <TableToolbarButton TItem="Foo" Color="Color.Success" Icon="fa-fw fa-solid fa-pen-to-square" IsEnableWhenSelectedOneRow="true" Text="@ColumnLocalizer["WidthButtonText2"]" OnClickCallback="@CustomerButton" />
            <TableToolbarButton TItem="Foo" Color="Color.Warning" Icon="fa-fw fa-solid fa-pen-to-square" IsEnableWhenSelectedOneRow="true" Text="@ColumnLocalizer["WidthButtonText3"]" OnClickCallback="@CustomerButton" />
            <TableToolbarButton TItem="Foo" Color="Color.Danger" Icon="fa-fw fa-solid fa-pen-to-square" IsEnableWhenSelectedOneRow="true" Text="@ColumnLocalizer["WidthButtonText4"]" OnClickCallback="@CustomerButton" />
        </TableToolbarTemplate>
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" Width="100" />
            <TableColumn @bind-Field="@context.Address" />
        </TableColumns>
        <RowButtonTemplate>
            <TableCellButton Color="Color.Primary" Icon="fa-solid fa-pen" Text="@ColumnLocalizer["WidthButtonText1"]" OnClick="@(() => OnRowButtonClick(context, ColumnLocalizer["WidthButtonText1"]))" />
            <TableCellButton Color="Color.Success" Icon="fa-solid fa-pen" Text="@ColumnLocalizer["WidthButtonText2"]" OnClick="@(() => OnRowButtonClick(context, ColumnLocalizer["WidthButtonText2"]))" />
            <TableCellButton Color="Color.Warning" Icon="fa-solid fa-pen" Text="@ColumnLocalizer["WidthButtonText3"]" OnClick="@(() => OnRowButtonClick(context, ColumnLocalizer["WidthButtonText3"]))" />
            <TableCellButton Color="Color.Danger" Icon="fa-solid fa-pen" Text="@ColumnLocalizer["WidthButtonText4"]" OnClick="@(() => OnRowButtonClick(context, ColumnLocalizer["WidthButtonText4"]))" />
            <TableCellPopconfirmButton Color="Color.Info" Icon="fa-solid fa-pen" Text="@ColumnLocalizer["WidthConfirmButtonText"]" OnConfirm="@(() => OnRowButtonClick(context, ColumnLocalizer["WidthConfirmButtonText"]))" />
        </RowButtonTemplate>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["TableColumnTitle"]" Introduction="@ColumnLocalizer["TableColumnIntro"]" Name="TableColumn">
    <p>@((MarkupString)ColumnLocalizer["TableColumnP1"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["TableColumnP2"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["TableColumnP3"].Value)</p>
    <ul>
        <li>@((MarkupString)ColumnLocalizer["TableColumnli1"].Value)</li>
        <li>@((MarkupString)ColumnLocalizer["TableColumnli2"].Value)</li>
    </ul>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true"
           ShowToolbar="false" IsMultipleSelect="true" ShowExtendButtons="false"
           OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180">
                <Template Context="value">
                    @if (value.Row.Complete)
                    {
                        <div class="text-success">@value.Value</div>
                    }
                    else
                    {
                        <div class="text-danger">@value.Value</div>
                    }
                </Template>
            </TableColumn>
            <TableColumn @bind-Field="@context.Name" Width="100" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Complete" Width="100">
                <Template Context="value">
                    <Checkbox Value="@value.Value" IsDisabled="true"></Checkbox>
                </Template>
            </TableColumn>
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["FormatterTitle"]" Introduction="@ColumnLocalizer["FormatterIntro"]" Name="Formatter">
    <p>@((MarkupString)ColumnLocalizer["FormatterP1"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["FormatterP2"].Value)</p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true"
           ShowToolbar="false" IsMultipleSelect="true" ShowExtendButtons="false"
           OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="120" FormatString="yyyy-MM-dd" />
            <TableColumn @bind-Field="@context.Name" Width="100" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Count" Formatter="@IntFormatter" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["AlignTitle"]" Introduction="@ColumnLocalizer["AlignIntro"]" Name="Align">
    <p>@((MarkupString)ColumnLocalizer["AlignP1"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["AlignP2"].Value)</p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true"
           ShowToolbar="false" IsMultipleSelect="true" ShowExtendButtons="false"
           OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="120" FormatString="yyyy-MM-dd" Align="Alignment.Center" />
            <TableColumn @bind-Field="@context.Name" Width="100" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Count" Formatter="@IntFormatter" Width="60" Align="Alignment.Right" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["ShownWithBreakPointTitle"]" Introduction="@ColumnLocalizer["ShownWithBreakPointIntro"]" Name="ShownWithBreakPoint">
    <p>@((MarkupString)ColumnLocalizer["ShownWithBreakPointP1"].Value)</p>
    <ul class="ul-demo mb-3">
        <li>@((MarkupString)ColumnLocalizer["ShownWithBreakPointLi1"].Value)</li>
        <li>@((MarkupString)ColumnLocalizer["ShownWithBreakPointLi2"].Value)</li>
        <li>@((MarkupString)ColumnLocalizer["ShownWithBreakPointLi3"].Value)</li>
        <li>@((MarkupString)ColumnLocalizer["ShownWithBreakPointLi4"].Value)</li>
        <li>@((MarkupString)ColumnLocalizer["ShownWithBreakPointLi5"].Value)</li>
    </ul>
    <p>@((MarkupString)ColumnLocalizer["ShownWithBreakPointP2"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["ShownWithBreakPointP3"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["ShownWithBreakPointP4"].Value)</p>
    <Table TItem="Foo" RenderMode="TableRenderMode.Table"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true"
           ShowToolbar="false" IsMultipleSelect="true" ShowExtendButtons="false"
           OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="120" FormatString="yyyy-MM-dd" Align="Alignment.Center" />
            <TableColumn @bind-Field="@context.Name" Width="100" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Count" ShownWithBreakPoint="BreakPoint.Large" Formatter="@IntFormatter" Width="60" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["VisibleTitle"]" Introduction="@ColumnLocalizer["VisibleIntro"]" Name="Visible">
    <p>@((MarkupString)ColumnLocalizer["VisibleP1"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["VisibleP2"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["VisibleP3"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["VisibleP4"].Value)</p>
    <p>@((MarkupString)ColumnLocalizer["ResetVisibleColumnsDesc"].Value)</p>
    <div><Button Text="@ColumnLocalizer["ResetVisibleColumnsButtonText"]" OnClickWithoutRender="ResetVisibleColumns" /></div>
    <Table TItem="Foo" @ref="TableColumnVisibles"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true" IsMultipleSelect="true"
           ShowToolbar="true" ShowAddButton="false" ShowEditButton="false" ShowDeleteButton="false"
           ShowExtendButtons="false" ShowColumnList="true"
           OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" />
            <TableColumn @bind-Field="@context.Address" Width="290" />
            <TableColumn @bind-Field="@context.Education" />
            <TableColumn @bind-Field="@context.Count" Visible="false" />
            <TableColumn @bind-Field="@context.Complete" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["AllowResizingTitle"]" Introduction="@ColumnLocalizer["AllowResizingIntro"]" Name="AllowResizing">
    <p>@((MarkupString)ColumnLocalizer["AllowResizingDesc"].Value)</p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource" AllowResizing="true"
           IsStriped="true" IsBordered="true"
           ShowToolbar="false" IsMultipleSelect="true" ShowExtendButtons="false"
           OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="120" FormatString="yyyy-MM-dd" />
            <TableColumn @bind-Field="@context.Name" Width="100" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Count" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["ShowCopyColumnTitle"]" Introduction="@ColumnLocalizer["ShowCopyColumnIntro"]" Name="ShowCopyColumn">
    <p>@((MarkupString)ColumnLocalizer["ShowCopyColumnDesc"].Value)</p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource" AllowResizing="true"
           IsStriped="true" IsBordered="true"
           ShowToolbar="false" IsMultipleSelect="true" ShowExtendButtons="false"
           OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="120" FormatString="yyyy-MM-dd" ShowCopyColumn="true" />
            <TableColumn @bind-Field="@context.Name" Width="100" ShowCopyColumn="true" />
            <TableColumn @bind-Field="@context.Address" ShowCopyColumn="true" />
            <TableColumn @bind-Field="@context.Count" ShowCopyColumn="true" />
            <TableColumn @bind-Field="@context.Education" ShowCopyColumn="true" />
            <TableColumn @bind-Field="@context.Complete" ShowCopyColumn="true" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["TemplateTitle"]" Introduction="@ColumnLocalizer["TemplateIntro"]" Name="Template">
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true"
           ShowToolbar="false" IsMultipleSelect="true" ShowExtendButtons="false"
           OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="120" FormatString="yyyy-MM-dd" />
            <TableColumn @bind-Field="@context.Name" Width="100" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Count" />
            <TableColumn @bind-Field="@context.Id" Text="">
                <Template Context="v">
                    <PopConfirmButton Text="Test" Size="Size.ExtraSmall" />
                </Template>
            </TableColumn>
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["AutoGenerateColumnsTitle"]" Introduction="@ColumnLocalizer["AutoGenerateColumnsIntro"]" Name="AutoGenerateColumns">
    <p>
        @((MarkupString)ColumnLocalizer["AutoGenerateColumnsP1"].Value)
        <ul class="ul-demo mb-3">
            <li>@((MarkupString)ColumnLocalizer["AutoGenerateColumnsLi1"].Value)</li>
            <li>@((MarkupString)ColumnLocalizer["AutoGenerateColumnsLi2"].Value)</li>
            <li>@((MarkupString)string.Format(ColumnLocalizer["AutoGenerateColumnsLi3"].Value, WebsiteOption.CurrentValue.BootstrapBlazorLink))</li>
        </ul>
        @((MarkupString)ColumnLocalizer["AutoGenerateColumnsP2"].Value)
    </p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true" AutoGenerateColumns="true"
           ShowToolbar="false" IsMultipleSelect="true" ShowExtendButtons="false"
           OnQueryAsync="@OnQueryAsync">
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["OnColumnCreatingTitle"]" Introduction="@ColumnLocalizer["OnColumnCreatingIntro"]" Name="OnColumnCreating">
    <Tips>
        <p>@((MarkupString)ColumnLocalizer["OnColumnCreatingP1"].Value)</p>
        <ol>
            <li>@ColumnLocalizer["OnColumnCreatingLi1"]</li>
            <li>@((MarkupString)ColumnLocalizer["OnColumnCreatingLi2"].Value)</li>
        </ol>
        <p>@((MarkupString)ColumnLocalizer["OnColumnCreatingP2"].Value)</p>
    </Tips>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true" AutoGenerateColumns="true"
           ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true"
           ShowDefaultButtons="true" OnSaveAsync="@OnSaveAsync"
           OnQueryAsync="@OnQueryAsync" OnColumnCreating="@OnColumnCreating" ShowEditButton="true">
    </Table>
</DemoBlock>

<DemoBlock Title="@ColumnLocalizer["AdvanceTitle"]" Introduction="@ColumnLocalizer["AdvanceIntro"]" Name="Advance">
    <Table TItem="Foo" IsPagination="true" PageItemsSource="@PageItemsSource" RenderMode="TableRenderMode.Table"
           IsStriped="true" IsBordered="true" OnQueryAsync="OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.Name" Width="220">
                <Template Context="value">
                    <div class="d-flex">
                        <div>
                            <img src="@Foo.GetAvatarUrl(value.Row.Id)" class="bb-avatar" />
                        </div>
                        <div class="ps-2">
                            <div>@value.Value</div>
                            <div class="bb-sub">@value.Row.Address</div>
                        </div>
                    </div>
                </Template>
            </TableColumn>
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Education" Align="Alignment.Center" Width="80" />
            <TableColumn @bind-Field="@context.Count" Width="160">
                <Template Context="value">
                    <div class="w-100">
                        <div>@value.Value %</div>
                        <Progress Value="@value.Value" Color="@Foo.GetProgressColor(value.Value)"></Progress>
                    </div>
                </Template>
            </TableColumn>
            <TableColumn @bind-Field="@context.Complete" Align="Alignment.Center" Width="80" />
        </TableColumns>
    </Table>
</DemoBlock>
// 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/

namespace BootstrapBlazor.Shared.Samples.Table;

/// <summary>
/// Table 组件列属性示例代码
/// </summary>
public partial class TablesColumn
{
    [NotNull]
    private List<Foo>? Items { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<Foo>? Localizer { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<TablesColumn>? ColumnLocalizer { get; set; }

    [Inject]
    [NotNull]
    private ToastService? ToastService { get; set; }

    private static IEnumerable<int> PageItemsSource => new int[] { 5, 10, 20 };

    [NotNull]
    private Table<Foo>? TableColumnVisibles { get; set; }

    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Items = Foo.GenerateFoo(Localizer);
    }

    private Task ResetVisibleColumns()
    {
        TableColumnVisibles.ResetVisibleColumns(new ColumnVisibleItem[]
        {
            new(nameof(Foo.DateTime), true),
            new(nameof(Foo.Name), false),
            new(nameof(Foo.Address), false),
            new(nameof(Foo.Education), false),
            new(nameof(Foo.Count), false),
            new(nameof(Foo.Complete), true)
        });
        return Task.CompletedTask;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="d"></param>
    /// <returns></returns>
    private static Task<string> IntFormatter(object? d)
    {
        var ret = "";
        if (d is TableColumnContext<Foo, object?> data && data.Value != null)
        {
            var val = (int)data.Value;
            ret = val.ToString("0.00");
        }
        return Task.FromResult(ret);
    }

    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 = Foo.GetNameSortFunc();
            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>
    private async Task CustomerButton(IEnumerable<Foo> items)
    {
        var cate = ToastCategory.Information;
        var title = ColumnLocalizer["CustomerButtonTitle"];
        var content = ColumnLocalizer["CustomerButtonContent", items.Count()];
        await ToastService.Show(new ToastOption()
        {
            Category = cate,
            Title = title,
            Content = content
        });
    }

    [NotNull]
    private Table<Foo>? TableRows { get; set; }

    private async Task OnRowButtonClick(Foo item, string text)
    {
        var cate = ToastCategory.Success;
        var title = $"{text} {item.Name}";
        var content = ColumnLocalizer["OnRowButtonClickContent"];
        await ToastService.Show(new ToastOption()
        {
            Category = cate,
            Title = title,
            Content = content
        });

        await TableRows.QueryAsync();
    }

    private static Task<bool> OnSaveAsync(Foo foo, ItemChangedType changedType)
    {
        return Task.FromResult(true);
    }

    private static Task OnColumnCreating(List<ITableColumn> columns)
    {
        foreach (var item in columns)
        {
            if (item.GetFieldName() == nameof(Foo.Name))
            {
                item.Readonly = true;
            }
        }
        return Task.CompletedTask;
    }
}

B station related video link

交流群

QQ Group:BootstrapAdmin & Blazor 795206915 675147445 Welcome to join the group discussion
img
Themes
Bootstrap
Motronic
Ant Design (完善中)
DevUI (制作中)
LayUI (完善中)
An error has occurred. This application may no longer respond until reloaded. Reload
Seems like the connection with the server has been lost. It can be due to poor or broken network. Please hang on while we're trying to reconnect...
Oh snap! Failed to reconnect with the server. This is typically caused by a longer network outage, or if the server has been taken down. You can try to reconnect, but if that does not work, you need to reload the page.
Oh man! The server rejected the attempt to reconnect. The only option now is to reload the page, but be prepared that it won't work, since this is typically caused by a failure on the server.
Bootstrap Blazor Component library updated to 7.0.8-beta05

Bootstrap Blazor at present has more than 120 components. This component is based on Bootstrap Blazor An enterprise-level component library that provides several types of common components such as layout, navigation, form, data, notification, icon, voice, etc. Each component has been carefully designed with modularity, responsiveness and excellent performance. Starting from more practical scenarios, meeting the needs of various scenarios, greatly reducing the time cost of developers, greatly shortening the development cycle, greatly improving development efficiency, and providing a set of General Rights Management System Example project。Bootstrap Blazor Products are maintained by a professional full-time technical team, with efficient response speed, diversified solutions, long-term support, and enterprise-level support. At present, it has been used in many well-known state-owned enterprises, and the project is running stably with a maximum of 1200 people online. On the right is the QR code of the Chinese Blazor QQ community with the largest number of people in China, welcome to scan and join the group.

component updated to 6.6.0 Change log [portal] If the component brings you convenience, please help to light up the project Star github gitee

QQGroup
QQ 795206915