Skip to main content
.NET 6.0+

How to: Filter Large List Views With Auto Filter Row

  • 3 minutes to read

This topic demonstrates how to use the Auto Filter Row functionality to prevent a grid control from displaying an entire List View collection in ASP.NET Core Blazor and Windows Forms applications.

Imagine a List View bound to a database table with a large amount of data. When a grid control contains millions of records, users often do not need to display this data even if virtual paging is enabled for better performance and usability. Instead, they need an application to initially display an empty List View and allow them to filter or search data on demand. All users can benefit from this design, since it reduces the database server and network load because the application does not need to retrieve large amounts of data from the database.

Step-by-Step Instructions

  1. In the YourSolutionName.Module project, invoke the Model Editor and navigate to the required Views | <ListView> node.

  2. Set the IModelListViewShowAutoFilterRow.ShowAutoFilterRow property to true and the IModelListView.DataAccessMode property to Server.

  3. In Solution Explorer, navigate to:

    • A platform-specific project in a .NET 6+ Windows Forms or ASP.NET Core Blazor application.
    • A platform-specific module project in a Windows Forms application.
  4. Add a View Controller to the Controllers folder.

  5. Inherit the Controller from the ObjectViewController<ViewType, ObjectType> class and override the OnViewControlsCreated method as demonstrated in the following code example:

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Blazor.Editors;
    using DevExpress.Data.Filtering;
    using Microsoft.AspNetCore.Components;
    using DevExpress.Blazor;
    using YourApplicationName.Module.BusinessObjects;
    
    namespace YourApplicationName.Blazor.Server.Controllers;
    
    public class BlazorAutoFilterRowController : ObjectViewController<ListView, TargetClassName> {
        private const string FalseCriteriaKey = "FalseCriteria";
        private CriteriaOperator FalseCriteria = CriteriaOperator.Parse("1=0");
    
        protected override void OnViewControlsCreated() {
            base.OnViewControlsCreated();
            if (View.Editor is DxGridListEditor gridListEditor) {
                IDxGridAdapter dataGridAdapter = gridListEditor.GetGridAdapter();
                View.CollectionSource.Criteria[FalseCriteriaKey] = FalseCriteria;
                dataGridAdapter.GridModel.FilterCriteriaChanged = 
                EventCallback.Factory.Create<GridFilterCriteriaChangedEventArgs>(this, args => {
                    if (ReferenceEquals(args.FilterCriteria, null)) {
                        View.CollectionSource.Criteria[FalseCriteriaKey] = FalseCriteria;
                    }
                    else if (View.CollectionSource.Criteria.ContainsKey(FalseCriteriaKey)) {
                        View.CollectionSource.Criteria.Remove(FalseCriteriaKey);
                    }
                });
            }
        }
    }
    

    If you did not specify criteria to filter List View data, the grid control retrieves all existing objects. To prevent this behavior, set a false criterion for the List View’s Collection Source.

  6. Run the application. The List View with enabled Auto Filter Row should not display any objects.

    ASP.NET Core Blazor
    Auto Filter Row with False Criteria in ASP.NET Core Blazor, DevExpress
    Windows Forms
    Auto Filter Row with False Criteria in Windows Forms, DevExpress
See Also