Skip to main content

DashboardConfigurator.CustomFilterExpression Event

Allows you to include WHERE clauses into DashboardSqlDataSource queries.

Namespace: DevExpress.DashboardWeb

Assembly: DevExpress.Dashboard.v24.1.Web.dll

NuGet Package: DevExpress.Web.Dashboard.Common

Declaration

public event CustomFilterExpressionWebEventHandler CustomFilterExpression

Event Data

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

Property Description
DashboardId Gets the identifier of the current dashboard.
DataSourceComponentName Get the data source name, used in code to identify the data source’s object, for which the event has been raised. Inherited from CustomFilterExpressionEventArgs.
DataSourceConnectionName Inherited from CustomFilterExpressionEventArgs.
DataSourceName Gets the name of the data source for which the event has been raised. Inherited from CustomFilterExpressionEventArgs.
FilterExpression Gets or sets the filter expression that defines a WHERE clause included in the SQL query. Inherited from CustomFilterExpressionEventArgs.
QueryName Gets the name of the query for which the event was raised. Inherited from CustomFilterExpressionEventArgs.

Remarks

The CustomFilterExpression event fires for each SelectQuery within the SqlDataSource.Queries collection. The e.FilterExpression property allows you to include a WHERE clause into a query at runtime. If a filter is already applied to the SQL query, e.FilterExpression returns the corresponding filter criteria.

For more information on how to create filter criteria as a CriteriaOperator object, refer to the following help article: Simplified Criteria Syntax.

Note

The CustomFilterExpression event is not raised for custom SQL queries and stored procedures.

Example

The following example shows how to handle the DashboardConfigurator.CustomFilterExpression event to apply a dynamic filter for the DashboardSqlDataSource when the Web Dashboard control operates in Designer mode.

e.QueryName
Specifies the name of the query that should be filtered.
e.FilterExpression
Specifies the filter criteria.

View Example: ASP.NET Core

configurator.CustomFilterExpression += (s, e) => {
    var contextAccessor = serviceProvider.GetService<IHttpContextAccessor>();
    var workingMode = contextAccessor.HttpContext.Request.Headers["DashboardWorkingMode"];

    if (e.DashboardId == "SQL" && e.QueryName == "Categories") {
        if (workingMode == "Designer")
            e.FilterExpression = CriteriaOperator.Parse("[Categories.CategoryID] = 1");
    }
};

The code snippet below handles the CustomFilterExpression event and appends a custom filter to the existing filter instead of overriding it:

configurator.CustomFilterExpression += (s, e) => {
    // ...
    if (e.DashboardId == "dashboard1" && e.QueryName == "OrderDetails") {
        var shipCountry = "USA";
        e.FilterExpression = CriteriaOperator.And(e.FilterExpression, CriteriaOperator.Parse("[ShipCountry] = ?", shipCountry));
    }
};

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomFilterExpression event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also