Back to Devexpress

Filter Control

aspnet-120663-aspnet-mvc-extensions-data-editors-extensions-filter-control.md

latest2.5 KB
Original Source

Filter Control

  • Dec 10, 2020
  • 2 minutes to read

The FilterControlExtension allows end users to build complex filter criteria with an unlimited number of filter conditions, combined by logical operators, and apply them to extensions or data models.

Features

  • Custom Appearance

  • Filter Expression Validation

  • Client-Side APIs

Implementation

Use the FilterControl(MVCxFilterControlSettings) helper method to add the Filter Control (FilterControlExtension) extension to a view. The FilterControl(MVCxFilterControlSettings) method’s parameter provides access to the filter control’s settings (MVCxFilterControlSettings).

Declaration

The following code adds the filter control to a view.

View code (ASPX):

aspx
@{
    Html.DevExpress().GridView<Product>(settings => {
        settings.Name = "grid";
        settings.CallbackRouteValues = new { Controller = "Editors", Action = "FilterControl_GridPartial" };
        settings.Width = Unit.Percentage(100);

        settings.Columns.Add(c => c.ProductName);
        settings.Columns.Add(c => {
            c.FieldName = "CategoryID";
            c.Caption = "CategoryName";
        });

        settings.Columns.Add(c => c.Supplier.CompanyName);
        ...
    }).Bind(Model).Render();
}

View code (Razor):

csharp
@{
    Html.DevExpress().GridView<Product>(settings => {
        settings.Name = "grid";
        settings.CallbackRouteValues = new { Controller = "Editors", Action = "FilterControl_GridPartial" };
        settings.Width = Unit.Percentage(100);

        settings.Columns.Add(c => c.ProductName);
        settings.Columns.Add(c => {
            c.FieldName = "CategoryID";
            c.Caption = "CategoryName";
        });

        settings.Columns.Add(c => c.Supplier.CompanyName);
        ...
    }).Bind(Model).GetHtml();
}

Note

The Partial View should contain only the extension’s code.

Online Demo

Filter Control Extension - Features