Skip to main content
All docs
V25.1
  • DxPivotTable.SetFilterCriteria(String) Method

    Applies a filter to Pivot Table data.

    Namespace: DevExpress.Blazor.PivotTable

    Assembly: DevExpress.Blazor.PivotTable.v25.1.dll

    NuGet Package: DevExpress.Blazor.PivotTable

    Declaration

    public void SetFilterCriteria(
        string criteria
    )

    Parameters

    Name Type Description
    criteria String

    A string that specifies the filter expression.

    Remarks

    The DevExpress Blazor Pivot Table component allows you to apply filters in the UI and in code.

    Call the SetFilterCriteria(string criteria) method to filter Pivot Table data in code. Pass a filter expression to this method. When you call this method, the Pivot Table clears any applied filters. You can filter Pivot Table data by every data source field, including fields that are not displayed in the Pivot Table.

    You can also use the SetFilterCriteria(CriteriaOperator criteria) method to apply filters.

    Related API members:

    FilterCriteriaChanged
    Fires when filter criteria applied to Pivot Table data changes.
    GetFilterCriteria()
    Returns the filter criteria applied to Pivot Table data.
    ClearFilter()
    Clears all filter criteria applied to Pivot Table data.

    The following code adds a toolbar that allows you to specify a filter for Pivot Table data (Region = “North America”) and clear the filter. The code also gets the filter criteria and displays it under the Pivot Table.

    @rendermode InteractiveServer
    @using Services
    @using DevExpress.Data.Filtering
    
    <DxToolbar ItemClick="@OnItemClick">
        <Items>
            <DxToolbarItem Name="_setFilterCriteria" Text="Set Filter Criteria" Tooltip="Set Filter Criteria" />
            <DxToolbarItem Name="_clearFilterCriteria" Text="Clear Filter Criteria" Tooltip="Clear Filter Criteria" />
        </Items>
    </DxToolbar>
    <br />
    
    <DxPivotTable Data="SalesData" @ref="PivotTable">
        <Fields>
            <DxPivotTableField Field="@nameof(Sales.SaleInfo.Region)"
                               Area="@PivotTableArea.Row"
                               AreaIndex="0" />
            <DxPivotTableField Field="@nameof(Sales.SaleInfo.Country)"
                               Area="@PivotTableArea.Row"
                               SortOrder="@PivotTableSortOrder.Descending"
                               AreaIndex="1" />
            <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                               GroupInterval="@PivotTableGroupInterval.DateYear"
                               Area="@PivotTableArea.Column"
                               AreaIndex="0"
                               Caption="Year" />
            <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                               GroupInterval="@PivotTableGroupInterval.DateQuarter"
                               Area="@PivotTableArea.Column"
                               AreaIndex="1"
                               Caption="Quarter" />
            <DxPivotTableField Field="@nameof(Sales.SaleInfo.Amount)"
                               SortOrder="@PivotTableSortOrder.Ascending"
                               Area="@PivotTableArea.Data"
                               SummaryType="@PivotTableSummaryType.Sum" />
        </Fields>
    </DxPivotTable>
    
    <p class="cw-480 mt-3">
        Filter Criteria: <b>@PivotTable?.GetFilterCriteria()?.ToString()</b>
    </p>
    
    @code {
        IEnumerable<Sales.SaleInfo> SalesData;
        protected override async Task OnInitializedAsync() {
            SalesData = await Sales.GetSalesAsync();
        }
    
        IPivotTable PivotTable { get; set; }
        void OnItemClick(ToolbarItemClickEventArgs e) {
            switch (e.ItemName) {
                case "_setFilterCriteria":
                    var regionField = pivot.GetFields().FirstOrDefault(f => f.Field === "Region");
                    PivotTable.SetFilterCriteria($"[{regionField.FilterFieldName}]='North America'");
                    break;
                case "_clearFilterCriteria":
                    PivotTable.ClearFilter();
                    break;
            }
        }
    }
    

    Pivot Table - Filter API

    See Also