More in this section

Forums / Developing with Sitefinity / Filter on categories

Filter on categories

2 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    112 posts
    Registered:
    14 Jun 2012
    08 Jul 2011
    Link to this post
    Hi all,

    I've a question on how to filter my products module by categories.
    I have created a page which has the ProductView control from the Products Sample. This shows products.

    On the left of the page I have a RadPanelBar which shows Categories with subcategories. (HierarchicalTaxon). Now what I like is that when you click on a category, the products view gets filtered by the category and all the subcategories that belong to this category. The URL should contain the category.

    If I click on a subcategory, the products view should be filtered also.

    I tried to build the URL using the TaxonomyEvaluator.BuilUrl, but it generates a URL which isn't of much use:

    http://localhost/-in-Category/CategoriesTest

    Is this scenario possible?

    Thanks,
    Daniel
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    12 Jul 2011
    Link to this post
    Hello Daniel,

    To apply filtering you need to subscribe for a command thrown by DynamicCommandWidgetElement- filterByResortl. You should build a filter of a dynamic LINQ and applies it on the MasterGridView. Here is a sample based on products module.

    // called by the MasterGridView when it is loaded
    function OnMasterViewLoaded(sender, args) {
        // the sender here is MasterGridView
        var itemsGrid = sender.get_itemsGrid();
        itemsGrid.add_command(handleItemsGridCommand);
    }
      
    function handleItemsGridCommand(sender, args) {
        switch (args.get_commandName()) {
            case "filterByResort":
                var id = args.get_commandArgument().get_dataItem().Id;
                // here Colors is the filtered custom taxonomy
                var filter = "Colors.Contains(" + '"{' + id + '}"' + ")";
                sender.applyFilter(filter);
                break;
            default:
                break;
        }
    }

    To filter custom taxonomies you must construct the filter with the name of the taxonomy

    Colors.Contains
    CustomTaxonomy.Contains

    Using an empty string in sender.applyFilter you will clear the filtering.

    All the best,
    Ivan Dimitrov
    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
2 posts, 0 answered