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" associated with the column it was dropped in. How can I accomplish this? I couldn't find any examples about APIs in the documentation. https://i.sstatic.net/sneeT.png

<template>
  <div class="board">
    <div class="boards">
      <div class="boards-cards leads">
        <div class="board-card-header ">
          <h3>
            Leads
          </h3>
          <span>
            {{ allLeads.length }}
          </span>
        </div>
        <draggable
          ghost-class="ghost"
          :list="allLeads"
          class="board-card-body"
          :options = "{group:allLeads}"
          group="leads"
          @change="handleChange"
          
        >
          <BoardUserCard
            v-for="item in allLeads"
            :key="item.name"
            :name="item.name"
            :email="item.email"
            :img="item.img"
            :status="item.status"
            
          />
        </draggable>
      </div>
      <div class="boards-cards contacted">
        <div class="board-card-header ">
          <h3>
            Contacted
          </h3>
          <span>
            {{ contactedLeads.length }}
          </span>
        </div>
        <draggable
          ghost-class="ghost"
          :list="contactedLeads"
          class="board-card-body"
          :options = "{group:contactedLeads}"
          group="leads"
          @change="handleChange"
          
        >
          <BoardUserCard
            v-for="item in contactedLeads"
            :key="item.name"
            :name="item.name"
            :email="item.email"
            :img="item.img"
            :status="item.status"
            
          />
        </draggable>
      </div>
      <div class="boards-cards converted">
        <div class="board-card-header ">
          <h3>
            Converted
          </h3>
          <span>
            {{ convertedLeads.length }}
          </span>
        </div>
        <draggable
          ghost-class="ghost"
          :list="convertedLeads"
          class="board-card-body"
          :options = "{group:convertedLeads}"
          group="leads"
          @change="handleChange"
          
        >
          <BoardUserCard
            v-for="item in convertedLeads"
            :key="item.name"
            :name="item.name"
            :email="item.email"
            :img="item.img"
            :status="item.status"
            
          />
        </draggable>
      </div>
    </div>



  </div>
</template>

<script>
import BoardUserCard from "@/components/BoardUserCard.vue";
import draggable from "vuedraggable";

