Implementing Row Highlighting in a Vuetify Simple Table Component

Currently diving into the Vutify documentation to explore v-simple-table and v-data-table, wondering if there's a way to implement row highlighting similar to v-data-table.

For reference:

Vuetify - How to highlight row on click in v-data-table

This is how my table body is structured:

<v-simple-table dense fixed-header height="90vh" >
            <template v-slot:default>
              <thead > ;
              <tr >
                <th style="font-size: 16px;height: 40px;" width='4%' class="black--text">
                  Location
                </th>

(...rest of the original code...)

                      </template>
                    </td>
    
                  </template>
                </tr>
              </tbody>
            </table>

While I can currently hover over a row to display hover effects, my goal is to enable changing the background color of a row upon selection through a click event.

I'm aiming for an outcome akin to this example, adapted to work with a simple table:

Answer №1

Here is a Vue-focused solution...

template:


   <tbody>
        <tr
          v-for="(item,idx) in items"
          :key="item.name"
          @click="handleClick(idx)"
          :class="{ selected: selected.includes(idx) }"
        >
          <td>{{ item.name }}</td>
          <td>{{ item.calories }}</td>
        </tr>
   </tbody>

script:


  data () {
    return {
      items: [
        {
          id: 1,
          name: "Frozen Yogurt",
          calories: 159,
          fat: 6.0,
          carbs: 24,
          protein: 4.0,
          iron: "1%",
        },
      ],
      selected: [],
    }
  },
  methods: {
    handleClick(i) {
        let index = this.selected.indexOf(i)
        if (index > -1) {
            this.selected.splice(index, 1);   
        }
        else {
            this.selected.push(i)
        }
    },
  }

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

Creating a dynamic form that efficiently captures user information and automatically redirects to the appropriate web page

Sorry for the unusual question, but it was the best way I could think of asking. I have come across websites with fill-in-the-blank lines where you can input your desired information and then get redirected to another page. For example: "What are you sea ...

Using AngularJS to filter options in a dropdown list and trigger a function with ng-change

I have a dropdown menu that is being formatted using filters to display the text in a certain way. I need to send the selected item's ID value to the controller instead of just the name: <select ng-model="my_field" ...

Why isn't the Full Calendar loading automatically within a Bootstrap Tab?

I have been working on a travel website and incorporated a bootstrap tab feature. In the first tab, I have some content, while in the second tab, I've added a full calendar with JavaScript. Everything seems to be functioning correctly when the full ca ...

Managing multiple to-do lists within a React application using parent-child relationships

ReactJS has a flaw that I've come across while trying to create a Todo application using Redux for state management. The issue arises when dealing with nested JSON data, such as having parent and child nodes in the response from a database query. Red ...

Tips for implementing picker options to limit the starting date in the Element UI date-picker

I'm currently developing a web application using Element UI, with a specific focus on the el-date-picker component. Here is the code I have written for defining a period using two calendars. However, I am facing difficulty in applying picker-options ...

Problem with opening the keyboard feature in an Ionic app

Hello everyone, I'm relatively new to Ionic development and I've been trying to integrate a keyboard plugin into my application that opens from the footer and focuses on input fields for entering values. Here is the link to the plugin I used: ht ...

searching backwards using regular expressions

I have successfully extracted <%? imagepath;%> using the following regex from a string. <%(\?|.|\s)*%> <img src="http://abc/xyz/<%? imagepath;%>.gif"> <img not_src="http://abc/xyz/<%? imagepath;%>.gif"> <i ...

Different methods for dynamically altering the style attribute

Here's some code I wrote: <html> <head> <style> .containerTitle { background-color:silver; text-align:center; font-family:'Segoe UI'; font-size:18px; font-weight:bold; height:30px; } ...

Is it common practice to provide a callback function as a parameter for an asynchronous function and then wrap it again?

app.js import test from "./asyncTest"; test().then((result)=>{ //handle my result }); asyncTest.js const test = async cb => { let data = await otherPromise(); let debounce = _.debounce(() => { fetch("https://jsonplaceholde ...

Is the memory usage of node.js proportional to the number of concurrent requests, or is there a potential memory leak?

Running the following node.js code: var http = require('http'); http.createServer(function(req,res){ res.writeHead(200,{'Content-Type': 'text/plain'}); res.write("Hello"); res.end(); }).listen(8888); Upon starting the server ...

Mastering the art of Puppeteer with Javascript

I am currently learning how to make web requests using JavaScript with puppeteer. After some trial and error, I was able to extract the value of a tag from a random website. However, I am struggling to figure out how to retrieve 10 consecutive values of ...

Unable to utilize a function within a mongoose schema

I encountered an issue while attempting to access the schema methods of a mongoose schema in TypeScript. Schema const userSchema: Schema<IUser> = new Schema( { name: { type: String, required: [true, "Name is required"], ...

How can I use the select2 jQuery plugin with the tags:true option to ensure that selected choices do not appear again in the dropdown menu?

Transitioning to select2 for tagging from a different plugin, I'm facing a gap that I need to address in select2's functionality. Let's consider an example. Suppose my list of choices (retrieved server-side via Ajax request) is: "Dog", "Ca ...

The challenges encountered with JSONP/Ajax Script - displaying 'Undefined'

I need help retrieving data from a webserver that I don't have control over. I've searched online but haven't found a solution yet. I've tried various codes, with and without DataTables. If anyone could provide guidance on where to go ...

Show a modal when the axios request is finished

EDIT: After some exploration, I've shared the solution I found in case it helps others facing a similar issue. I'm currently working on building a reusable Bootstrap 5 modal child component within Vue3. The goal is to pass an ID as a prop from t ...

Steps to make a pop-up window for text copying by users

On my website, I have a link that users need to copy for various purposes. I want to provide an easy way for them to see the link and then manually copy it to their clipboard. Instead of using code to copy to the clipboard, I am looking for a solution whe ...

The node server is experiencing difficulties connecting to the mysql database, resulting in a timed out connection error at Connection._handleConnectTimeout

Having trouble establishing a connection with the mysql database. Every time I attempt to start the node server, it keeps throwing a database connection error. The specific error message is as follows: connect ETIMEDOUT at Connection._handleConnectTimeou ...

evaluate individual methods within a stateless component with unit testing

I am working with a stateless component in React that I need to test. const Clock = () => { const formatSeconds = (totalSeconds) => { const seconds = totalSeconds % 60, minutes = Math.floor(totalSeconds / 60) return `${m ...

What is the best way to retrieve the chosen table row (tr) in this situation?

I have a table displayed below: How can I retrieve the selected mobile number of the tr when a button is clicked? <table class="table table-striped table-bordered table-hover table-full-width dataTable" id="sample_2" aria-describedby="sample_2_info"&g ...

Styling with the method in React is a beneficial practice

I am working on a simple React app that includes some components requiring dynamic styling. I am currently using a method to achieve this, but I am wondering if there are other recommended ways to handle dynamic styling in React. Everything seems to be wor ...