mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-03 12:37:40 +08:00
fix(module: table): fix nullable built-in DateTime filter (#1964)
* fix(module:table): fix nullable date-time built-in filter * Update DateFilterExpression.cs * Update DateFilterExpression.cs * Update DateFilterExpression.cs
This commit is contained in:
parent
0e40f1bd03
commit
97d1ec43d9
@ -18,14 +18,57 @@ namespace AntDesign.FilterExpression
|
||||
}
|
||||
public Expression GetFilterExpression(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
|
||||
{
|
||||
leftExpr = RemoveMilliseconds(leftExpr);
|
||||
rightExpr = RemoveMilliseconds(rightExpr);
|
||||
switch (compareOperator)
|
||||
{
|
||||
case TableFilterCompareOperator.IsNull:
|
||||
case TableFilterCompareOperator.Equals:
|
||||
return Expression.Equal(leftExpr, rightExpr);
|
||||
case TableFilterCompareOperator.IsNotNull:
|
||||
return Expression.NotEqual(leftExpr, rightExpr);
|
||||
}
|
||||
|
||||
if (leftExpr.Type.IsGenericType)
|
||||
{
|
||||
Expression notNull = Expression.NotEqual(leftExpr, Expression.Constant(null));
|
||||
Expression isNull = Expression.Equal(leftExpr, Expression.Constant(null));
|
||||
leftExpr = Expression.Property(leftExpr, "Value");
|
||||
rightExpr = Expression.Property(rightExpr, "Value");
|
||||
if (compareOperator != TableFilterCompareOperator.TheSameDateWith)
|
||||
{
|
||||
leftExpr = RemoveMilliseconds(leftExpr);
|
||||
}
|
||||
|
||||
switch (compareOperator)
|
||||
{
|
||||
case TableFilterCompareOperator.Equals:
|
||||
return Expression.AndAlso(notNull, Expression.Equal(leftExpr, rightExpr));
|
||||
case TableFilterCompareOperator.NotEquals:
|
||||
return Expression.OrElse(isNull, Expression.NotEqual(leftExpr, rightExpr));
|
||||
case TableFilterCompareOperator.GreaterThan:
|
||||
return Expression.AndAlso(notNull, Expression.GreaterThan(leftExpr, rightExpr));
|
||||
case TableFilterCompareOperator.GreaterThanOrEquals:
|
||||
return Expression.AndAlso(notNull, Expression.GreaterThanOrEqual(leftExpr, rightExpr));
|
||||
case TableFilterCompareOperator.LessThan:
|
||||
return Expression.AndAlso(notNull, Expression.LessThan(leftExpr, rightExpr));
|
||||
case TableFilterCompareOperator.LessThanOrEquals:
|
||||
return Expression.AndAlso(notNull, Expression.LessThanOrEqual(leftExpr, rightExpr));
|
||||
case TableFilterCompareOperator.TheSameDateWith:
|
||||
return Expression.AndAlso(notNull,
|
||||
Expression.Equal(
|
||||
Expression.Property(leftExpr, "Date"),
|
||||
Expression.Property(rightExpr, "Date")));
|
||||
}
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
if (compareOperator != TableFilterCompareOperator.TheSameDateWith)
|
||||
{
|
||||
leftExpr = RemoveMilliseconds(leftExpr);
|
||||
}
|
||||
|
||||
switch (compareOperator)
|
||||
{
|
||||
case TableFilterCompareOperator.Equals:
|
||||
return Expression.Equal(leftExpr, rightExpr);
|
||||
case TableFilterCompareOperator.NotEquals:
|
||||
return Expression.NotEqual(leftExpr, rightExpr);
|
||||
case TableFilterCompareOperator.GreaterThan:
|
||||
@ -37,8 +80,9 @@ namespace AntDesign.FilterExpression
|
||||
case TableFilterCompareOperator.LessThanOrEquals:
|
||||
return Expression.LessThanOrEqual(leftExpr, rightExpr);
|
||||
case TableFilterCompareOperator.TheSameDateWith:
|
||||
return Expression.Equal(Expression.Property(leftExpr, "Date"),
|
||||
Expression.Property(rightExpr, "Date"));
|
||||
return Expression.Equal(
|
||||
Expression.Property(leftExpr, "Date"),
|
||||
Expression.Property(rightExpr, "Date"));
|
||||
}
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user