Can a data filter be customized to fit a specific grid layout, ensuring that all images are displayed in a full column or at a designated size?

Check out this awesome box grid https://i.sstatic.net/qbmQz.jpg

But here's the issue: when I add a data filter and switch between filters, the images always appear in the same location and size as the original grid. Is there any way to make the filtered images all display in the same size? Here's my grid code:

 <div class="container">
  <div class="text-center">
      <button class="btn btn-default filter-button" data-filter="all">All</button>
      <button class="btn btn-default filter-button" data-filter="bootstrap">BootStrap</button>
      <button class="btn btn-default filter-button" data-filter="bootstrax">BootStrax</button>
      <button class="btn btn-default filter-button" data-filter="purecss">Pure CSS</button>
  </div>
  <div class="container container-box">
    <style>
      .container-box{
     width: 600px;  }
    </style>
      <div class="row">
        <div class="col-12"><img width="600" class="img-fluid pb-3 filter bootstrax " 
      src="./images/01.jpg" alt=""></div>
      </div>
      <div class="row g-3">
        <div class="col-4"><img width="200" class="img-fluid filter bootstrap" 
      src="./images/02.jpg" alt=""></div>
        <div class="col-4"><img width="200" class="img-fluid filter purecss" 
      src="./images/03.jpg" alt=""></div>
        <div class="col-4"><img width="200" class="img-fluid filter bootstrax" 
      src="./images/04.jpg" alt=""></div>
      </div>
      </div>
      </div>

           

$(document).ready(function() {
$(".filter-button").click(function(e) {
  var value = $(this).attr("data-filter");
  if (value == "all") {
    $(".filter").show("1000");
  } else {
    $(".filter").filter("." + value).show("3000");
    $(".filter").not("." + value).hide("3000");
  }
});

if ($(".filter-button").removeClass("active")) {
  $(this).removeClass("active");
}
$(this).addClass("active");
 });

Is it doable to achieve this using javascript, css, and html? Or if you have a better suggestion, please share it with me.

Answer №1

To integrate the isotop js library, you can include the CDN link in your script section:

      <script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script>

With isotope, you can maintain a nested gallery structure and enable data filtering. The filtered images will display next to each other seamlessly while preserving the grid layout.

<div class="container text-center pt-5">
<div class="row">
<div class="col-md-12">
  <div class="filters">
    <h4>Featured categories</h4>
    <ul>
      <li data-filter=".idea">Furniture <img class="dot" src="./images/dot.svg" 
      alt=""></li>
      <li data-filter=".ui">lighting <img class="dot" src="./images/dot.svg" 
      alt=""></li>
      <li data-filter=".ux">Accessories <img class="dot" src="./images/dot.svg" 
      alt=""></li>
      <li data-filter=".code">Tailor-made objects <img class="dot" 
      src="./images/dot.svg" alt=""></li>
      <li class="is-checked fp" data-filter="*">All</li>
    </ul>
  </div>
</div>

<div class="col-md-12">
  <div class="rows grid data-isotope='{ "itemSelector": ".grid-item", "masonry": 
    { "columnWidth": 200 } }'">
    <div class="col-md-12 grid-item code">
      <img class="img-fluid" src="./images/01.jpg" alt="">
    </div>
       <div class="col-md-4 grid-item ux ">
      <img class="img-fluid img-grid" src="./images/02.jpg" alt="">
    </div>
    <div class="col-md-4 grid-item ui">
      <img class="img-fluid img-grid" src="./images/03.jpg" alt="">
    </div>
    <div class="col-md-4 grid-item idea">
      <img class="img-fluid img-grid" src="./images/04.jpg" alt="">
    </div>
    <!-- More grid items here -->
  </div>
</div>

Include the following script as well:

var $grid = $('.grid').isotope({
// options
itemSelector: '.grid-item',
layoutMode: 'fitRows',
});

 // change is-checked class on buttons
 var $buttonGroup = $('.filters');
 $buttonGroup.on( 'click', 'li', function( event ) {
 $buttonGroup.find('.is-checked').removeClass('is-checked');
 var $button = $( event.currentTarget );
 $button.addClass('is-checked');
 var filterValue = $button.attr('data-filter');
 $grid.isotope({ filter: filterValue });
 });

Good luck with your implementation!

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

Having trouble exporting CSV files with Tamil fonts. Are you experiencing an error?

