Filter DownloadList at runtime by Taxonomy

Posted by Community Admin on 04-Aug-2018 23:23

Filter DownloadList at runtime by Taxonomy

All Replies

Posted by Community Admin on 29-Dec-2011 00:00

In sitefinity 3.7 we could filter the download list at runtime via the querystring by setting the following Query string values within the control  (ContentProviderKey, ContentItemKey, CategoryKey, TagKeyType, etc...)

What is the method used for filtering the download list by taxonomy at runtime for version 4.  This should be a simple thing but I can't find a reference to it.

Posted by Community Admin on 30-Dec-2011 00:00

I found an existing post that is trying to do the same thing and is probably a better place for a response.

http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/multiple-taxonomycontrol-s.aspx

Posted by Community Admin on 03-Jan-2012 00:00

Hi Webteam,

Like my colleague Stanislav explained in the forum post you mentioned, the easiest approach to get you started would be to customize the template for the specific view type you want to use, and hook up to the ItemDataBound event where you can check whether the items have the desired category assigned to them or not. Extended filtering (i.e. by multiple categories) , although not that trivial can be achieved by tusing LINQ dynamic expressions, you can read more on the topic here and here.
Another approach that comes to my mid would be the following - you can collect all the parameters in the dropdowns in an easily operable structure (e.g List, or array of strings). Then you will filter dynamically, in a consequtive order i.e. First you filter all documents by the first cutoms filed. Then you fiter on the result by the next custom field and so on. This could be achieved with a method that's accepting a custom filed value from the List/array of search criteria and is called recursively, with the end result being documents that match all the criteria. The only drawback of this implementation is that it might impose some performance issues, it really depends on the amount of data you'll be filtering.

Kind regards,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 19-Jan-2012 00:00

I can hook up to the itemDataBound event but how would I check the taxonomies for each document, I don't see a property associated with the document to get taxonomies and I don't see any methods under the taxonomymanager either that would work.

so I have something like....
 protected void table_ItemDataBound (object sender, GridItemEventArgs e)
   
        if ((e.Item.ItemType == GridItemType.Item) || (e.Item.ItemType == GridItemType.AlternatingItem))
       
            var dataItem = e.Item.DataItem;
            var gridItem = e.Item as GridDataItem;
            var document = (Telerik.Sitefinity.Libraries.Model.Document)dataItem;

// I'm not sure at this point how to get the taxonomies for the above document.

Posted by Community Admin on 20-Jan-2012 00:00

Hi,

Since taxonomies (Tags, Categories, Departments etc.) are persisted as dynamic fields for the content, they do not exist as public properties that can be accessed. However you can use our extension methods GetValue() and SetValue() to operate with any dynamic field assigned to your content type. Please note you'll need to add a reference to Telerik.Sitefinity.Model in your class to resolve the namespace where the above mentioned extension methods are located. Here's an example how you can operate with the Tags/Categories assigned to a document:

var manager = TaxonomyManager.GetManager();
            var docManager = LibrariesManager.GetManager();
  
            //Get the GUID of the desired category
            var myCategoryId = manager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == "MyNewsCategory").SingleOrDefault().Id;
  
            //Alternatively you can get the GUID of the desired Tag
            var myTagId = manager.GetTaxa<FlatTaxon>().Where(t => t.Name == "MyTagname").SingleOrDefault().Id;
  
            //get documents by Library
            var docList = docManager.GetDocuments().Where(d => d.Parent.Title == "MyLibrary");
  
            //Get a list of the news items who have the desired category assigned to them
            var docListByCats = docList.Where(d => d.GetValue<TrackedList<Guid>>("Category").Contains(myCategoryId)).ToList();
  
            //Or by Tags
            var docListByTags = docList.Where(d => d.GetValue<TrackedList<Guid>>("Tags").Contains(myTagId)).ToList();



All the best,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed