Sync date filter UI with filter criteria in BandGridBase

Added logic to synchronize the date filter UI with the current
filter criteria by updating _filterFrom and _filterTo based on
the CriteriaOperator. Introduced SyncDateFilterFromContext and
ParseDateOperand helpers to extract and apply "from" and "to"
date values, ensuring UI and filter state remain consistent.
This commit is contained in:
OlgunR
2026-05-11 10:27:13 +02:00
parent f0259e3f78
commit 1112fa215c

View File

@@ -257,6 +257,7 @@ public abstract class BandGridBase<TItem> : ComponentBase
ctx => b =>
{
_filterContexts[fieldName] = ctx;
SyncDateFilterFromContext(fieldName, ctx.FilterCriteria);
int s = 0;
b.OpenElement(s++, "div");
b.AddAttribute(s++, "class", "date-filter-menu p-2");
@@ -296,6 +297,39 @@ public abstract class BandGridBase<TItem> : ComponentBase
b.CloseElement();
};
private void SyncDateFilterFromContext(string fieldName, CriteriaOperator? criteria)
{
if (criteria == null)
{
_filterFrom[fieldName] = null;
_filterTo[fieldName] = null;
return;
}
DateTime? from = null;
DateTime? to = null;
if (criteria is GroupOperator group)
{
foreach (var op in group.Operands.OfType<BinaryOperator>())
ParseDateOperand(op, ref from, ref to);
}
else if (criteria is BinaryOperator binary)
{
ParseDateOperand(binary, ref from, ref to);
}
_filterFrom[fieldName] = from;
_filterTo[fieldName] = to;
}
private static void ParseDateOperand(BinaryOperator op, ref DateTime? from, ref DateTime? to)
{
if (op.RightOperand is not OperandValue val || val.Value is not DateTime dt) return;
if (op.OperatorType == BinaryOperatorType.GreaterOrEqual) from = dt;
else if (op.OperatorType == BinaryOperatorType.Less) to = dt.AddDays(-1);
}
private void OnFilterFromChanged(string fieldName, DateTime? value)
{
_filterFrom[fieldName] = value;