Rubaxa-Sortable encountered an error while attempting to execute the 'matches' function on the 'Element': the selector '>*' is invalid

I have implemented Rubaxa Sortable JavaScript library in my Vue.js project. It works perfectly fine with <ul><li> elements, but when I try to use it with table rows, I encounter this error during drag-and-drop:

Sortable.min.js:3 Uncaught DOMException: Failed to execute 'matches' on 'Element': '>*' is not a valid selector.

My setup includes Vue.js version 2.5.13 and Rubaxa Sortable version 1.7.0.

Vue.directive('sortable', {
  inserted: function (el, binding) {
    var sortable = new Sortable(el, binding.value || {});
  }
});
new Vue({
  el: '#app',
  data () {
    return {
      items: [{id: 1},{id: 2},{id: 3},{id: 4},{id: 5}]
    }
  },
  methods: {
    reorder ({oldIndex, newIndex}) {
      const movedItem = this.items.splice(oldIndex, 1)[0]
      this.items.splice(newIndex, 0, movedItem)
    }
  }
})
<script src="https://vuejs.org/js/vue.min.js"></script>
<script src="https://cdn.rawgit.com/RubaXa/Sortable/c35043730c22ec173bac595346eb173851aece20/Sortable.min.js"></script>
<div id="app">
  <h2>With List</h2>
  <ul v-sortable="{onEnd: reorder}">
    <li v-for="i in items" :key="i.id">{{ i.id }}</li>
  </ul>

  <hr/>

  <h2>With Table</h2>
  <table v-sortable="{onEnd: reorder}">
    <tr v-for="i in items" :key="i.id">
      <td>{{ i.id }}</td>
    </tr>
  </table>

  {{ items }}

</div>

Answer №1

A <table> is not allowed to directly contain table rows (<tr>). The correct structure of a table should include the following elements.

<table>
   <thead></thead>
   <tbody></tbody>
   <tfoot></tfoot>
</table>

When creating an HTML table like this,

<table>
   <tr>First Row</tr>
   <tr>Second Row</tr>
</table>

The browser will automatically place all rows within the <tbody> element and display it in the following way.

<table>
   <tbody>
      <tr>First Row</tr>
      <tr>Second Row</tr>
   </tbody>
</table>

Therefore, table rows should be nested inside the <tbody> element. Remember to generate your table rows within <tbody> and apply v-sortable to that specific <tbody>.

<table>
   <tbody v-sortable="{onEnd: reorder}">  <!-- Apply v-sortable here -->
      <tr v-for="i in items" :key="i.id">
         <td>{{ i.id }}</td>
      </tr>
   </tbody>
</table>

Additionally, the minified version of Sortable contains a bug where they removed a try-catch block during minification process, resulting in sorting failure for elements other than <ul><li>. It is recommended to use the uncompressed development version of Sortable until this issue is resolved.

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

"What's the best way to make sure a checkbox stays checked and its content remains visible after a

After updating my HTML content, it now consists of a hidden table inside a div with the class "myClass": <div class="myClass" style="display:none"> <table class="table table-hover"> ..... </table> </div> The table remains hidden u ...

Implementing automatic pagination based on container height using jQuery

Looking to convert an AngularJS fiddle into jQuery. The goal is to create pagination using several p tags only with jQuery. Current code: <div class="parent"> <p>text1</p> <p>text2</p> <p>text3</p> ...

