blazor-devexpress-dot-blazor-dot-dxgrid-11cf6fab.md
Opens the filter builder dialog.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public void ShowFilterBuilder()
The filter builder dialog is a centralized viewer/editor for Grid component’s filter conditions. Users can edit and combine filter criteria applied to any number of columns, all within the same window.
Read Tutorial: Filter Panel and Filter Builder Run Demo: Filter Builder Customization
To open this dialog, users can click the current filter region in the filter panel. Call the ShowFilterBuilder method to open this dialog from code.
The following code snippet creates a toolbar button that opens the filter builder dialog:
@inject NwindDataService NwindDataService
<DxGrid @ref="Grid"
Data="Data"
FilterMenuButtonDisplayMode="GridFilterMenuButtonDisplayMode.Always"
FilterPanelDisplayMode="GridFilterPanelDisplayMode.Always">
<Columns>
<DxGridDataColumn FieldName="SalesPerson" Caption="Salesperson" />
<DxGridBandColumn Caption="Order">
<Columns>
<DxGridDataColumn FieldName="CompanyName" />
<DxGridDataColumn FieldName="OrderDate" Caption="Date" />
<DxGridBandColumn Caption="Product">
<Columns>
<DxGridDataColumn FieldName="ProductName" Caption="Name" />
<DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c"
CaptionAlignment="GridTextAlignment.Right" />
</Columns>
</DxGridBandColumn>
<DxGridDataColumn FieldName="Quantity" />
</Columns>
</DxGridBandColumn>
</Columns>
<ToolbarTemplate>
<DxToolbar ItemRenderStyleMode="ToolbarRenderStyleMode.Contained">
<Items>
<DxToolbarItem Alignment="ToolbarItemAlignment.Right"
Text="Filter Builder" RenderStyle="ButtonRenderStyle.Secondary"
Click="() => Grid.ShowFilterBuilder()" />
</Items>
</DxToolbar>
</ToolbarTemplate>
</DxGrid>
@code {
object Data { get; set; }
IGrid Grid { get; set; }
protected override async Task OnInitializedAsync() {
var invoices = await NwindDataService.GetInvoicesAsync();
var customers = await NwindDataService.GetCustomersAsync();
Data = invoices.OrderBy(i => i.OrderDate).Join(customers, i => i.CustomerId, c => c.CustomerId,
(i, c) => { return new {
CompanyName = c.CompanyName,
SalesPerson = i.Salesperson,
UnitPrice = i.UnitPrice,
OrderDate = i.OrderDate,
ProductName = i.ProductName,
Quantity = i.Quantity
};
});
}
protected override Task OnAfterRenderAsync(bool firstRender) {
if (firstRender)
Grid.SetFilterCriteria(CriteriaOperator.Parse("[UnitPrice] > 100M" +
"And ([SalesPerson] In ('Robert King', 'Andrew Fuller')" +
"Or [CompanyName] == 'Ernst Handel')"));
return base.OnAfterRenderAsync(firstRender);
}
}
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace BlazorDemo.Data.Northwind {
public class Invoice {
public string ShipName { get; set; }
public string ShipAddress { get; set; }
public string ShipCity { get; set; }
public string ShipRegion { get; set; }
public string ShipPostalCode { get; set; }
public string ShipCountry { get; set; }
public string CustomerId { get; set; }
public string CustomerName { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Salesperson { get; set; }
public int OrderId { get; set; }
public DateTime? OrderDate { get; set; }
public DateTime? RequiredDate { get; set; }
public DateTime? ShippedDate { get; set; }
public string ShipperName { get; set; }
public int ProductId { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public short Quantity { get; set; }
public float Discount { get; set; }
public decimal? ExtendedPrice { get; set; }
public decimal? Freight { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace BlazorDemo.Data.Northwind {
public partial class Customer {
public Customer() {
Orders = new HashSet<Order>();
}
public string CustomerId { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BlazorDemo.Data.Northwind;
using BlazorDemo.DataProviders;
namespace BlazorDemo.Services {
public partial class NwindDataService {
public Task<IEnumerable<Invoice>> GetInvoicesAsync(CancellationToken ct = default) {
// Return your data here
}
public Task<IEnumerable<Customer>> GetCustomersAsync(CancellationToken ct = default) {
// Return your data here
}
}
}
// ...
builder.Services.AddScoped<NwindDataService>();
See Also