Skip to main content
Tab

ASPxGridView.ProcessColumnAutoFilter Event

Enables you to apply custom filter criteria when filter row is in the Auto mode.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public event ASPxGridViewAutoFilterEventHandler ProcessColumnAutoFilter

Event Data

The ProcessColumnAutoFilter event's data class is ASPxGridViewAutoFilterEventArgs. The following properties provide information specific to this event:

Property Description
Column Gets the data column to be filtered.
Criteria Gets the applied filter criteria. Inherited from GridAutoFilterEventArgs.
Kind Gets a value specifying which action should be performed within the corresponding event handler. Inherited from GridAutoFilterEventArgs.
Value Gets or sets a value that is the custom text displayed within the filter row cell. Inherited from GridAutoFilterEventArgs.

Remarks

End-users can build simple filter criteria and apply them using the Filter Row, which can work in either Auto or OnClick mode (based on the ASPxGridViewBehaviorSettings.FilterRowMode property value). When the filter works in Auto mode, you can use the ProcessColumnAutoFilter event handler to perform any actions before the filter criterion is applied.

This event is raised twice and enables you to perform the following actions.

  • Provide custom filter criteria.
  • Specify text displayed within the auto-filter row cell.

When the event parameter’s GridAutoFilterEventArgs.Kind property returns GridViewAutoFilterEventKind.CreateCriteria, you can provide custom filter criteria with the GridAutoFilterEventArgs.Criteria property.

Note

When handling the ProcessColumnAutoFilter event, you should apply filter criteria only to the column that is filtered.

When the GridAutoFilterEventArgs.Kind property returns GridViewAutoFilterEventKind.ExtractDisplayText, you can provide custom text displayed within the filter row cell with the GridAutoFilterEventArgs.Value property.

In the OnClick mode, use the ASPxGridView.ProcessOnClickRowFilter event handler to perform any actions before the filter criteria are applied.

Online Examples

View Example: How to filter a date column by both date and time

View Example: How to apply custom function filter criteria operators

Example

In this example, the ASPxGridView.ProcessColumnAutoFilter event is handled to allow end-users to filter employees by the year of birth.

Since the BirthDate column displays DateTime values, the DateTime editor is used to specify the filter criteria. To allow end-users to only enter the year, the default editor is replaced with the text editor within the ASPxGridView.AutoFilterCellEditorCreate event handler.

The image below shows the result:

ProcessColumnAutoFilter

using DevExpress.Web.ASPxEditors;
using DevExpress.Data.Filtering;

protected void ASPxGridView1_ProcessColumnAutoFilter(object sender,
    DevExpress.Web.ASPxGridViewAutoFilterEventArgs e) {
    if(e.Column != ASPxGridView1.Columns["BirthDate"]) return;

    if (e.Kind == DevExpress.Web.GridViewAutoFilterEventKind.CreateCriteria) {
        // Creates a new filter criterion and applies it.
        e.Criteria = null;
        int year;
        if (!int.TryParse(e.Value, out year)) return;
        e.Criteria = (new OperandProperty("BirthDate") >= new DateTime(year, 1, 1)) &
                          (new OperandProperty("BirthDate") < new DateTime(year + 1, 1, 1));
    }
    else {
        DateTime res;
        if (!DateTime.TryParse(e.Value, out res)) {
            e.Value = string.Empty;
        }
        else {
            // Specifies the text displayed within the auto-filter row cell.
            e.Value = res.Year.ToString();
        }
    }
}
protected void ASPxGridView1_AutoFilterCellEditorCreate(object sender,
     DevExpress.Web.ASPxGridViewEditorCreateEventArgs e) {

    // Replaces the default editor used to edit DateTime values with the text editor.
if (e.Column == ASPxGridView1.Columns["BirthDate"]) e.EditorProperties = new TextBoxProperties();
}
See Also