What is the best method for designing a filtering menu with a "Narrow By" option?

Looking to create a sidebar menu similar to the functionality on mcmaster.com. This specific feature allows users to efficiently filter products and toggle through different options dynamically. Upon selecting the "metric" option, the entire page adjusts to showcase metric-based products, including both the sidebar and main content area. It's worth noting that despite these changes, the URL remains fairly consistent without extensive reloading when transitioning between options. View image before selecting "metric" option

View image after selecting "metric" option

Is it possible to achieve this type of functionality using just HTML, CSS, and Javascript?

Answer №1

This question seems too broad for a specific solution. To receive help from the community, you should provide the actual code that needs to be implemented.

Based on my observation, Ajax is used to dynamically update the page content according to filter options.

A simple form of filtering involves displaying certain items on the page while hiding others based on selected filters.

Below is a basic example: blue represents metric units, green represents inches. Clicking "clear" will reset the filter. This serves as a fundamental illustration of how filters can work.

$(".filter span").click(function(){
  
  $(".filter span").removeClass("selected");
  
  $(this).toggleClass("selected");
  
  var theClass = $(this).attr("class");
  theClass = theClass.replace(" selected","");
  
  if ( theClass === "metric" ) {
    $(".items .inch").hide();
    $(".items .metric").show();
    } else if ( theClass === "inch" ){
      $(".items .inch").show();
      $(".items .metric").hide();
      
      } else {
        $(".item").show();
        $(".filter span").removeClass("selected");
        }
  
  });
.filter {
  width: 100%;
  display: block;
  float: left:
  }

.items {
  width: 100%;
  display: block;
  float: left;
  }

.item {
  display: block;
  float: left;
  width: 10%;
  margin-right: 10px;
  margin-bottom: 10px;
  border: solid 1px #ccc;
  padding: 10px;
  text-align: center;
  }

.items .inch {
  background: #0f0;
  }

.items .metric {
  background: #00f;
  }

.filter span:hover {
  cursor: pointer;
  font-weight: 900;
  padding: 2px;
  border: solid 1px #000;
  }

