Filter on categories

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

Filter on categories

All Replies

Posted by Community Admin on 08-Jul-2011 00:00

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:

localhost/.../CategoriesTest

Is this scenario possible?

Thanks,
Daniel

Posted by Community Admin on 12-Jul-2011 00:00

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

This thread is closed