mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-04 13:08:23 +08:00
feat(module: table): add guid built-in filter (#1756)
Co-authored-by: James Yeung <shunjiey@hotmail.com>
This commit is contained in:
parent
fcd594fbe5
commit
4c674d7b3a
@ -251,6 +251,7 @@ else if (IsBody && RowSpan != 0 && ColSpan != 0)
|
||||
<SelectOption TItem="TableFilterCompareOperator" TItemValue="TableFilterCompareOperator" Value="@TableFilterCompareOperator.Contains" Label="@Table?.Locale.FilterOptions.Contains"></SelectOption>
|
||||
<SelectOption TItem="TableFilterCompareOperator" TItemValue="TableFilterCompareOperator" Value="@TableFilterCompareOperator.NotContains" Label="@Table?.Locale.FilterOptions.NotContains"></SelectOption>
|
||||
}
|
||||
else if (_columnDataType == typeof(Guid)) { }
|
||||
else
|
||||
{
|
||||
<SelectOption TItem="TableFilterCompareOperator" TItemValue="TableFilterCompareOperator" Value="@TableFilterCompareOperator.GreaterThan" Label="@Table?.Locale.FilterOptions.GreaterThan"></SelectOption>
|
||||
@ -372,6 +373,10 @@ else if (IsBody && RowSpan != 0 && ColSpan != 0)
|
||||
{
|
||||
<InputNumber Value="(ulong?)filter.Value" Formatter="number => NumberFormatter(number)" TValue="ulong?" ValueChanged="value => SetFilterValue(filter, value)"></InputNumber>
|
||||
}
|
||||
else if (_columnDataType == typeof(Guid))
|
||||
{
|
||||
<Input Value="(Guid?)filter.Value" TValue="Guid?" ValueChanged="value => SetFilterValue(filter, value)" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<Input TValue="TData" Value="(TData)filter.Value" ValueChanged="value => SetFilterValue(filter, value)" />
|
||||
|
@ -12,6 +12,7 @@ namespace AntDesign.FilterExpression
|
||||
private readonly NumberFilterExpression _numberFilter = new NumberFilterExpression(typeof(T));
|
||||
private readonly DateFilterExpression _dateFilter = new DateFilterExpression();
|
||||
private readonly EnumFilterExpression _enumFilter = new EnumFilterExpression();
|
||||
private readonly GuidFilterExpression _guidFilter = new GuidFilterExpression();
|
||||
|
||||
public FilterExpressionResolver()
|
||||
{
|
||||
@ -27,14 +28,19 @@ namespace AntDesign.FilterExpression
|
||||
{
|
||||
return _numberFilter;
|
||||
}
|
||||
if (THelper.GetUnderlyingType<T>() == typeof(DateTime))
|
||||
var underlyingType = THelper.GetUnderlyingType<T>();
|
||||
if (underlyingType == typeof(DateTime))
|
||||
{
|
||||
return _dateFilter;
|
||||
}
|
||||
if (THelper.GetUnderlyingType<T>() == typeof(string))
|
||||
if (underlyingType == typeof(string))
|
||||
{
|
||||
return _stringFilter;
|
||||
}
|
||||
if (underlyingType == typeof(Guid))
|
||||
{
|
||||
return _guidFilter;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
35
components/table/FilterExpression/GuidFilterExpression.cs
Normal file
35
components/table/FilterExpression/GuidFilterExpression.cs
Normal file
@ -0,0 +1,35 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace AntDesign.FilterExpression
|
||||
{
|
||||
public class GuidFilterExpression : IFilterExpression
|
||||
{
|
||||
public TableFilterCompareOperator GetDefaultCampareOperator()
|
||||
{
|
||||
return TableFilterCompareOperator.Equals;
|
||||
}
|
||||
|
||||
public Expression GetFilterExpression(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
|
||||
{
|
||||
switch (compareOperator)
|
||||
{
|
||||
case TableFilterCompareOperator.IsNull:
|
||||
case TableFilterCompareOperator.Equals:
|
||||
return Expression.Equal(leftExpr, rightExpr);
|
||||
case TableFilterCompareOperator.IsNotNull:
|
||||
case TableFilterCompareOperator.NotEquals:
|
||||
return Expression.NotEqual(leftExpr, rightExpr);
|
||||
default:
|
||||
throw new InvalidOperationException($"The compare operator {compareOperator} is not supported for Guid type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
<Table DataSource="data" OnChange="OnChange" TItem="Data">
|
||||
<Column TData="Guid"
|
||||
@bind-Field="context.Id"
|
||||
Sortable
|
||||
Filterable />
|
||||
|
||||
<Column TData="string"
|
||||
@bind-Field="context.Name"
|
||||
SorterCompare="@((a,b)=> string.Compare(a,b))"
|
||||
@ -35,12 +40,14 @@
|
||||
|
||||
@using AntDesign.TableModels;
|
||||
@using System.Text.Json;
|
||||
@using System;
|
||||
@code {
|
||||
|
||||
class Data
|
||||
{
|
||||
public Data(string name, string address, DateTime birthDate, bool isActive, Gender gender, Hobbies? hobbies)
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
Name = name;
|
||||
Address = address;
|
||||
BirthDate = birthDate;
|
||||
@ -49,6 +56,7 @@
|
||||
Hobbies = hobbies;
|
||||
}
|
||||
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Address { get; set; }
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
@ -9,10 +9,10 @@ title:
|
||||
|
||||
当不设置 `Filters` 时,在 `Column` 上使用 `Filterable` 属性也可以显示筛选器,默认会根据绑定的属性类型来创建内置的筛选器。
|
||||
|
||||
内置筛选器是根据绑定属性的类型来展示的,目前支持 数值型、枚举型、`string`、`bool`、`DateTime` 。
|
||||
内置筛选器是根据绑定属性的类型来展示的,目前支持 数值型、枚举型、`string`、`bool`、`Guid`、`DateTime` 。
|
||||
|
||||
## en-US
|
||||
|
||||
When `Filters` is not set, filters can also be displayed using the `Filterable` property on `Column`, which by default creates built-in filters based on the type of property bound.
|
||||
|
||||
The built-in filters are displayed based on the type of the bound property, and currently support numeric, enum, `string`, `bool`, and `DateTime`.
|
||||
The built-in filters are displayed based on the type of the bound property, and currently support numeric, enum, `string`, `bool`, `Guid` and `DateTime`.
|
Loading…
Reference in New Issue
Block a user