Choosing which row to display on a Vuetify v-data-table has never been

Is there a way to highlight a selected row in v-data-table by popping it out? I am currently working on adding an edit functionality within the v-data-table, as shown in this image https://i.sstatic.net/LqGZw.png. If anyone could provide assistance with this, it would be greatly appreciated. I have experience with VueJs, but not as much with CSS.

Answer №1

If you're working with Vuetify and utilizing a v-data-table with selection, consider targeting the Vuetify CSS selector to customize the background color as needed. Alternatively, if the selection box on the left provides sufficient visualization, you may opt not to target the selected line and add background-color accordingly.

.theme--light.v-data-table tbody tr.v-data-table__selected {
    background: green !important;
}
<!DOCTYPE html>
<html>
<head>
  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/@mdi/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85e3eaebf1c5b1abfd">[email protected]</a>/css/materialdesignicons.min.css" rel="stylesheet>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3b5b6a6b7aaa5ba83f1edbb">[email protected]</a>/dist/vuetify.min.css" rel="stylesheet>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
  <div id="app">
    <v-app>
      <v-main>
        <template>
          <v-data-table
            v-model="selected"
            :headers="headers"
            :items="desserts"
            :single-select="singleSelect"
            item-key="name"
            show-select
            class="elevation-1"
          >
            <template v-slot:top>
              <v-switch
                v-model="singleSelect"
                label="Single select"
                class="pa-3"
              ></v-switch>
            </template>
          </v-data-table>
        </template>
      </v-main>
    </v-app>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed9b9888addfc395">[email protected]</a>/dist/vue.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="17616272637e716e5725396f">[email protected]</a>/dist/vuetify.js"></script>
  <script>
    new Vue({
      el: '#app',
      vuetify: new Vuetify(),
      data () {
      return {
        singleSelect: false,
        selected: [],
        headers: [
          {
            text: 'Dessert (100g serving)',
            align: 'start',
            sortable: false,
            value: 'name',
          },
          { text: 'Calories', value: 'calories' },
          { text: 'Fat (g)', value: 'fat' },
          { text: 'Carbs (g)', value: 'carbs' },
          { text: 'Protein (g)', value: 'protein' },
          { text: 'Iron (%)', value: 'iron' },
        ],
        desserts: [
          {
            name: 'Frozen Yogurt',
            calories: 159,
            fat: 6.0,
            carbs: 24,
            protein: 4.0,
            iron: '1%',
          },
          {
            name: 'Ice cream sandwich`,
            calories: 237,
            fat: 9.0,
            carbs: 37,
            protein: 4.3,
            iron: '1%',
          },
          {
            name: 'Eclair',
            calories: 262,
            fat: 16.0,
            carbs: 23,
            protein: 6.0,
            iron: '7%',
          },
          {
            name: 'Cupcake',
            calories: 305,
            fat: 3.7,
            carbs: 67,
            protein: 4.3,
            iron: '8%',
          },
          {
            name: 'Gingerbread',
            calories: 356,
            fat: 16.0,
            carbs: 49,
            protein: 3.9,
            iron: '16%',
          },
          {
            name: 'Jelly bean',
            calories: 375,
            fat: 0.0,
            carbs: 94,
            protein: 0.0,
            iron: '0%',
          },
          {
            name: 'Lollipop',
            calories: 392,
            fat: 0.2,
            carbs: 98,
            protein: 0,
            iron: '2%',
          },
          {
            name: 'Honeycomb',
            calories: 408,
            fat: 3.2,
            carbs: 87,
            protein: 6.5,
            iron: '45%',
          },
          {
            name: 'Donut',
            calories: 452,
            fat: 25.0,
            carbs: 51,
            protein: 4.9,
            iron: '22%',
          },
          {
            name: 'KitKat',
            calories: 518,
            fat: 26.0,
            carbs: 65,
            protein: 7,
            iron: '6%',
          },
        ],
      }
    },
    })
  </script>
</body>
</html>

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

Implement a transition effect for when elements change size using the `.resizable().css` method

I attempted to incorporate a deceleration effect when resizing an element back to its original size using the resizable method. The slowdown effect should only trigger during the click event (when the "Click-me" button is pressed), not while manipulating ...

When the page loads, the HTML side menu will automatically scroll to the active item in a vertical

My website features a vertical side menu with approximately 20 items. The issue I am facing is that when a user clicks on an item, the destination loads but the side menu must be manually scrolled to find the active item if it's located at the bottom ...

Are there any quick tricks for condensing multiple hover CSS properties into a single line of code?

