instructions on modifying a singular row within a v-data-table (excluding design changes, focusing on the data itself)

For this specific scenario involving v-data-table, I encountered a challenge in finding an answer. While I am aware that templates and slots can be utilized to modify columns, my query pertains to reflecting values in only one row. Essentially, I aim to add a logo when a user right-clicks on the name column, indicating that the value has been copied, and then remove it after 3 seconds, creating a toggle effect.

The functionality works smoothly when clicking on a name within a particular row, successfully copying the link value using the vue-clipboard library. However, the issue arises as this action is replicated across all columns containing links, rather than being restricted to just one. As I was unable to execute the vue-clipboard library in a sandbox environment, I have provided snippets of the code for reference.

To illustrate the current behavior more effectively, attached is a screenshot from the v-data-table displaying a check icon in both rows, despite only interacting with the first one. The desired outcome would involve showing the check icon exclusively in the cell that was clicked.https://i.sstatic.net/hNqwT.png

Template;

<template>
    <v-data-table
        :headers="headers"
        :items="tableData"
        class="display-stats"
        :items-per-page="5"
        :footer-props="{
            'items-per-page-options': rowsPerPageItems,
        }"
        >
        <template v-slot:[`item.name`]="{ item }">
            <span v-if="item.link" class="link-span" @contextmenu="copyLink(item.link)">
            <a class="preview-link" :href="item.preview" target="_blank">{{ item.name }}</a>
            <p v-show="copied">
                <v-icon small :color="green">fas fa-check</v-icon>
            </p>
            </span>
            <span v-else>
            {{ item.name }}
            </span>
        </template>
    </v-data-table>
</template>

Script;

<script lang="ts">
import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'

VueClipboard.config.autoSetContainer = true // include this line
Vue.use(VueClipboard)


interface PriceStats {
  rowsPerPageItems: Number[]
  copied: boolean
}

export default Vue.extend({
  name: 'Component',

  props: {
    priceData: {
      type: Array as () => Array<PriceStats>,
      default: () => {},
    },
    loading: {
      type: Boolean,
      default: false,
    },
  },
  data(): PriceData {
    return {
      rowsPerPageItems: [10, 20, 30],
      copied: false,
    }
  },
  computed: {
    tableData:{
      get():PriceStats[]{
        if (this.priceData) {
          return this.priceData
        } else {
          return []
        }
      },
      set(newVal:PriceStats){
        this.tableData=newVal
      }
    },

    headers(): DataTableHeader[] {
      return [
        {
          text: 'Name',
          value: 'name',
        },
        {
          text: 'Age',
          value: 'age',
          align: 'center',
        },
        {
          text: 'Salary',
          value: 'salary',
        },
        {
          text: 'Position',
          value: 'format',
        },
        {
          text: 'Date',
          value: 'date',
        },
        {
          text: 'Premium',
          value: 'premium',
          align: 'right',
        },
      ]
    },

  },
  methods: {
    copyLink(previewLink: string) {
      this.$copyText(previewLink).then(
        (e) => {

          this.copied = true
          setTimeout(()=> {
            this.copied = false
          },3000)
        },
        (e) => {
          need an error logic here
          this.copied = false
        }
      )
    },
  },
})
</script>

Answer №1

Assuming each user has a unique name, you can implement a check to see if the name matches the copied one and then display an icon accordingly:

<v-data-table ...>
<span v-if="item.link" class="link-span"  @contextmenu="copyLink(item.link,item.name)">
            <a class="preview-link" :href="item.preview" target="_blank">{{     item.name }}</a>
           <p v-show="item.name == copiedName">
             <v-icon small :color="green">fas fa-check</v-icon>
           </p>
            </span>
     </v-data-table>

copiedName can represent an external variable where the user's name is stored after using the copyLink function.

...

copyLink(previewLink: string,name) {
      this.$copyText(previewLink).then(
        (e) => {

          this.copied = true
          this.copiedName = name

          setTimeout(()=> {
            this.copied = false
          },3000)
        },
        (e) => {
          // Error handling code goes here
          this.copied = false
        }
      )
    },

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

Exploring Methods for Retrieving offsetHeight and scrollHeight in AngularJS

