Back to Devexpress

DashboardConfigurator.CustomFilterExpression Event

dashboard-devexpress-dot-dashboardweb-dot-dashboardconfigurator-32531fa7.md

latest6.6 KB
Original Source

DashboardConfigurator.CustomFilterExpression Event

Allows you to include WHERE clauses into DashboardSqlDataSource queries.

Namespace : DevExpress.DashboardWeb

Assembly : DevExpress.Dashboard.v25.2.Web.dll

NuGet Package : DevExpress.Web.Dashboard.Common

Declaration

csharp
public event CustomFilterExpressionWebEventHandler CustomFilterExpression
vb
Public Event CustomFilterExpression As CustomFilterExpressionWebEventHandler

Event Data

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

PropertyDescription
DashboardIdGets the identifier of the current dashboard.
DataSourceComponentNameGet the data source name, used in code to identify the data source’s object, for which the event has been raised. Inherited from CustomFilterExpressionEventArgs.
DataSourceConnectionNameInherited from CustomFilterExpressionEventArgs.
DataSourceNameGets the name of the data source for which the event has been raised. Inherited from CustomFilterExpressionEventArgs.
FilterExpressionGets or sets the filter expression that defines a WHERE clause included in the SQL query. Inherited from CustomFilterExpressionEventArgs.
QueryNameGets 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.QueryNameSpecifies the name of the query that should be filtered.e.FilterExpressionSpecifies the filter criteria.

View Example: ASP.NET Core

cs
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:

cs
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.

DashboardDifferentUserDataMVC/CS/MVCDashboard/App_Start/DashboardConfig.cs#L22

csharp
DashboardConfigurator.Default.DataLoading += DashboardConfigurator_DataLoading;
DashboardConfigurator.Default.CustomFilterExpression += DashboardConfigurator_CustomFilterExpression;
DashboardConfigurator.Default.ConfigureDataConnection += DashboardConfigurator_ConfigureDataConnection;

See Also

ASPxDashboard.CustomFilterExpression

DashboardConfigurator Class

DashboardConfigurator Members

DevExpress.DashboardWeb Namespace