Databases Reference
In-Depth Information
the default implementation of the MetaTable cannot take advantage of it automatically.
To work around this shortcoming, the built-in MetaTable has to be extended to override
the GetFilteredColumns method. Listing 13.2 shows the complete implementation of the
UnleashedMetaTable from the Unleashed.DynamicData project of the sample solution.
LISTING 13.2 UnleashedMetaTable Implementation
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
using System.Web.UI.WebControls;
namespace Unleashed.DynamicData
{
public class UnleashedMetaTable : MetaTable
{
public UnleashedMetaTable(UnleashedMetaModel model, TableProvider provider)
: base(model, provider)
{
}
public override IEnumerable<MetaColumn> GetFilteredColumns()
{
return this.GetScaffoldColumns(
DataBoundControlMode.ReadOnly, ContainerType.List)
.Where(column => IsFilterable(column));
}
private bool IsFilterable(MetaColumn column)
{
if (!string.IsNullOrEmpty(column.FilterUIHint)) return true;
DisplayAttribute display = column.Attributes.OfType<DisplayAttribute>()
.FirstOrDefault();
if (display != null && display.GetAutoGenerateFilter().HasValue)
return display.GetAutoGenerateFilter().Value;
if (column.IsCustomProperty) return false;
if (column is MetaChildrenColumn) return false;
return true;
}
}
}
Search WWH ::




Custom Search