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

Table Search

Commonly used for single table maintenance, simple addition, deletion, modification, search, sorting, filtering, search and other common functions can be realized through attribute configuration, and very complex can be realized through the advanced usage of Template business needs functions

Set ShowSearch to display the query component, customize the search UI by setting the SearchTemplate template

Demo
  • Enable no data display function by setting ShowEmpty="true"
  • The EmptyText parameter is used to set the text to be displayed when there is no data, the default is to take the built-in text in the resource file
  • EmptyTemplate parameter is used to customize no data display template
Loading...

When ShowSearch is set, if SearchTemplate is not set when editing template, the component will try to automatically generate search criteria UI

Demo

When the column information is bound, set the Searchable property and set the search criteria to automatically build the UI. You can set the SearchDialogShowMaximizeButton to maximize the search pop-up window display Maximize button

if (options.Searchs.Any())
{
    // Logical relationship usage FilterLogic.Or
    items = items.Where(options.Searchs.GetFilterFunc<Foo>(FilterLogic.Or));
}
Loading...

When SearchTemplate is set, the component automatically generates the search UI using this template as the rendering UI

Demo

By setting the SearchTemplate of the name column to customize the edit, use the drop-down box to select the name

Because it is a search condition, in this example, the drop-down box of the name search column is added. Please select... item

The column search template is generated in the search order SearchTemplate -> AutoGenerate first to find out whether the search template is set, and then automatically generated according to the bound field type

Set the search bar to show only Advanced Search by setting ShowSearch="true" ShowSearchText="false"

Make the search popup draggable by setting SearchDialogDraggable="true"

Loading...

Set CustomerSearchModel and CustomerSearchTemplate to fully control the search criteria UI

Demo

Due to a certain application scenario, our form entity class TItem is not ideal as a search model, for example, we have an attribute that is int or enum, we need a blank condition item of all or please select... as a search condition. It is very difficult to use the default model at this time , you can use the custom search model CustomerSearchModel and CustomerSearchTemplate to customize the control search interface

Loading...
@page "/tables/search"

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

<h4>@((MarkupString)SearchLocalizer["Desc"].Value)</h4>

<Tips>
    <p>@((MarkupString)SearchLocalizer["SearchTableTips"].Value)</p>
</Tips>

<DemoBlock Title="@SearchLocalizer["SearchTableTitle"]" Introduction="@SearchLocalizer["SearchTableIntro"]" Name="SearchTable">
    <ul class="ul-demo mb-3">
        <li>@((MarkupString)SearchLocalizer["SearchTableLi1"].Value)</li>
        <li>@((MarkupString)SearchLocalizer["SearchTableLi2"].Value)</li>
        <li>@((MarkupString)SearchLocalizer["SearchTableLi3"].Value)</li>
    </ul>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true"
           ShowToolbar="true" ShowSearch="true" IsMultipleSelect="true" ShowExtendButtons="true"
           AddModalTitle="@SearchLocalizer["AddModelTitle"]" EditModalTitle="@SearchLocalizer["EditModelTitle"]"
           SearchModel="@SearchModel" ShowEmpty="true" SearchMode="SearchMode.Top"
           OnQueryAsync="@OnSearchModelQueryAsync" OnResetSearchAsync="@OnResetSearchAsync"
           OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Education" />
        </TableColumns>
        <SearchTemplate>
            <GroupBox Title="@SearchLocalizer["SearchTableGroupBoxText"]">
                <div class="row g-3 form-inline">
                    <div class="col-12 col-sm-6">
                        <BootstrapInput @bind-Value="@context.Name" PlaceHolder="@SearchLocalizer["NamePlaceholder"]" maxlength="50" ShowLabel="true" DisplayText="@Localizer[nameof(context.Name)]" />
                    </div>
                    <div class="col-12 col-sm-6">
                        <BootstrapInput @bind-Value="@context.Address" PlaceHolder="@SearchLocalizer["AddressPlaceholder"]" maxlength="500" ShowLabel="true" DisplayText="@Localizer[nameof(context.Address)]" />
                    </div>
                </div>
            </GroupBox>
        </SearchTemplate>
    </Table>
</DemoBlock>