Imagine wanting to apply the hover CSS property to multiple classes, you would typically have to write it like this: a:hover, p:hover, div:hover{ // CSS properties } It can become repetitive having to add ":hover" to each class. Is there a way to stream ...

Is it possible to apply a tailwind class that fades or transitions into something else after a specific duration?

How can I achieve a transition effect from the bg-red-300 class to bg-transparent, or a different background class, over a 2-second duration? Do I need to use javascript for this effect? I would like an element to be highlighted and then return to its no ...

Error encountered in React JS: Anticipated input was "CALC", "dimension", "number", but received unexpected end of input. CompileError originates from undefined CSS selector

After completing my entire project, I encountered an error while running yarn build. The error message from Yarn is as follows: Parse error on line 1: ^ Expecting "CALC", "LPAREN", "ADD", "SUB", "FUNCTION" ...

Is there a way to locate button designs similar to Bootstrap's without actually relying on the

Looking to incorporate buttons with a similar style to those from Bootstrap into my web app. Does anyone have CSS styles available to achieve this look without relying on Bootstrap? Additionally, is there a collection of historical Bootstrap styles or te ...

What is the best way to understand and decipher this CSS code?

As I delve into customizing the CSS of an Internet theme, I am faced with a syntax that is unfamiliar and puzzling to me. One example from the theme is as follows: @media screen and(max-width: 768 px) { .wy-tray-container { bottom: auto;top: 0; ...

leveraging aria attributes to create collapsible elements

I am working on an expandable div element that expands when a user clicks on it. I want to ensure it is accessible for screen readers. Below is the code snippet: HTML <div class="expandable" (click)="expandItem()" attr.aria-expanded="isCollapsed"> ...

Customize a CSS attribute within Dojo

I am currently working with the enhanced grid in Dojo 1.10 version and I have encountered a simple problem that I am struggling to fix. I need to set a background-color CSS property for a table row, but there is already another background property applied ...

I'm struggling to understand how to upload pictures from my files onto my website

Adding images to my website has been more challenging than I expected. For example, if I have a folder named "images" on my computer's desktop with an image called "eye," will the following code display the image correctly? <img src="Desktop ...

How can I use JavaScript and HTML to print a canvas that is not within the print boundaries?

As someone who is new to javascript, I recently created a canvas function that allows me to successfully print. However, I am encountering an issue with printing large canvas areas. When I navigate to the further regions of the canvas and try to print, i ...

Problems with the navigation bar scrolling in Bootstrap

The project I'm currently working on is located at zarwanhashem.com If you'd like to see my previous question along with the code, you can check it out here: Bootstrap one page website theme formatting problems Although the selected answer help ...

How can I retrieve data from an API in Vue using promises?

Within my repository.js file, I have the following code snippet: async getAllContactRequests() { return new Promise(() => { axios .get("http://127.0.0.1:8000/api/contactRequests", { headers: { "Authorization&qu ...

What is the best way to utilize environment variables in a vuejs project that is utilizing a CDN?

I decided to use the Vuejs CDN for my app development. However, I encountered a problem when I needed to separate the development and production versions due to different API endpoints. I didn't want to expose my development API endpoint. How can I ac ...

What is the optimal unit to employ in CSS - percentages or pixels?

As someone who is not well-versed in CSS, I strive to create a design that will appear visually appealing across all browsers and screen resolutions. I have observed that certain websites construct their designs using percentages for properties like width, ...

Guide to updating a single item in a Vue.js store array

I'm still getting the hang of Vue and more recently Vuex. My current challenge is figuring out how to alter a specific post in the global state using vuex after an action has been executed. Let's take a look at the state for better context. // ...

What is the default margin for Autocomplete in Material UI?

Having just started with material-ui, I'm having trouble figuring out the margins of the Autocomplete. My form includes both Autocomplete and TextInput elements, but their positioning seems off to me. Is there some predefined margin box around Autocom ...

Achieving consistent column heights in Bootstrap by aligning neighboring columns

I am striving to achieve a layout similar to this: https://i.sstatic.net/HIEB4.png However, in Bootstrap, I am currently getting this: https://i.sstatic.net/sLw1v.png My desired layout specifications are as follows: Width ratios should be in the propor ...

Move your cursor over the image to activate the effect, then hover over it again to make the effect disappear

Looking to enhance my images with hover effects. Currently, all the images are in grayscale and I'd like to change that so that when you hover over an image, it reverts to full color and remains that way until hovered over again. I've noticed so ...

What steps do I need to take to activate CSS Modules in React version 16.13.1?

Hello everyone! I'm currently delving into tutorials and articles on how to activate CSS Modules in React 16.13.1. It's clear that the first step is to run "npm run eject", which I've already completed. The next step involves modifying the " ...