Is there a way to receive notifications on an Android device when the real-time data updates through Firebase Cloud Messaging (FC

I am attempting to implement push notifications in an Android device using Firebase Realtime Database. For example, if an installed app is killed or running in the background, and a user posts a message in a group (resulting in a new child being added in t ...

The system was unable to locate node.js with socket.io

I'm having trouble locating the file. According to the documentation I reviewed, socket.io is supposed to be automatically exposed. Encountered Error: polling-xhr.js?bd56:264 GET http://localhost:8081/socket.io/?EIO=3&transport=polling&t=LyY ...

Showing the outcome of the AJAX call

I have searched extensively for information on how to use AJAX, but I have been unable to find a resource that clearly explains the concept and its workings. When I send an AJAX request to a PHP file using the code below, I can see the response in Mozilla ...

Showing or hiding child content based on the selected state of a radio button

This is a follow-up question from a previous one on changing check boxes to radio buttons. Now, I need to display child radio buttons and change the background color when the parent radio button is active. The child radio buttons should be hidden and the b ...

Creating a dialog box that effectively blocks user interaction

Is it possible to implement a blocking dialog box with JavaScript/JQuery/Ajax? I've been working with the JQuery UI dialog box, but using it asynchronously with callback functions has made it more complicated than expected. For example: ans1 = confi ...

Set default selected value for dropdown list using radio buttons

Could anyone provide guidance on how to reset a dropdown list value using a radio button selection? Specifically, I need the dropdown list to reset to its default "selected" option when a particular radio button is clicked. Any recommended approaches usin ...

Guide to triggering an API call upon changing the value in a Vue Multiselect component

Is there a way to trigger an API call when the value changes in a Vue Multiselect component? I want to update the value in the multiselect, make an API call, and display the result in the console. Below is my code snippet. <template> <div> ...

VueDraggable communicates with the database by sending a request during drag and drop interactions

Help needed with the vuedraggable component. I have three columns (photo attached) and I would like to be able to drag BoardUserCard between the columns. Upon dropping the card, I want to send a PUT request to the database to change the "lead_status_id" as ...

Styling with CSS: Using a Base64 Encoded Image in the Background URL

Can a Base64 encoded image be loaded as a background image URL without exposing the actual encoded string in the page source? For example, if a Node API is used to GET request at "/image", it returns the serialized Base64 data. res.json("da ...

How come the overlay only appears the first time the button is clicked in JQUERY? What could be the issue here?

Why is my purple overlay with yellow text showing only once after the button is clicked, even though I have toggled the function? Check out my codepen to test the issue: https://codepen.io/cat999/project/editor/AEeEdg $('.animate-this').cl ...

Enhance the Vue.js performance by preloading components

After discovering the benefits of lazy loading components, I decided to start implementing it in my project. However, I encountered some issues when trying to prefetch the lazy loaded components and vue-router routes. Upon inspecting with Chrome DevTools, ...

Enhancing the appearance of list options in Autocomplete Material UI by utilizing the renderOption feature

I'm putting in a lot of effort to customize the option elements in the autocomplete list. My plan is to achieve this using the renderOptions prop, where I can create DOM elements and easily apply styles with sx or styled components. However, somethin ...

Preventing pageup/pagedown in Vuetify slider: Tips and tricks

I am currently using Vuetify 2.6 and have integrated a v-slider into my project. Whenever the user interacts with this slider, it gains focus. However, I have assigned PageUp and PageDown keys to other functions on the page and would like them to continue ...

The function maybeStripe.apply is not defined

Greetings, Encountering a Stripe error in Gatsby upon page load Error: Uncaught (in promise) TypeError: maybeStripe.apply is not a function import React, { useEffect, useState } from 'react'; import { loadStripe } from '@stripe/str ...

How can I retrieve an array of collections from multiple parent documents in Firebase and pass them as props in Next.js?

I need to access all the collections within the documents stored in a collection named users. This is how I currently retrieve all the user information: export async function getServerSideProps() { const snapshot = await firebase .firestore() .collection ...

Validation on the client side for a form that is displayed within a bootstrap modal using ajax technology

Within my ASP.Net Core application, I am faced with the need to utilize validation on both the server side and client side in a bootstrap modal form. While I have successfully implemented server side validation, I have encountered difficulties when it come ...

Transitions in Vue do not function properly when used in conjunction with a router-view containing a

Recently, I developed a component where I implemented router-view exclusively to facilitate route-based changes. It's worth mentioning that this is the second instance of router-view, with the first one residing in the App.vue component. Interestingly ...

Is Vue Router the key to enhancing navigation with dynamic transitions?

My goal is to configure my Vue App to utilize a linear navigation format in order to organize the final HTML documents that will be served through iFrame. . ├── School │ ├── SQL | | ├── SQL Basics | | ├── SQL Intermedia ...