How to us a URL param/query to filter a Custom Module.

Posted by Community Admin on 04-Aug-2018 18:52

How to us a URL param/query to filter a Custom Module.

All Replies

Posted by Community Admin on 12-Sep-2012 00:00

I have a custom module called "Case Studies". I want to be able to dynamically filter the list of Case Studies by the tags on each. I would like to do this filtering through the url. Whether I use url parameters or a query string, I don't care. What I want is the out of the box functionality for the build in modules that allows you to do just that. This functionality is described here (http://www.sitefinity.com/blogs/slavoingilizov/posts/11-12-12/url_filtering_in_built-in_content_widgets.aspx).

In my approach I want that data to still be filtered, sorted, and paginated based on the settings that are configured in the standard designer view. I want my filtering to be included in the filtering and before the pagination.

I spent a good amount of time using JustDecompile to read through the NewsView, DynamicContentView, and their associated classes. I see the following line in the news MasterListView that does the taxonomy filtering here in the GetItemsList method:

newsItems = this.EvaluateUrl<NewsItem>(newsItems, "Taxonomy", "", typeof(NewsItem), base.Host.UrlEvaluationMode, base.Host.UrlKeyPrefix);

I was looking at DynamicContentViewMaster in the GetNonPagedDataSource method and found this line:
dynamicContents = this.EvaluateUrl<DynamicContent>(dynamicContents, "Taxonomy", "", base.DynamicContentType, UrlEvaluationMode.UrlPath, this.UrlKeyPrefix);

I was hoping that this meant that I could use the UrlPath method that was used for News to filter my CaseStudies. So I tried this url:
/case-studies/-in-Taxonomy/Taxonomies/test

However I get the following "Page Not Found" error:

[HttpException (0x80004005): Page not found]
   Telerik.Sitefinity.Web.PageRouteHandler.handler_PreRenderComplete(Object sender, EventArgs e) +340
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +141
   System.Web.UI.Page.PerformPreRenderComplete() +49
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5218

So that was a big no and I'm not really sure what the purpose of having that in the code is. It is obvious that the casestudy page is hit since I put a breakpoint in the widget template for OnInit and Page_Load and both are hit. So if anyone knows what is going on with that I would love to hear and explanation and a fix!

Next I tried to find a way to add a filter to the "AdditionalFilter" property on the DynamicContentViewMaster before InitializeControls was called on the same class. I'm trying to do all of this from the widget template's OnInit method. Unfortunately at this point the data source has already been set, and thus paginated, though it isn't bound.

So, any suggestions?

Posted by Community Admin on 13-Sep-2012 00:00

I am using Sitefinity 5 btw.

Posted by Community Admin on 13-Sep-2012 00:00

Well, I can't figure out a good way to do this. My hack is going to be reading the settings off of the DynamicContentViewMaster in the OnInit or OnLoad of the widget template. I will then use these settings plus my url query parameters to filter the data myself and then set the results as the data source of the rad list view on my template. I will also update the pager.

This sucks but I can't find another way to keep the default design view and add my own data filtering pre pagination. This will cause the data to be queried twice unfortunately.

This thread is closed