GridViewColumn.FilterTemplate Property
Specifies a template to display the column’s filter row cell.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
Property Value
Type | Default | Description |
---|---|---|
ITemplate | null | An object that implements the ITemplate interface. |
Remarks
Set the ShowFilterRow property to true
to show the filter row.
When you specify the FilterTemplate
property, the control creates a template within a container object of the GridViewFilterCellTemplateContainer type.
At the control level, use the GridViewTemplates.FilterRow or GridViewTemplates.FilterCell property to create a template for the filter row or a filter row cell.
Example
In the example below, the filter row cell template contains the ASPxGridLookup control.
Create a custom filter criteria and use the ApplyFilterToColumn(GridViewDataColumn, CriteriaOperator) method to apply this filter to the grid.
<dx:ASPxGridView runat="server" ID="Grid" AutoGenerateColumns="False" DataSourceID="ProductsDataSource"
ClientInstanceName="grid" OnCustomCallback="Grid_CustomCallback" EnableViewState="false">
<Columns>
<dx:GridViewDataTextColumn FieldName="CategoryName">
<FilterTemplate>
<dx:ASPxGridLookup runat="server" ID="Lookup" AutoGenerateColumns="False" DataSourceID="CategoriesDataSource"
KeyFieldName="CategoryID" SelectionMode="Multiple" TextFormatString="{0}">
<Columns>
<dx:GridViewCommandColumn ShowSelectCheckbox="true" />
<dx:GridViewDataTextColumn FieldName="CategoryName" />
<dx:GridViewDataBinaryImageColumn FieldName="Picture">
<PropertiesBinaryImage ImageWidth="48" />
</dx:GridViewDataBinaryImageColumn>
</Columns>
<ClientSideEvents ValueChanged="Lookup_ValueChanged" />
</dx:ASPxGridLookup>
</FilterTemplate>
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="ProductName" />
<dx:GridViewDataTextColumn FieldName="ProductSales" />
<dx:GridViewDataDateColumn FieldName="ShippedDate" />
</Columns>
<Settings ShowFilterRow="true" />
</dx:ASPxGridView>
function Lookup_ValueChanged(s, e) {
grid.PerformCallback("FilterByCategories");
}
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;
}