protected override void BuildRenderTree(RenderTreeBuilder builder) { base.BuildRenderTree(builder); LoadStateIfExists(); var rendererBuilder = new BlazorRendererTreeBuilder(builder); rendererBuilder .OpenElement(HtmlTagNames.Button, filterIsApplied ? "action-button action-button-small action-button-filter-active" : "action-button action-button-small") .AddAttribute(HtmlJSEvents.OnClick, EventCallback.Factory.Create(this, (MouseEventArgs e) => { filterDefinitionOpened = !filterDefinitionOpened; }) ) .OpenElement(HtmlTagNames.Span) .OpenElement(HtmlTagNames.I, "fas fa-filter") .CloseElement() .CloseElement() .CloseElement(); rendererBuilder.OpenElement(HtmlTagNames.Div, filterDefinitionOpened ? parser != TryParseBool ? $"{WrapperCssClass} {WrapperCssClass}-open" : $"{WrapperCssClass} {WrapperCssClass}-open {WrapperCssCheckboxClass}" : $"{WrapperCssClass}"); if (parser == TryParseBool) { BuildRendererTreeForCheckbox(rendererBuilder); } else { BuildRendererTreeForFilterOperations(rendererBuilder); BuildRendererTreeForInputs(rendererBuilder); } if (parser != TryParseBool) { rendererBuilder.OpenElement(HtmlTagNames.Div, "filter-buttons"); _ = rendererBuilder.OpenElement(HtmlTagNames.Button, "btn btn-light filter-buttons-clear") .AddAttribute(HtmlJSEvents.OnClick, EventCallback.Factory.Create(this, (MouseEventArgs e) => { ClearFilter(); }) ) .AddContent("Clear") .CloseElement() .CloseElement(); } rendererBuilder.CloseElement(); }
private void BuildRendererTreeForFilterOperations(BlazorRendererTreeBuilder rendererBuilder) { rendererBuilder .OpenElement(HtmlTagNames.Select) .AddAttribute(HtmlJSEvents.OnChange, EventCallback.Factory.Create(this, (ChangeEventArgs e) => { selectedFilterOperation = (FilterOperation)BindConverterExtensions.ConvertTo(e.Value, 1); if (filterIsApplied) { filterContext.AddOrUpdateFilterDefinition(new ExpressionFilterDefinition( ColumnName, selectedFilterOperation, actualFilterValue, TextComparison)); } })); foreach (var enumValue in Enum.GetValues(typeof(FilterOperation))) { var filterOperation = (FilterOperation)enumValue; if (!allowedFilterOperations.HasFlag(filterOperation) || filterOperation == FilterOperation.None) { continue; } selectedFilterOperation = selectedFilterOperation == FilterOperation.None ? filterOperation : selectedFilterOperation; var enumStringValue = enumValue.ToString(); rendererBuilder.OpenElement(HtmlTagNames.Option); if (enumStringValue == selectedFilterOperation.ToString()) { rendererBuilder.AddAttribute(HtmlAttributes.Selected, true); } rendererBuilder .AddAttribute(HtmlAttributes.Value, (int)enumValue) .AddContent(enumStringValue) .CloseElement(); } rendererBuilder.CloseElement(); }
private void BuildRendererTreeForFilterOperations(BlazorRendererTreeBuilder rendererBuilder) { rendererBuilder .OpenElement(HtmlTagNames.Select) .AddAttribute(HtmlJSEvents.OnChange, BindMethods.SetValueHandler(delegate(int __value) { selectedFilterOperation = (FilterOperation)__value; if (filterIsApplied) { filterContext.AddOrUpdateFilterDefinition(new ExpressionFilterDefinition(ColumnName, selectedFilterOperation, actualFilterValue)); } }, (int)selectedFilterOperation)); foreach (var enumValue in Enum.GetValues(typeof(FilterOperation))) { var filterOperation = (FilterOperation)enumValue; if (!allowedFilterOperations.HasFlag(filterOperation) || filterOperation == FilterOperation.None) { continue; } selectedFilterOperation = selectedFilterOperation == FilterOperation.None ? filterOperation : selectedFilterOperation; var enumStringValue = enumValue.ToString(); rendererBuilder.OpenElement(HtmlTagNames.Option); if (enumStringValue == selectedFilterOperation.ToString()) { rendererBuilder.AddAttribute(HtmlAttributes.Selected, true); } rendererBuilder .AddAttribute(HtmlAttributes.Value, (int)enumValue) .AddContent(enumStringValue) .CloseElement(); } rendererBuilder.CloseElement(); }