<DemoBlock Title="@SearchLocalizer["AutoGenerateSearchTitle"]" Introduction="@SearchLocalizer["AutoGenerateSearchIntro"]" Name="AutoGenerateSearch">
    <p>@((MarkupString)SearchLocalizer["AutoGenerateSearchP"].Value)</p>
    <Tips>@((MarkupString)SearchLocalizer["AutoGenerateSearchTips"].Value)</Tips>
    <Pre>if (options.Searchs.Any())
{
    // @SearchLocalizer["AutoGenerateSearchCommnt"] FilterLogic.Or
    items = items.Where(options.Searchs.GetFilterFunc<Foo>(FilterLogic.Or));
}</Pre>
    <GroupBox Title="@SearchLocalizer["AutoGenerateSearchGroupBoxTitle"]" class="mb-2">
        <div class="row g-3 form-inline">
            <div class="col-12 col-sm-3">
                <Switch DisplayText="@SearchLocalizer["DisplayText1"]" ShowLabel="true" @bind-Value="SearchModeFlag" />
            </div>
            <div class="col-12 col-sm-3">
                <Switch DisplayText="@SearchLocalizer["DisplayText2"]" ShowLabel="true" @bind-Value="ShowSearchText" />
            </div>
            <div class="col-12 col-sm-3">
                <Switch DisplayText="@SearchLocalizer["DisplayText3"]" ShowLabel="true" @bind-Value="ShowResetButton" />
            </div>
            <div class="col-12 col-sm-3">
                <Switch DisplayText="@SearchLocalizer["DisplayText4"]" ShowLabel="true" @bind-Value="ShowSearchButton" IsDisabled="SearchModeFlag" />
            </div>
        </div>
    </GroupBox>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource" SearchDialogShowMaximizeButton="true"
           IsStriped="true" IsBordered="true" SearchModel="@SearchModel" ShowSearch="true"
           SearchMode="SearchModeValue" ShowResetButton="ShowResetButton" ShowSearchButton="ShowSearchButton"
           ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true" ShowSearchText="ShowSearchText"
           AddModalTitle="@SearchLocalizer["AddModelTitle"]" EditModalTitle="@SearchLocalizer["EditModelTitle"]"
           OnQueryAsync="@OnQueryAsync" OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" Filterable="true" />
            <TableColumn @bind-Field="@context.Name" Searchable="true" />
            <TableColumn @bind-Field="@context.Address" Searchable="true" />
            <TableColumn @bind-Field="@context.Education" Searchable="true" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@SearchLocalizer["CustomColSearchTitle"]" Introduction="@SearchLocalizer["CustomColSearchIntro"]" Name="CustomColSearch">
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP"].Value)</p>
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP1"].Value)</p>
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP2"].Value)</p>
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP3"].Value)</p>
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP4"].Value)</p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true" SearchModel="@SearchModel" ShowSearch="true" ShowSearchText="false"
           ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true" SearchDialogIsDraggable="true"
           AddModalTitle="@SearchLocalizer["AddModelTitle"]" EditModalTitle="@SearchLocalizer["EditModelTitle"]" SearchDialogShowMaximizeButton="true"
           OnQueryAsync="@OnQueryAsync" OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" Filterable="true" />
            <TableColumn @bind-Field="@context.Name" Searchable="true">
                <SearchTemplate Context="model">
                    <div class="col-12 col-sm-6">
                        <Select Items="SearchItems" @bind-Value="@model!.Name" ShowLabel="true" DisplayText="姓名" />
                    </div>
                </SearchTemplate>
            </TableColumn>
            <TableColumn @bind-Field="@context.Address" Searchable="true" />
            <TableColumn @bind-Field="@context.Education" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@SearchLocalizer["CustomerSearchModelTitle"]" Introduction="@SearchLocalizer["CustomerSearchModelIntro"]" Name="CustomerSearchModel">
    <p>@((MarkupString)SearchLocalizer["CustomerSearchModelP"].Value)</p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource" SearchMode="SearchMode.Top"
           IsStriped="true" IsBordered="true" CustomerSearchModel="@CustomerSearchModel" ShowSearch="true" ShowSearchText="true"
           ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true"
           OnQueryAsync="@OnQueryAsync" OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" Searchable="true" />
            <TableColumn @bind-Field="@context.Address" Searchable="true" />
            <TableColumn @bind-Field="@context.Count" />
            <TableColumn @bind-Field="@context.Education" />
        </TableColumns>
        <CustomerSearchTemplate>
            @if (context is FooSearchModel model)
            {
                <FooSearch @bind-Value="@model" />
            }
        </CustomerSearchTemplate>
    </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/

using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;

namespace BootstrapBlazor.Shared.Samples.Table;

/// <summary>
/// Table 组件搜索示例代码
/// </summary>
public sealed partial class TablesSearch
{
    [Inject]
    [NotNull]
    private IStringLocalizer<Foo>? Localizer { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<TablesSearch>? SearchLocalizer { get; set; }

    private Foo SearchModel { get; set; } = new Foo();

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

    [NotNull]
    private List<Foo>? Items { get; set; }

    private bool SearchModeFlag
    {
        get
        {
            return SearchModeValue == SearchMode.Popup;
        }
        set
        {
            SearchModeValue = value ? SearchMode.Popup : SearchMode.Top;
        }
    }

    private bool ShowResetButton { get; set; } = true;

    private bool ShowSearchButton { get; set; } = true;

    private bool ShowSearchText { get; set; }

    private SearchMode SearchModeValue { get; set; }

    private IEnumerable<SelectedItem>? SearchItems { get; set; }

    [NotNull]
    private ITableSearchModel CustomerSearchModel { get; set; } = new FooSearchModel();

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

        Items = Foo.GenerateFoo(Localizer);

        SearchItems = new List<SelectedItem>()
        {
            new SelectedItem { Text = SearchLocalizer["SelectedItemText"].Value, Value = "" },
            new SelectedItem { Text = SearchLocalizer["SelectedItemText1"].Value, Value = SearchLocalizer["SelectedItemValue1"].Value },
            new SelectedItem { Text = SearchLocalizer["SelectedItemText2"].Value, Value = SearchLocalizer["SelectedItemValue2"].Value },
        };
    }

