1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Filtering with Custom Classification

Filtering with Custom Classification

4 posts, 0 answered
  1. Jason
    Jason avatar
    16 posts
    Registered:
    27 Aug 2008
    29 Mar 2012
    Link to this post
    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
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    03 Apr 2012
    Link to this post
    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
  3. Jack
    Jack avatar
    23 posts
    Registered:
    03 May 2011
    01 May 2012
    Link to this post
    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!
  4. Jack
    Jack avatar
    23 posts
    Registered:
    03 May 2011
    10 May 2012
    Link to this post
    Any help?
4 posts, 0 answered