Tab
A newer version of this page is available. Switch to the current version.

GridViewColumn.FilterTemplate Property

Gets or sets a template for displaying the filter row cell.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v18.2.dll

Declaration

[DefaultValue(null)]
public virtual ITemplate FilterTemplate { get; set; }
<DefaultValue(Nothing)>
Public Overridable Property FilterTemplate As ITemplate

Property Value

Type Default Description
ITemplate

null

An object that implements the ITemplate interface.

Remarks

Once a template defined via the FilterTemplate property is created within a control, it is instantiated within a container object of the GridViewFilterCellTemplateContainer type. This container object exposes a set of specific properties to which the template's child controls can be bound.

To provide a common template for displaying cells of a header filter, use the GridViewTemplates.FilterCell property.

Examples

In some cases, when the default filter row editor's functionality is not enough, you can provide custom filter cell content using the GridViewColumn.FilterTemplate.

In this example, a default cell editor is replaced with the ASPxGridLookup control. The control's ASPxClientEdit.ValueChanged client-side event is used to send a callback to the server side, invoking the grid's ASPxGridView.CustomCallback event. In the event handler, a filter criteria is created and applied to the grid using the ASPxGridView.ApplyFilterToColumn method.

using DevExpress.Data.Filtering;
using DevExpress.Web.ASPxGridLookup;
using DevExpress.Web.ASPxGridView;

public partial class _Default : System.Web.UI.Page {
    protected void Grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
        if(e.Parameters == "FilterByCategories") {
            var column = Grid.DataColumns["CategoryName"];
            var lookup = Grid.FindFilterCellTemplateControl(column, "Lookup") as ASPxGridLookup;
            if(lookup != null)
                Grid.ApplyFilterToColumn(column, CreateCriteria(lookup, column.FieldName));
        }
    }

    protected CriteriaOperator CreateCriteria(ASPxGridLookup gridLookup, string fieldName) {
        var values = gridLookup.GridView.GetSelectedFieldValues(fieldName);
        return values.Count > 0 ? new InOperator(fieldName, values) : null;
    }
}