While working on my .Net core project, I implemented an isotope filter dynamically. Everything seemed to be functioning correctly, however, a minor error occurred. When selecting a specific category, the position of the product did not appear as expected. Please refer to the images linked below:
After applying the filter, the image did not change its position (it should have appeared first)
Here's a snippet of my code from Index.cshtml:
@model BornoMala.Models.ViewModels.ProductDetailsVM
<section id="portfolio" class="portfolio">
<div class="container">
<div class="row" data-aos="fade-up">
<div class="col-lg-12 d-flex justify-content-center">
<ul id="portfolio-flters">
<li data-filter="all" class="filter-active filter-button">All</li>
@foreach (var obj in Model.Categories)
{
<li class="filter-button" data-filter="@obj.Name.Replace(' ','_')">@obj.Name</li>
}
</ul>
</div>
</div>
<div class="row portfolio-container" data-aos="fade-up">
@foreach (var prod in Model.Products)
{
<div class="col-lg-4 col-md-6 portfolio-item filter @Model.Category.Name.Replace(' ','_')">
<div class="portfolio-img"><img src="@Model.ImageUrl" class="img-fluid" alt=""></div>
<div class="portfolio-info">
<h4>@Model.Title</h4>
<p>By <b>@Model.Title</b></p>
</div>
</div>
}
</div>
</div>
</section>
In the Isotope.js section of my code:
$(window).on('load', function () {
var portfolioIsotope = $('.portfolio-container').isotope({
itemSelector: '.portfolio-item',
});
});
$(document).ready(function () {
$(".filter-button").click(function () {
$("#portfolio-flters li").removeClass('filter-active');
$(this).addClass('filter-active');
var value = $(this).attr('data-filter');
if (value == "all") {
$('.portfolio-item').show('3000');
}
else {
$(".portfolio-item").not('.' + value).hide('2000');
$('.portfolio-item').filter('.' + value).show('2000');
}
});
});
I encountered an issue where if I remove the ".portfolio-container" class from the "load window" in the Isotope.js script, the details page container loses flexibility. Feel free to check out another image showcasing this problem: