Databases Reference
In-Depth Information
public class FilterFactory
{
public FilterFactory();
public virtual QueryableFilterUserControl CreateFilterControl (
MetaColumn column, string filterUIHint);
public virtual string GetFilterVirtualPath (
MetaColumn column, string filterUIHint);
}
The GetFilterVirtualPath method is responsible for determining a virtual path to
a filter template, such as ~\DynamicData\Filters\Text.ascx , that matches the given
MetaColumn object and filterUIHint . The column contains metadata information
describing the entity property, and the filter hint comes from the page markup. The
CreateFilterControl is invoked by the DynamicFilter (or, in our case, the
UnleashedFilter ) control to create an instance of the filter template. Internally, the
CreateFilterControl calls the GetFilterVirtualPath method and caches its results to
improve performance for subsequent lookups of the same column and hint combination.
Therefore, you need to override only the GetFilterVirtualPath method and can leave the
CreateFilterControl method as is.
Listing 13.1 shows the complete implementation of UnleashedFilterFactory , a class that
extends the built-in FilterFactory to implement fallback-based algorithm for filter
template lookup. As you can see, it overrides the GetFilterVirtualPath method just
discussed; however, most of the heavy lifting is actually done by the GetFilterCandidates
method. This method returns an IEnumerable of strings where each item is a possible
name of the filter template, based on the given MetaColumn and filter hint. The
GetFilterVirtualPath method tries the candidate names until it finds an existing .ASCX
file in the DynamicData\Filters folder of the project. If none of the candidate names
matches an existing filter template, the GetFilterVirtualPath calls the base method,
inherited from the FilterFactory , to handle the Boolean, ForeignKey, and Enumeration
filter templates it supports.
LISTING 13.1 UnleashedFilterFactory Implementation
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Compilation;
using System.Web.DynamicData;
namespace Unleashed.DynamicData
{
public class UnleashedFilterFactory : FilterFactory
{
private static readonly Dictionary<Type, Type> FallbackTypes =
new Dictionary<Type, Type>
{
 
Search WWH ::




Custom Search