I am disabling the dynamic filter dropdowns on some of the pages of my dynamic data app to improve performance (some of the tables are quite large). I am doing it in the meta-data with the following:
<Filter(Enabled:=False)>
However, when I do this, it also disables the filtering that occurs when I click through from a foreign key. Is there a good way to disable the dropdowns to save loading them without disabling the click through filtering?
[AttributeUsage(AttributeTargets.Property)]
public class HideFilterInDefaultAttribute : Attribute
{
public Boolean Hide { get; private set; }
public HideFilterInDefaultAttribute(Boolean hide)
{
Hide = hide;
}
// this will allow us to have a default set to false
public static HideFilterInDefaultAttribute Default = new HideFilterInDefaultAttribute(false);
}
public partial class ForeignKeyFilter : System.Web.DynamicData.QueryableFilterUserControl
{
protected void Page_Init(object sender, EventArgs e)
{
string initialValue = DefaultValue;
if (initialValue == null && Column.Attributes.OfType<HideFilterInDefaultAttribute>().DefaultIfEmpty(HideFilterInDefaultAttribute.Default).First().Hide)
{
this.NamingContainer.Visible = false;
}
else
{
PopulateListControl(DropDownList1);
if (!String.IsNullOrEmpty(initialValue))
{
ListItem li = new ListItem();
li = DropDownList1.Items.FindByValue(initialValue);
DropDownList1.Items.Clear();
DropDownList1.Items.Add(li);
}
}
}
}
Northwind DB
public class Product_MD
{
[HideFilterInDefault(true)]
public object Supplier { get; set; }
}
That worked really well, but it looks like the text next to the filter is still appearing. What's the easiest way to suppress that too without modifying every PageTemplate?
you can also improve performance if you use the Autocomplete filter from my NuGet package
Dynamic Data 15 Custom Filters you can set the number of characters the user must type before a prefiltered query is sent.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
natek11
Member
1 Points
3 Posts
Disable Dynamic Data Filter Dropdown without Disabling the Click Through Filtering
May 24, 2012 05:44 PM|LINK
I am disabling the dynamic filter dropdowns on some of the pages of my dynamic data app to improve performance (some of the tables are quite large). I am doing it in the meta-data with the following:
<Filter(Enabled:=False)>
However, when I do this, it also disables the filtering that occurs when I click through from a foreign key. Is there a good way to disable the dropdowns to save loading them without disabling the click through filtering?
Thanks in advance
valZ
Member
130 Points
41 Posts
Re: Disable Dynamic Data Filter Dropdown without Disabling the Click Through Filtering
May 25, 2012 06:30 AM|LINK
I'm doing something like this.
[AttributeUsage(AttributeTargets.Property)] public class HideFilterInDefaultAttribute : Attribute { public Boolean Hide { get; private set; } public HideFilterInDefaultAttribute(Boolean hide) { Hide = hide; } // this will allow us to have a default set to false public static HideFilterInDefaultAttribute Default = new HideFilterInDefaultAttribute(false); }public partial class ForeignKeyFilter : System.Web.DynamicData.QueryableFilterUserControl { protected void Page_Init(object sender, EventArgs e) { string initialValue = DefaultValue; if (initialValue == null && Column.Attributes.OfType<HideFilterInDefaultAttribute>().DefaultIfEmpty(HideFilterInDefaultAttribute.Default).First().Hide) { this.NamingContainer.Visible = false; } else { PopulateListControl(DropDownList1); if (!String.IsNullOrEmpty(initialValue)) { ListItem li = new ListItem(); li = DropDownList1.Items.FindByValue(initialValue); DropDownList1.Items.Clear(); DropDownList1.Items.Add(li); } } } }public class Product_MD { [HideFilterInDefault(true)] public object Supplier { get; set; } }natek11
Member
1 Points
3 Posts
Re: Disable Dynamic Data Filter Dropdown without Disabling the Click Through Filtering
May 25, 2012 07:44 PM|LINK
That worked really well, but it looks like the text next to the filter is still appearing. What's the easiest way to suppress that too without modifying every PageTemplate?
Thanks!
natek11
Member
1 Points
3 Posts
Re: Disable Dynamic Data Filter Dropdown without Disabling the Click Through Filtering
May 25, 2012 07:47 PM|LINK
Never mind, I changed
Me.NamingContainer.Visible = False
to
Me.NamingContainer.NamingContainer.Visible = False
and that seemed to do the trick. thanks again!
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Disable Dynamic Data Filter Dropdown without Disabling the Click Through Filtering
May 26, 2012 01:52 PM|LINK
you can also improve performance if you use the Autocomplete filter from my NuGet package Dynamic Data 15 Custom Filters you can set the number of characters the user must type before a prefiltered query is sent.
Always seeking an elegant solution.