    private static Task<Foo> OnAddAsync() => Task.FromResult(new Foo() { DateTime = DateTime.Now });

    private Task<bool> OnSaveAsync(Foo item, ItemChangedType changedType)
    {
        // 增加数据演示代码
        if (changedType == ItemChangedType.Add)
        {
            item.Id = Items.Max(i => i.Id) + 1;
            Items.Add(item);
        }
        else
        {
            var oldItem = Items.FirstOrDefault(i => i.Id == item.Id);
            if (oldItem != null)
            {
                oldItem.Name = item.Name;
                oldItem.Address = item.Address;
                oldItem.DateTime = item.DateTime;
                oldItem.Count = item.Count;
                oldItem.Complete = item.Complete;
                oldItem.Education = item.Education;
            }
        }
        return Task.FromResult(true);
    }

    private Task<bool> OnDeleteAsync(IEnumerable<Foo> items)
    {
        items.ToList().ForEach(i => Items.Remove(i));
        return Task.FromResult(true);
    }

    private static Task OnResetSearchAsync(Foo item)
    {
        item.Name = "";
        item.Address = "";
        return Task.CompletedTask;
    }

    private Task<QueryData<Foo>> OnSearchModelQueryAsync(QueryPageOptions options)
    {
        // 自定义了 SearchModel
        IEnumerable<Foo> items = Items;

        // 设置记录总数
        var total = items.Count();

        if (!string.IsNullOrEmpty(SearchModel.Name))
        {
            items = items.Where(i => i.Name == SearchModel.Name);
        }

        if (!string.IsNullOrEmpty(SearchModel.Address))
        {
            items = items.Where(i => i.Address == SearchModel.Address);
        }

        // 内存分页
        items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();

        return Task.FromResult(new QueryData<Foo>()
        {
            Items = items,
            TotalCount = total,
            IsSorted = true,
            IsFiltered = true,
            IsSearch = true,
            IsAdvanceSearch = true
        });
    }


    private Task<QueryData<Foo>> OnQueryAsync(QueryPageOptions options)
    {
        IEnumerable<Foo> items = Items;

        var isAdvanceSearch = false;
        // 处理高级搜索
        if (options.AdvanceSearchs.Any())
        {
            items = items.Where(options.AdvanceSearchs.GetFilterFunc<Foo>());
            isAdvanceSearch = true;
        }

        // 处理 自定义 高级搜索 CustomerSearchModel 过滤条件
        if (options.CustomerSearchs.Any())
        {
            items = items.Where(options.CustomerSearchs.GetFilterFunc<Foo>());
            isAdvanceSearch = true;
        }

        // 处理 Searchable=true 列与 SeachText 模糊搜索
        if (options.Searchs.Any())
        {
            items = items.Where(options.Searchs.GetFilterFunc<Foo>(FilterLogic.Or));
        }

        // 过滤
        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 = options.CustomerSearchs.Any(),
            IsAdvanceSearch = isAdvanceSearch
        });
    }
}

B 站相关视频链接

交流群

QQ Group:BootstrapAdmin & Blazor 795206915 675147445 Welcome to join the group discussion
Themes
Bootstrap
Motronic
Ant Design (完善中)
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 组件库 更新到 6.6.0

首先感谢您对本套组件的关注,本目前本套组件已经拥有超过 120 个组件,本组件是基于 Bootstrap 风格的 Blazor 企业级组件库,提供如布局、导航、表单、数据、通知、图标、语音等几大类通用组件,每一个组件都经过静心设计,具有模块化、响应式和优秀的性能。从更多实际场景出发,满足多种场景的需求,极大的减少开发者时间成本,大大缩短开发周期,大幅提高开发效率,并提供了一套 通用权限管理系统 示例工程。Bootstrap Blazor 产品是由一支专业的全职技术团队进行维护,高效的响应速度,多元化的解决方案,长期提供支持,并提供企业级支持。目前已在多家知名国企内部使用,项目最高在线 1200 人稳定运行。右侧为国内人数最多的中文 Blazor QQ 社区二维码,欢迎扫描加群。

组件更新到 6.6.0 更新日志 [传送门] 如果组件给您带来了方便,请您帮忙给项目点亮 Star github gitee

QQGroup
QQ 795206915