Incorporating JQuery UI sortable functionality with the CSS grid display property to create a

I'm currently working on creating a sortable CSS grid using jQuery UI.

    $( function() {
    $( "#sortable" ).sortable({
      handle: "handle"
    });
    });
    gridHolder{
      display:grid;
      background:tan;
      grid-template-columns:1fr 1fr 1fr 2fr;
    }
    gridHeader > *{
        padding:10px;
        background:yellow;
        border:thin solid black;
    }
    gridContent , gridHeader{
      display:contents;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

<gridHolder id="sortable">
  <gridHeader>
<handle>Handle</handle>
<name>Name</name>
<address>Address</address>
<phone>Phone</phone>
  </gridHeader>
  <gridContent>
<handle>Handle</handle>
    <name>Adam</name>
    <address>111 Main St</address>
    <phone>123-4567</phone> 
  </gridContent>  
  <gridContent>
<handle>Handle</handle>
    <name>Bob</name>
    <address>222 Brown Ave</address>
    <phone>987-6543</phone> 
  </gridContent>  
  <gridContent>
<handle>Handle</handle>
    <name>Carl</name>
    <address>333 East Ave</address>
    <phone>555-1343</phone> 
  </gridContent>    
  
</gridHolder>

Link to the example

The problem I'm facing is that the sortable feature doesn't seem to work properly with the combination of CSS grid and the display: contents property. I understand that display: contents is more of an organizer for child elements rather than a traditional display property, but I'm unsure why it's affecting the jQuery UI sortable functionality.

Answer №1

Looking at the core concepts of CSS, it appears that content within a grid cannot be manipulated via sorting, dragging, or moving.

Note: Properties like float, display: inline-block, display: table-cell, vertical-align, and column-* have no impact on grid items.

The absence of these properties likely leads to issues with jQuery UI's DnD functionality.

Even when following correct HTML/CSS syntax, attempts to enable these features using jQuery UI did not yield the desired outcome.

This ongoing investigation aims to determine whether this assumption holds true.

Update:

Another important consideration in CSS Grid Layout (and to some extent Flexbox) is the risk of flattening markup. When an item needs to become a grid item, it must be a direct child of the grid container. For instance, an <ul> element inside a grid container becomes a grid item, whereas its child <li> elements do not.

Understanding the relationship between parent-child structure is key to resolving the issue at hand. An alternative example that functions properly illustrates this point.

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

Get the nearest offspring of the guardian

I have a main 'container' div with multiple subsections. Each subsection contains 1 or 2 sub-subsections. Let's say I have a variable that holds one of the subsections, specifically the 4th subsection. This is the structure:container > s ...

Stopping form submission on a jQuery form

I am in the process of implementing a password control feature on a login form using jQuery and ajax. This is the current script I have: $(document).ready(function() { $("#login-form").submit(function(e) { var csrftoken = getCookie('csr ...

Ways to make a button blink using AngularJS

Currently working on an AngularJS SPA application where a button is present in the front-end HTML page. When this button is clicked, it triggers an operation which takes some time to complete. I want to inform the user that the operation is still in prog ...

Testing the number input field using Selenium with PrimeFaces and jQuery

Within my application, I am using PrimeFaces which includes an input number widget among its extensions. This widget utilizes the autoNumeric jQuery plugin in the background, hence why I also tagged this question with jQuery. The issue I'm encounter ...

Addressing responsiveness problems with Bootstrap navigation bar

Seeking assistance with setting up the fundamental bootstrap grid system. Despite my efforts, I am unable to make it work. Could someone guide me in creating the basic structure for the Navbar above? Specifically, focusing on using columns and rows with p ...

Incorporating AJAX functionality into an existing PHP form

I am currently working on a PHP registration form that validates user inputs using $_POST[] requests. Validating username length (3-20 characters) Checking username availability Ensuring the username matches /^[A-Za-z0-9_]+$/ pattern and more... Instead ...

Achieving perfect alignment of an image within a Twitter Bootstrap cell when the height of the cell is uncertain

I have a bootstrap grid and I am attempting to center an image (200x100 as shown in the provided example) within a cell. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!DOCTYPE html> <html& ...

What steps are involved in incorporating dynamic pagination in PHP using this particular snippet of code?

I am looking for a way to display a list of numbers from 1 to 1000 in a single line with the ability to scroll. However, I need to exclude both "Prev" and "1" from this list. How can I achieve this? Below is the code snippet that I currently have: echo ...

Using jQuery to sift through and sort through content

I have successfully implemented a basic filter using HTML and jQuery. The issue I am facing is that when all filter options are unchecked, it displays no results. My goal is to modify the functionality so that when all checkboxes are deselected, it automa ...

JavaScript and CSS tabs with smooth transition effect

I want to create tabs that smoothly fade between each other when switching. The code I have works, but there's a slight issue. When transitioning from one tab to the previous one, there is a momentary glitch where the last tab briefly changes state be ...

Dealing with full-width elements on mobile devices

I've got a pretty basic question here but can't seem to find a straightforward answer. I'm using Bootstrap to style a website and struggling with making it mobile-responsive. Following the given answer, I used this code to show a button ne ...

What is the most efficient way to find the parent element with the fewest children?

In close proximity are two containers, each containing a series of smaller containers. <ul class="containers"> <li>Matt</li> <li>John</li> <li>Mark</li> </ul> <ul class="containers"> &l ...

"Trying to access jQuery .slide and .slideUp features, but unfortunately they are

I've created this script: $("#comments .comment .links").hide(); $("#comments .comment").hover( function() { $(".links", this).stop(true).slideDown(300); }, function() { $(".links", this).stop(true).slideUp(300); } ); However, I'm facin ...

Ensure the first column is fixed and all other columns have the same height

I have encountered an issue where the first column of my table has varying heights compared to the other columns, resulting in inconsistent row heights. Below is the code I am using: <div class="outer"> <div class="inner"> <table> ...

Spinning in a circular motion to achieve specific degrees and locations

Trying to figure out how to make divs rotate around a circle is proving to be quite the challenge for me. To see what I mean, check out this Fiddle: http://jsfiddle.net/TMuD5/2/ As a junior in JS/JQuery, I've reached my limit of knowledge on this t ...

Using HTML and CSS to create interactive icons that change color when clicked, similar to how a link behaves

Have you ever wondered if there's a way to make an icon act like a link when clicked, just like regular text links turning purple? And not just the last one clicked, but every single icon that gets clicked. Trying to use the :visited pseudo was unsucc ...

Utilizing the Current URL from the address bar as a variable to link within the same page

My goal is to: Extract the current URL address from the browser bar, which will have a format like this: http://example.com/test/index.html?&dv1=1023faf2ee37cbbfa441eca0e1a36c Retrieve the lengthy ID number located at the end of the URL 1023faf2ee37c ...

Set a default selection for radio buttons in Angular template-driven forms

I'm having an issue with setting a default selection for a radio button in my template-driven form. Here's the relevant part of my code: <div class="donut-form-promos"> <span>Promo:</span> <div class=&quo ...

What is the proper way to handle a 504 response header in an AJAX request using jQuery?

Recently, I encountered an issue with an AJAX call from the client that caught my attention. Here is a snapshot of how it looked: $.ajax({ 'url': '/converter/ajax-make-corrections/', 'data': { ...

Tips for displaying an arrow icon that points up or down when clicking on a table header in Vue.js

I am currently working on a listing page where data is fetched using Laravel. The issue I am facing is related to sorting functionality when clicking on the table headings (<th>). The desired behavior is for arrow marks to indicate ascending or desce ...