We are exploring various methods to display Tamil content in a CSV file with characters like "தூதுக்கடட". Can anyone provide assistance? mysqli_set_charset($db, "utf8mb4"); $query = $db->query("$reports"); if($query->num_rows > ...

What is the best way to concatenate two different values in React JSX using the "+" operator?

I have a situation where I need to take a value from an input, add 10% to it, and display the result. For example, if a person inputs 1000, the 10% of 1000 is 100, so the total result should be 1100. Currently, when I use the "+" operator, it concatenates ...

What methods do Google and Yahoo use to update the URL displayed in the browser's status bar?

Have you ever noticed that on Google and Yahoo search pages, the URLs of the search result links actually point to google.com or yahoo.com? It's a clever trick they use by adding extra arguments to the URLs that allow for redirection to the actual sea ...

In JavaScript, using square brackets before a method allows for dynamic method

Does anyone know the significance of the square brackets preceding the method call in this code snippet? It's a new syntax for me... return [].concat(privateUserList); Appreciate any insights! ...

Finding matches within a specific group in regular expressions

I am currently tackling the challenge of implementing a feature that involves detecting and linking phrases like "Co. Reg. No" in a specific HTML element. <div class="entry">The company with Co. Reg. No 1241515 will...</div> My goal is to cre ...

Surprising results when using react-router-dom alongside React's Context API

I am currently working on a small project where I am trying to implement basic authentication using the React Context API without Redux. Here is the code snippet: import { createContext, useContext, useState } from 'react' export const AuthConte ...

Tips for stopping variables from leaking in JavaScript

I'm currently working on a JavaScript code for my task manager website. Each page has its own JS file, but I've noticed that the data saved in one file seems to leak over to the others. How can I contain these variables so that tasks don't s ...

Gatsby's own domain and absolute links: the perfect pair

My goal is to establish a direct link to files (such as images and downloads) in my static directory. During development, the link should be http://localhost/myimage.jpg, and once deployed, it needs to switch to https://www.example.com/myimage.jpg. Is the ...

Can you explain the reference point used in the `drawImage()` function on a canvas?

Here is an inquiry concerning the usage of the drawImage() function. var x = (i-j)*(img[0].height/2) + (ctx.canvas.width/2)-(img[0].width/2); var y = (i+j)*(img[0].height/4); abposx = x + offset_x; abposy = y + offset_y; ctx.drawImage ...

Utilizing document.write() for displaying markup content

I have an inline SVG stored as a variable on my webpage and I am making some changes to it. How can I display viewText on the page (not the SVG image) with the modifications? What is the best way to make viewText appear on the page? For instance: ...

Spin an object around the global axis using the tween.js library

I'm trying to achieve a gradual rotation of a cube on the world axis using tween. Initially, I was able to rotate the cube around the world axis without tweening with the following code: rotateAroundWorldAxis(cube[1], new THREE.Vector3(0,1,0),degreeT ...

Display Error with Custom Alert Box

I recently implemented a customized alert box from slayeroffice's website, which you can find at slayeroffice.com/code/custom_alert/. When I view it on my browser, the alert box appears with a blue color in the center of the screen. Here is how it lo ...

There is an issue with the function of elem.autocomplete - it is not recognized

I'm new to Angular.JS and have been struggling for the past 6 hours. I've been working on reading data from an HTTP source and displaying it as an autocomplete feature on the view. Previously, the data was displayed in a select box, but I decide ...

Issue with react-router-dom: <Route> elements are strictly meant for configuring the router and should not be rendered on their own

I've been grappling with this issue for quite some time now, but none of my attempts have succeeded and I keep encountering the same error: < Route> elements are for router configuration only and should not be rendered Here's the snippet ...

Nonspecific _POST parameter error encountered while utilizing XMLHttpRequest()

I am currently experimenting with Ajax to add data into a database using the POST method. However, I am facing an issue where PHP is unable to recognize the post variables being sent. ajax: function createUser() { var _id=document.getElementById('ne ...

Modify an element upon clicking the mouse on an image

I am looking to dynamically change the paragraph element with className="details" to an editable input field when a user clicks on the image with className="edit-icon" within the same grid container. How can I achieve this functionality ...

Invoke a controller in Prestashop by utilizing AJAX technology

I am struggling to figure out how to call the method / function in my controller. The controller is named TestController.php, and I also have files named Test.tpl and Test.js. Additionally, I am unsure of what to put in the URL field. My goal is to retrie ...

Duplicating an array retrieved through a jQuery ajax request

Currently, I am encountering an issue while attempting to duplicate a JSON array within this specific JavaScript function: var test = new array(); function showUser(user, pass, remember) { $.getJSON("login.php", { username : user, password : pass, che ...

Challenges with the jScroll Plugin

Trying to implement jScroll to load a partial view multiple times using an increasing page number. The partial view returns a few divs. To achieve infinite scrolling, the partial view needs to have a hyperlink tag that directs to the next page to load. Th ...

Python error message: "Invalid index. List indices must be integers, not tuples."

I have been assembling a robot that navigates around a 2D grid room of 8 x 8 dimensions. One crucial step is configuring the sensors to detect information from the closest 5 tiles surrounding the robot. self.sensors = [0 for x in xrange(5)] In this insta ...