export default {
  name: "Dashboard",
  components: {
    BoardUserCard,
    draggable,
  },
  data() {
    return {
      showModal: false,
      allLeads: [
        {
          name: "Richard",
          email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e6b48f858e879482a6818b878f8ac885898b">[email protected]</a>",
          img: "avatar-small.svg",
          status: "all"
        },
        { name: "Rachael", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="782a191b10191d14381f15191114561b1715">[email protected]</a>", img: "leads.svg", status: "all" },
        { name: "Matt", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="521f33262612353f333b3e7c313d3f">[email protected]</a>", img: "user-avatar.svg",status: "all" },
        { name: "Brad", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e4a6968580a48389858d88ca878b89">[email protected]</a>", img: "leads.svg", status: "all"},
      ],
      contactedLeads: [
        {
          name: "Jeniffer",
          email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e1ab848f8887878493a1868c80888dcf828e8c">[email protected]</a>",
          img: "avatar-small.svg",
          status: "contacted"
        },
      ],
      convertedLeads: [
        { name: "Mike", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45082c2e20052228242c296b262a28">[email protected]</a>", img: "leads.svg", status: "converted" },
      ],

    };
  },
  methods: {
    openModal() {
      this.showModal = true;
    },
    closeModal() {
      this.showModal = false;
    },
    handleChange(event){
      console.log(event)
    }
  },
};
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

Answer №1

To include a data attribute in the component, simply add data-id="4"

     <draggable
          ghost-class="ghost"
          :list="convertedLeads"
          class="board-card-body"
          :options="{group: convertedLeads}"
          group="leads"
          @end="handleChange"  
          data-id="4"     
        >
You can then access the data-id attribute in the handleChange function like so:

    handleChange(event){
      console.log(event.from.getAttribute("data-id"))
      console.log(event.to.getAttribute("data-id"))
    }

`

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

How can I remove a row from an MVC webgrid using an ajax call?

Within my MVC Razor view, I have a partial view containing webgrid data. My goal is to include an action link to delete a specific row of data. To accomplish this, I crafted the following JavaScript function: function delMeal(pid) { if (confirm("Do yo ...

Is it recommended to utilize addEventListener?

Is it better to use the addEventListener method in these scenarios? <input id="input" type="file" onchange="fun()> or document.getElementById("input").addEventListener("change", function() { fun(); }); What are the advantages of using one over ...

What is the best way to check if an object exists in an array in JavaScript and update it if it does, otherwise add it as a new object in

I am working with an array of objects const target = [{name: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89fafbe2c9eee4e8e0e5a7eae6e4">[email protected]</a>', selected: false, alertType: 'max&ap ...

I'm looking for a solution to pass a PHP object as a parameter in JavaScript within an HTML environment,

I am currently working on a project using Laravel 5. I have a table in my view, and I want to pass all the data values to a JavaScript function when a link is clicked. I have tried several methods but have been unsuccessful so far. @foreach ($basl_offic ...

Refreshing Three.js Scene to its Initial State

I am in the process of developing a Visual Editor where I can manipulate objects by adding, deleting, and transforming them. Currently, my scene only consists of a 5000x5000 plane as the floor. I am looking for a way to reset the scene back to its origin ...

What causes a ReferenceError when attempting to retrieve the class name of a React component?

Take a look at my React component located in index.js: import React from 'react' import ReactDOM from 'react-dom' class App extends React.Component { render() { return ( <div className="App"> <h1>Hello, ...

Introducing HTML elements into pre-existing web pages

My interest lies in the idea of injecting HTML into existing web pages for enhanced functionality. Specifically, I am exploring the concept of creating a more efficient bookmarking system. As someone new to web development, I am unsure of how to achieve th ...

Customizing Images using a JSON array of images

Looking to implement a feature that displays images fetched from a CMS via a JSON file. The JSON data structure is as follows: { "images": [ {"title": "Image One", "url": "image1.jpg"}, {"title": "Image Two", "url": "image2.jpg"}, {"title": "Ima ...

`Incorporate concurrent network requests in React for improved performance`

I am looking to fetch time-series data from a rest service, and currently my implementation looks like this async function getTimeSeriesQuery(i) { // Demonstrating the usage of gql appollo.query(getChunkQueryOptions(i)) } var promises = [] for(var i ...

Vertical stability bar

I need help creating a vertically fixed navigation bar for my website. Currently, I am using a method that has been discussed in various posts: HTML: <html> <head> src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">< ...

Choose the date that is exactly 48 hours from now

I need to implement a date picker that shows today's date and the next 2 days in a select component. Can this be achieved using JavaScript and jQuery? While I came across a similar post on the topic, I specifically want it to work with a date picker: ...

Does utilizing this.someFunction.bind(this) serve a purpose or is it duplicative

As I analyze someone's code, I stumbled upon the following snippet: this.device_name.changes().onValue(this.changeName.bind(this)) My interpretation so far is that onValue requires a callback function, which in this case is this.changeName.bind(this ...

Unable to retrieve the data-id from the ajax response for extraction and transfer to the modal

I am encountering an issue when trying to retrieve the data-id from an AJAX response within a href tag. The response always returns as undefined. $("#loader_ekpresi").show(); $.ajax({ url:"<?php echo site_url() ?>Home/get_ekspresi", type:& ...

When using a PhoneGap app to access a webservice, are there any potential cross-site issues that could arise?

How can I access an external web service from a PhoneGap app using AJAX without needing to rely on CORS or JSONP to bypass the cross-origin issue? I've come across a question on Stack Overflow suggesting that cross-site HTTP calls are not a problem wi ...

Error: Attempting to display API data in a CardView using NativeScript-Vue results in a TypeError stating that property 'endpoint_link_1' is undefined

Greetings, I am a beginner in NativeScript-Vue and JavaScript. I do not have extensive experience with heavy Javascript coding. I am facing an issue with displaying data fetched from an API in CardViews. Below is the code snippet I attempted: <template ...

When watching YouTube videos in full screen mode on F11, the IFrame zooms in excessively, causing the video quality to suffer

After using the same code as the website Virtual Vacation, I noticed that they are experiencing the same issue as me. I am considering reaching out to them to inform them about it, but I am struggling to find a solution on my own. Specifically on WINDOWS ...

Error: Jest react testing encountered an issue when attempting to read the property 'type' from an undefined value

While conducting tests on my app components created with the material UI library using jest and enzyme, I encountered an error in one of my packages. Here is a screenshot of the error: Click here to view ...

Sending a JavaScript value to PHP after a quiz has been completed

I've created a web page where users can take quizzes. These quizzes dynamically generate questions using JavaScript each time they are accessed. Disclaimer: I'm fairly new to JavaScript. Once the user completes the quiz, they receive their fina ...

Authentication in HTML5 beyond the internet connection

Seeking feedback on the most effective way to control access to an HTML5 application that is primarily used offline. This application utilizes IndexedDB, local, and session storage to securely store data for offline use, all served via HTTPS. The main go ...

Tips for executing an asynchronous fetch prior to the first rendering

Currently, I am working with the Wordpress API using Next.js on the front end. My goal is to fetch my navigation/menu data and have it pre-rendered. However, my attempts have only resulted in an empty <nav> </nav> element being rendered when I ...