I'd suggest just having one column instead of two. You can use flexbox to arrange your items properly in a grid and then as items are removed your other items will take up the empty space automatically. This would be a lot easier than trying to manage two columns and detaching and attaching
Detach and re attach an element JQuery
So I have a live search which I am working on. And I was wondering why my detach() won't bring back the attachment after removing it. Basically the problem for me is that I hace two col-md-6 which handles two rows which displays many data (6 per column). My issue is that When I live search, the second column shows the items which matches the search result and the first column is blank (because the first column does not contain any which matches the search result). But it looks wierd as there is a huge gap in between and the results shows only on the second column. Here is an image example.
This is the default one,
And here is the searched one with the result,
As mentioned above, the first column stays empty so it takes that space. What I want is the items to move to first column if it is not already there. Here is my HTML,
<div class="row live-search-list">
<div class="col-md-6 first-column">
<ul class="menu-dish">
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-3.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 25.99</span>
<button class="addToBasket btn btn-primary btn-outline btn-md" data-toggle="modal" data-target="#exampleModalCenter">Add to Basket</button>
<h3>Grilled Beef with potatoes</h3>
<p class="cat">Meat / Potatoes / Rice / Tomatoe</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-4.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 30.99</span>
<button class="addToBasket btn btn-primary btn-outline btn-md" data-toggle="modal" data-target="#ModalCenter">Select Options</button>
<h3>Tuna Roast Source</h3>
<p class="cat">Tuna / Potatoes / Rice</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-5.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 40.00</span>
<h3>Roast Beef (4 sticks)</h3>
<p class="cat">Crab / Potatoes / Rice</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-6.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 20.50</span>
<h3>Salted Fried Chicken</h3>
<p class="cat">Crab / Potatoes / Rice</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-7.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 20.50</span>
<h3>Lumpia Shanghai</h3>
<p class="cat">Crab / Potatoes / Rice</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-8.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 20.50</span>
<h3>Chicken Adobo</h3>
<p class="cat">Crab / Potatoes / Rice</p>
</div>
</li>
</ul>
</div>
<div class="col-md-6">
<ul class="menu-dish">
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-9.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 25.99</span>
<h3>Marinated Beef</h3>
<p class="cat">Meat / Potatoes / Rice / Tomatoe</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-10.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 30.99</span>
<h3>Fried Tokwa</h3>
<p class="cat">Tuna / Potatoes / Rice</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-11.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 40.00</span>
<h3>Letson Kawali</h3>
<p class="cat">Crab / Potatoes / Rice</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-12.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 20.50</span>
<h3>Fried Pork</h3>
<p class="cat">Crab / Potatoes / Rice</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-13.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 20.50</span>
<h3>Chopsuey</h3>
<p class="cat">Crab / Potatoes / Rice</p>
</div>
</li>
<li>
<figure class="dish-entry">
<div class="dish-img" style="background-image: url(images/dish-14.jpg);"></div>
</figure>
<div class="text">
<span class="price">MVR 20.50</span>
<h3>Sunny sideup egg</h3>
<p class="cat">Crab / Potatoes / Rice</p>
</div>
</li>
</ul>
</div>
</div>
And my Jquery for live search,
jQuery(document).ready(function($){
$('.live-search-list li').each(function(){
$(this).attr('data-search-term', $(this).text().toLowerCase());
});
$('.live-search').on('keyup', function(){
var searchTerm = $(this).val().toLowerCase();
$('.live-search-list li').each(function(){
if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
$(this).show();
} else {
$(this).hide();
}
});
});
});
As you can see in html I have two col-md-6. Sorry about the long code.
Please or to participate in this conversation.