locked
Filter a list with multiple filters RRS feed

  • Question

  • User1122679459 posted

    I have a list of products that are displayed by a selected category. Once a category is selected, additional filters are shown.

    So I have Categories and three filters Age, Gender Brand. The user is able to select one or even all three filters

    Where I'm having trouble is generating those urls. For example If I'm on the Bike category and I filter by Age then Gender but then I decide to remove Age, those urls need to be in sync..

    Here is the code I'm using on the sidebar showing the Categories and filters:

    <h3>Categories</h3>
            <ul class="sidebar-list">
                @foreach (var row in category)
                {
                    <li><a href="~/Products?Category=@row.Id">@row.Name</a></li>
                }
                <li><a href="~/Products">View All</a></li>
            </ul>
    
            @if (!CategoryID.IsEmpty())
            {
                <h3>Age</h3>
                <ul class="sidebar-list">
                    
                    @if (!AgeID.IsEmpty())
                    {
                        var AgeName = db.QueryValue("SELECT Name FROM Age WHERE Age.ID = @0", AgeID);
                        var currentUrl = HttpContext.Current.Request.Url.AbsoluteUri;
                        var newURL = Utils.RemoveQueryStringByKey(currentUrl, "Age");
                        
                        <li class="active"><a href="@newURL"><i class="fa fa-times-circle"></i></a> @AgeName</li>
                    }
                    else
                    {
                        foreach (var row in age)
                        {
                            <li><a href="~/Products?Category=@CategoryID&Age=@row.Id">@row.Name</a> <span class="badge">@row.numberOfProducts</span></li>
                        }
                    }
                    
                </ul>
    
                <h3>Gender</h3>
                <ul class="sidebar-list">
                    @foreach (var row in gender)
                    {
                        <li><a href="~/Products?Category=@CategoryID&Gender=@row.Id">@row.Name</a> <span class="badge">@row.numberOfProducts</span></li>
                    }
                </ul>
    
                <h3>Brands</h3>
                <ul class="sidebar-list">
                    @foreach (var row in brand)
                    {
                        <li><a href="~/Products/@row.Id">@row.Name</a> <span class="badge">@row.numberOfProducts</span></li>
                    }
                </ul>
            }  

    Monday, January 5, 2015 10:05 PM

Answers

  • User-821857111 posted

    I've read your question quite a few times now and still have absolutely no idea what you are trying to achieve. Perhaps if you take a bit more time to describe the issue you are facing, what you are currently doing and how that fails to resolve it, and what your preferred outcome is, you will either end up with a clearer question or a "light bulb" moment when the solution is obvious to you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 8, 2015 10:17 AM

All replies

  • User-1506965535 posted

    Below is a screen shot.

    I cant see your screenshot. Also Please put the code which you have implemented for filtering.

    Tuesday, January 6, 2015 3:42 AM
  • User1122679459 posted

    I moved the image and added my code. Anyone have any thoughts?

    Thursday, January 8, 2015 9:05 AM
  • User-821857111 posted

    I've read your question quite a few times now and still have absolutely no idea what you are trying to achieve. Perhaps if you take a bit more time to describe the issue you are facing, what you are currently doing and how that fails to resolve it, and what your preferred outcome is, you will either end up with a clearer question or a "light bulb" moment when the solution is obvious to you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 8, 2015 10:17 AM