Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to allow end-users to set custom names for grid filters and save/restore these names when a grid layout is saved/restored

$
0
0

When an end-users applies any filter to a grid, this filter is shown in the Filter Panel. When the AllowMRUFilterList property is set to true, recently used filters can be accessed via the View's MRU Filter List. It is a convenient way to access previous filters. Since filters can contain multiple filter conditions, it is not always comfortable to search for a necessary filter in the MRU Filter List. This example illustrates how to provide an end-user with the capability to set custom short names for filters. This way, a custom filter name will be shown in the Filter Panel as well as in the MRU Filter List.

To implement this feature, we have created a custom FilterNameProvider class. Create this class object and pass your GridView to its constructor. Once it is done, set the FilterNameProvider.AllowSettingFilterNames property to true to enable this functionality.

Now, when you right-click a filter text in the Filter Panel, a context menu will be shown. Click the Save Filter As item to invoke FlyoutDialog. In this FlyoutDialog, you can enter a custom filter name for the current filter shown in the Filter Panel.

So, your end-user can now assign custom short names for filters. However, this information will be lost once you save and restore a grid layout. To save custom filter names with the grid layout, we use the XmlXtraSerializer.SerializeObjects method. We pass the current GridView together with a FilterNameProvider object to this method. FilterNameProvider has the GridFilters property of the List<GridFitlerItem> type, which is intended to be serialized. That is why this property is marked with the XtraSerializableProperty attribute. Note that properties of the GridFitlerItem class are also marked with this attribute.

To restore these filters, we use the XmlXtraSerializer.DeserializeObjects method. Since new GridFitlerItem objects will not be created automatically when this method is called, it is necessary to declare a special method at the FilterNameProvider class to allow you to create such objects manually. This method should have a name according to this pattern: “XtraCreate<PropertyName>Item”. That is why we call this method as XtraCreateGridFiltersItem


Viewing all articles
Browse latest Browse all 7205

Trending Articles