Filtering with Custom Classification

Posted by Community Admin on 04-Aug-2018 16:10

Filtering with Custom Classification

All Replies

Posted by Community Admin on 29-Mar-2012 00:00

Hi All,

I'm trying to figure out how to filter items from a custom module with custom classifications.  Can I use the filter expression under advanced settings in the item widget or do I need to create a custom control?

Thanks,
Jason

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

Hello Jason,

Yes, you can modify the default FilterExpression in the Advanced settings to filter by custom classification as well, what you need to do is extend the default filter by adding
"AND" + "YourCustomFieldName" and then you can use .Contains filter, by passing the taxon id like this:

Visible = true AND Status = Live AND Cat2.Contains((FF11D5C7-8016-4558-9DFE-91169288F0AB))
For the above sample I've created a custom classification of type Hierarchical taxonomy, and added a custom filed named "Cat2" to my module items. The Id passed in the .Contains filter is the Id of the custom category assigned to my items - you can either get this from the sf_taxa table in the database or by querying the taxonomy using our Taxonomies API. Just in case you need to implement filtering by taxonomies through code, I've also prepared a short sample demonstrating how you can filter Documents by the assigned Tags/Categories:
public IEnumerable<Document> GetDocumentsByCategoryOrTag(string libraryName, string categoryName, string tagName)
       
           var manager = TaxonomyManager.GetManager();
           var docManager = LibrariesManager.GetManager();
 
           //Get the GUID of the desired category
           var myCategoryId = manager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == categoryName).SingleOrDefault().Id;
 
           //Alternatively you can get the GUID of the desired Tag
           var myTagId = manager.GetTaxa<FlatTaxon>().Where(t => t.Name == tagName).SingleOrDefault().Id;
 
           //get documents by Library
           var docList = docManager.GetDocuments().Where(d => d.Parent.Title == libraryName);
 
           //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));
 
           //Or by Tags
           var docListByTags = docList.Where(d => d.GetValue<TrackedList<Guid>>("Tags").Contains(myTagId));
 
           return docListByCats;
           //or
          // return docListByTags;
       

One last remark - to use the above extension methods GetValue and SetValue you'll need to reference the Telerik.Sitefinity.Model namespace in your class.

Greetings,
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 01-May-2012 00:00

Hi Boyan, Im currently trying to filter Ecommerce products with custom classifications by using your solution however Im getting object reference not set error. What I am trying to achieve is adding a list of vendor to choose from when uploading a product and on separate pages have the ecommerce product list widget display the list of product from each vendor. I have attached some screenshots for reference.

Let me know if Im doing anything wrong
Thanks in advance!

Posted by Community Admin on 10-May-2012 00:00

Any help?

This thread is closed