Scenario:
When a user executes a navigation item that displays a large ListView, the application should display a popup window that allows you to define a filter for this ListView before loading records in it. This filter dialog should remember the user's choice and provide the capability to select one of the stored filters.
Steps to implement:
1. Create a ListView model extender - IModelListViewExt - that adds the AdditionalCriteria property to the ListView model to store the filter selected by the user.
2. Implement the ViewFilterContainer class whose DetailView is used as a filter dialog.
3. Implement the ViewFilterObject class which is used to store filters.
4. Implement the ShowFilterDialogController which shows the filter dialog instead of displaying the ListView, and then shows the filtered ListView. To do this, subscribe to the ShowNavigationItemController.ShowNavigationItemAction.Execute event and replace the ListView from the e.ShowViewParameters.CreatedView property with the ViewFilterContainer DetailView. Then show the filtered ListView via the XafApplication.MainWindow.SetView method.
5. Implement the NewViewFilterObjectController which sets the ObjectType property of the ViewFilterObject object created by the ViewFilterContainer.Filter lookup's New action.
See Also:
How to: Use Criteria Property Editors
How to: Extend the Application Model and Schema
ShowNavigationItemController Class
Dialog Controller
Question Comments
Added By: Pablo Mazaeda 1 at: 11/13/2012 6:21:47 AM
how do I do this for ASP.NET?
Added By: Mandeep Singh 10 at: 2/16/2014 6:57:38 AMTried to download this Example. Returns the following error
Server Error in '/Support/Center' Application.
Added By: Anatol (DevExpress Support) at: 2/16/2014 11:49:17 PMThis was likely a temporary issue. Please try to download the example once again.
Added By: Wieland Voß at: 3/4/2014 1:16:39 AMHi Anatol,
how do we implement this solution for the asp.net environment? Simply importing DevExpress.ExpressApp.Web in ViewFilterContainerDetailViewController doesn't seem to meet our needs, since LookupPropertyEditor and LookupEdit are unknown.
Thank you
Wieland
I have updated the example. Now its code is platform-independent and will work correctly in the ASP.NET project.
Added By: Wieland Voß at: 3/5/2014 7:32:50 AMThank you for your quick answer!
The implementation works fine, but ,unfortunately, is way too slow in web-modus :(
It seems, that the generation of large lookup-lists (millions) during filter-creation takes a lot of time. Do you have any hint, how to prevent this behaviour?
This is working great, but everytime I click a navigation item it creates a new "Default" filter. I'm using Web Application, would this matter?
Added By: Leandro Meneses 1 at: 9/21/2014 8:25:11 PMHi i need filter only one listview, solutio apply for all views. thanks
Added By: Anatol (DevExpress Support) at: 9/24/2014 7:36:47 AM Wieland, I have not reproduced any performance issue in ASP.NET applications. I have checked SQL queries sent by this example. When a navigation item is clicked, records from the ListView that is about to be displayed are not loaded until the filter dialog is closed. So, please provide a sample project reproducing the issue.Mauro, the Default filter can be created several times in ASP.NET, because the AdditionalCriteria value stored in the View model is not stored between sessions. To solve this issue, either store the selected filter in the database rather than in the Application Model, or configure your application to store all model differences in the database, as shown in the following example: How to: Store Model Differences in Database.
Leandro, you can check the Id of the created view in the ShowNavigationItemAction_Execute event handler and show the filter dialog only for the required ListView.Added By: Mauro Assis at: 10/22/2014 6:54:34 AM
I've got irt working now. I changed 1st line of GetFilterObject method in ShowFilterDialogController to:
CriteriaOperator criteria = CriteriaOperator.Parse("ObjectType = ?", objectType);
Because ASP.NET won't store last criteria used. But I have another request though. Now I want a Delete button to appear (like this <https://drive.google.com/file/d/0B1OV0NgtiOaXMTFkS19YaDdjRm8/view?usp=sharing>) in the dialog, allowing to delete a filter. Currently it shows only "New" and "Clear".