I am currently developing a directive that requires three specific values: scrollTop offsetHeight scrollHeight projectModule.directive('scroller', function ($window) { return { restrict: 'A', link: function (scope, elem, attrs) { ...

When attempting to debug JavaScript in Edge with Visual Studio Code, an error message stating 'Failed to load source map for chrome-error...' was encountered

Attempting to troubleshoot JavaScript code in Visual Studio Code is resulting in an error: Could not read source map for chrome-error://chromewebdata/: Unexpected 503 response from chrome-error://chromewebdata/edge-elixir-neterror.rollup.js.map: Unsupporte ...

Incorporating CASL with the latest version of Angular, version

I'm currently working on implementing CASL into my Angular application, but I'm having trouble understanding how to integrate it. // Login Component ngOnInit() { var jsonBody = {}; jsonBody['email'] = 'peter@klaven'; ...

Users are reporting a problem with the PrimeNG confirmation dialog where it becomes unresponsive and locks up the screen

Previously functioning code seems to have been affected by an update to PrimeNG. The confirmation dialog that was once usable is now hidden behind a gray click-mask, rendering everything on the screen unclickable: The HTML structure for these two dialogs ...

I am looking to modify the highlighted table cell whenever the value within it changes

I am currently working on a small project related to the Stock Market. In this project, I need to dynamically change the style of the td element based on data fluctuations - green highlight for an increase and red highlight for a decrease. In the provid ...

Tips for altering the class of an HTML button dynamically when it's clicked during runtime

I currently have a set of buttons in my HTML page: <button id="button1" onclick="myFunction()" class="buttonClassA"></button> <button id="button2" onclick="myFunction()" class="buttonClassA"></button> <button id="button3" onclic ...

Setting the width of an image within an iframe: A step-by-step guide

Is there a way to adjust the width of an image within an iframe? Typically, if an image with high resolution is placed inside an iframe, the iframe becomes scrollable by default. ...

Using Omit<T,K> with enums does not yield the expected result in Typescript

The setup includes an enum and interface as shown below: enum MyEnum { ALL, OTHER } interface Props { sources: Omit<MyEnum, MyEnum.ALL> } const test: Props = { sources: MyEnum.ALL } // triggering a complaint intentionally I am perplexed b ...

Challenges regarding variable scope in JavaScript

Presented below is the JavaScript code I am currently using, which involves jQuery: function language(language) { var text = new Object(); $.ajax({ type: "GET", url: "includes/xml/languages/" + language + ".xml", dataType: ...

Exploring the PayPal Checkout JavaScript SDK's CreateOrder call and interpreting the response

I am currently exploring how to use the JavaScript SDK to display PayPal payment buttons on a website. I am new to working with JSON and REST API calls, so I am facing some challenges in implementing this. The createOrder function is running smoothly and ...

Italian calendar conversion for the react-multi-date-picker library

I recently integrated the react-multi-date-picker into my project, utilizing the multiple mode feature. However, I encountered an issue when trying to display the Italian calendar based on the language setting. Despite using locale="it", the calendar was n ...

Prevent onClick event in jQuery and extract parameters from a function call

We've been tasked with implementing a temporary solution to some code, so it might seem a bit silly at first. But please bear with us. The goal is to block the onclick method of an anchor tag, extract the parameters from the function call, and then u ...

There was a parsing error due to encountering an unexpected reserved word 'interface' in the code, as flagged

I'm encountering an issue with my code when trying to utilize Props. The error message I'm receiving is "Parsing error: Unexpected reserved word 'interface'. (3:0)eslint". This project is being developed using next with TypeScript. Er ...

problem with transmitting information through $.ajax

I'm facing a frustrating issue with the $.ajax()... function in my PHP code. I am unable to retrieve the data sent by the ajax request. <?php if ($_POST){ include 'Bdd_connexion.php'; $filiere = $_POST['filiere']; ...

The database powered by Postgresql performs flawlessly when it comes to updating data with accurate code execution. However, there seems to be an

Imagine a zoo with a postgresql database. To enable web access to this database, I am using php and javascript. Most of the web pages are working fine, but I am currently working on a page where clients can add or remove animals from existing exhibits. T ...

Steps for setting the value of a textbox within a bootstrap popover

When a user clicks on an Anchor element, I am displaying a Bootstrap popover using the following JQuery code. Jquery $("[data-toggle=popover]").popover({ trigger: 'click', placement: "top", html: true, ...

Sails encountering CORS preflight error due to cross-origin request

I am new to creating hybrid apps and have been following some tutorials. However, I encountered these errors on my browser console: Refused to load the script 'http://192.168.1.142:35729/livereload.js?snipver=1' due to Content Security Policy di ...

Obtaining various values for checkboxes using dynamic data in a React application

Retrieve all checkbox values dynamically import * as React from "react"; import Checkbox from "@mui/material/Checkbox"; import FormControlLabel from "@mui/material/FormControlLabel"; import axios from "axios"; expor ...

React: The error message is saying that it cannot retrieve the 'handler' property because it is either undefined or null

I'm having some trouble with event handlers in my React.js project. Every time I try to create an event handler outside of the render function, I end up with an error. Can anyone help me figure out what I'm doing wrong? class CheckboxHandler ext ...

The Javascript code is failing to run following an ajax request

When I use XMLHttpRequest.send to call a php script that contains some javascript code, the javasript in the called php script does not run. The process of making the call: var formdata = new FormData(); formdata.append("uploadfilename", file); var ajax ...