.selected {
    font-weight: 900;
  padding: 2px;
  border: solid 1px #000;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="filter">
  Choose: <span class="metric">metric</span> <span class="inch">inch</span><span class="clear"> clear</span>
  </div>
<ul class="items">
  
  <div class="item metric">1. metric</div>
  <div class="item inch">2. inch</div>
  <div class="item metric">3. metric</div>
  <div class="item metric">4. metric</div>
  <div class="item inch">5. inch</div>
  <div class="item metric">6. metric</div>
  <div class="item metric">7. metric</div>
  <div class="item inch">8. inch</div>
  <div class="item metric">9. metric</div>
  
  

  
  </ul>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Need to remove bold formatting? Try this compact WYSIWYG editor!

Hello Stack Overflow community, I discovered a method called str.bold() that wraps text in <b></b> tags, which is perfect for a small WYSIWYG editor (I understand there are many open source solutions available, but I wanted to learn by creatin ...

Sending parameters in SwipeableDrawer in ReactJS using Material UI

This is a demonstration of my SwipeableDrawer from material-ui const sideList = ( </List> <ListItem button component={Link} to="/todos"> <ListItemText primary="Todos" /> </ListItem> </List> ) <SwipeableDrawer o ...

PHP function not being called when Ajax request is made (PHP file not found)

I need assistance with a web page feature that allows the user to choose a team, triggering a change in an image.src to reflect the new selection. The chosen teamID is then saved in a settings file. However, I am facing issues with getting the AJAX call to ...

Should Errors be Handled in the Service Layer or the Controller in the MVC Model?

Currently, I am in the process of developing a Backend using Express and following the MVC Model. However, I am uncertain about where to handle errors effectively. I have integrated express-async-errors and http-errors, allowing me to throw Errors anywher ...

The sole focus is on the animation within the div

Is it possible to have a circle animation within a button without overlapping it? Check out my code on this fiddle. $(document).ready(function(){ $('button').on("mouseup",function(){ $('#mousemark').removeClass("c ...

Using Javascript code within functions.php

I am facing an issue with the code below; function add_js_functions(){ $gpls_woo_rfq_cart = gpls_woo_rfq_get_item(gpls_woo_rfq_cart_tran_key() . '_' . 'gpls_woo_rfq_cart'); if(is_array($gpls_woo_rfq_cart)){ $count = count($gpls_woo_r ...

Unlinking styles from the template in Vue.js

I have a unique situation where my template contains a <style> block that needs to be positioned near its corresponding div due to CMS restrictions. However, when I try to integrate Vue.js into the mix, it appears to strip out the style block and di ...

Broadcasting events across the entire system

I'm trying to accomplish something specific in Angular2 - emitting a custom event globally and having multiple components listen to it, not just following the parent-child pattern. Within my event source component, I have: export class EventSourceCo ...

Is there a way in Python to translate JavascriptSerializer into a datetime object?

My JSON file contains date and time in the format generated by JavascriptSerializer, shown below: {"StartDate": "/Date(1519171200000)/", "EndDate": "/Date(1519257600000)/",} How can I convert it to datetime formats like these? "2012-04-23T18:25:43.511Z" ...

Unable to display toast notification in React/MUI/Typescript project

Currently tackling error notifications targeted at 400,401, and 500 errors within a large-scale project. I am facing an issue where I want to integrate my ErrorToastNotification component into my layout.tsx file to avoid duplicating it across multiple page ...

Ways to prevent horizontal scrolling in an image

Currently, I am working on a scrolling animation page that is optimized for mobile devices. One issue I am encountering is when an element is larger than the screen size, such as when an image is wider than the mobile device. In this scenario, the user can ...

Tips for creating an oval on Google Maps V3

I am struggling to create an oval shape on Google Maps V3. The current method I am using involves a series of polygons, but it is challenging to achieve a smooth oval shape as you can see in my JSFIDDLE. Is there a more efficient way to accomplish this? ...

Utilizing the power of AWS Lambda in conjunction with moment JS to generate unique

My current time zone is GMT+8, and the AWS region I am using is Singapore (ap-southeast-1). I am facing an issue where there are discrepancies in date calculations between my local machine and when I deploy my code on AWS Lambda. My goal is to ensure that ...

How can the target pseudo-class be utilized to replace the 'active' state on navigation across several pages effectively?

Within a large application, I am managing a micro site and looking to implement tertiary navigation with an active state for pages. This involves inserting a single html blob into multiple pages. My goal is to use an active class to highlight the page in ...

Specify the location of the resize button (corner)

Scenario : At the bottom of the page, there is a resizable textarea, However, having the resize button at the bottom-right corner does not provide the best user experience (try it out), Issue : I am wondering if there is a way to move the resize butt ...

MUI Input component does not support the use of the oninput attribute

My MUI Input component is defined like this, but the oninput attribute doesn't seem to work in MUI: <Input variant="standard" size="small" type="number" inputProps={{ min: '0', o ...

What is the standard way to write the server-side code for HTTP request and response handling?

I stumbled upon these resources: How to send HTTP request GET/POST in Java and How to SEND HTTP request in JAVA While I understand the client-side aspect, how can this implementation be done on the server side? The goal is to utilize the link on the clie ...

Adapting to more user inputs in accordance with the feedback received from the AJAX response

Two user inputs are being received: area time Utilizing this information, the available restaurants in the specified area during that particular time are displayed. In addition, all the cuisines offered by these restaurants are displayed as checkboxes. ...

Sending C# Model from View to Javascript

I have set up my ViewModel for the View: public class DashboardViewModel { public List<UserTask> UserTasks {get; set;} public List<WorkItem> WorkItems {get; set;} } In the View, I am looping through the WorkItems as follows: ...

Tips for utilizing New FormData() to convert Array data from an Object for executing the POST request with Axios in ReactJs

When working on the backend, I utilize multer to handle multiple file/image uploads successfully with Postman. However, when trying to implement this in ReactJS on the frontend, I find myself puzzled. Here's a sample case: state = { name: 'pro ...