The alignment of headers and data in the vuetify data table is off

I am currently facing an issue with the alignment of header values and data values in Vuetify data tables. I have tried setting "align: 'left'" but it is still not aligned properly.

Below is my Vue component:

    <template>
  <v-data-table
    :headers="headers"
    :items="items"
    :items-per-page="8"
    :hide-default-footer="true"
    hide-actions
    item-key="name"
    class="elevation-1"
    >
   <template slot="items" slot-scope="props">
      <td v-for="(header, index) in headers" :key="index">
          <span v-if="(header.template !== 'undefined' && header.template === 'aId')">
            <span>
                {{ props.item[header.value] }}
            </span>
          </span>
          ...
      </td>
   </template>
</v-data-table>
</template>
<script>
 export default {
    name: 'TestDataTable',
    props: {
        headers: {
            required: true,
            type: Array,
            default: () => {
                return [];
            }
        },
        items: {
            required: true,
            type: Array,
            default: () => {
                return [];
            }
        }
    }
 }
</script>

Current output:

https://i.sstatic.net/A8BxF.png

Can someone assist me with this issue? Also, how can I apply a background color (#E6E6E6) to the header?

Answer №1

Avoid using the span or p tag when setting conditions for displaying data,

Instead, consider using the template tag

For example:

<v-data-table
:headers="headers"
:items="items"
:items-per-page="8"
:hide-default-footer="true"
hide-actions
item-key="name"
class="elevation-1"
>
<template slot="items" slot-scope="props">
  <td v-for="(header, index) in headers" :key="index">
      <template v-if="(header.template !== 'undefined' && header.template === 'aId')">
            {{ props.item[header.value] }}
      </template>
      <template v-else-if="(header.template !== 'undefined' && header.template === 'aName')">
            {{ props.item[header.value] }}
      </template >
      <template v-else-if="(header.template !== 'undefined' && header.template === 'aType')">
            {{ props.item[header.value] }}
      </template>
      <template v-else-if="(header.template !== 'undefined' && header.template === 'aStatus')">
            {{ props.item[header.value] }}
      <template v-else-if="(header.template !== 'undefined' && header.template === 'aLocation')">
            {{ props.item[header.value] }}
      </template>
      <template v-else-if="(header.template !== 'undefined' && header.template === 'aZone')">
            {{ props.item[header.value] }}
      </template>
      <template v-else>
            {{ props.item[header.value] }}
      </template>
  </td>
 </template>
 </v-data-table>

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

Updating a select dropdown's choices or values based on the selection of another select dropdown using JavaScript

I am working with two HTML select elements. Below is an example of the code: <select class="select1" onchange='customJavascriptfuntion()'> <option value='a'>a</option> <option value='b'>b</option> ...

Can WebSocket messages be encoded?

Is there a way to encrypt or obscure the data I transmit via websockets? For example, the message looks like this: var encryptedMsg = { type: "message", data: { message: "Hello world!" } } I require the ability to send this message in ...

What is the best way to monitor useNavigate in React unit testing?

While working on my unit test, I encountered an issue where I am trying to test if useNavigate has been called after clicking on a button and if it has been called with the correct path. However, I am facing an error when attempting to spy on it. The error ...

Angular-jasmine: conducting tests on a component that utilizes timeout to render the DOM

Within my custom directive, I have implemented the following functionality: link: function (scope, element) { var editor = CKEDITOR.inline(element.find('div[contenteditable]')[0], {} To ensure that the directive is properly linked and that ...

Implementing a Delay using SetTimeout in a Single Function

I could really use your assistance. Whenever I run the iframe and click code separately in the code below without using settimeout, everything works fine. However, once I include settimeout for both, I encounter a "findo is not defined" error. setTimeout ...

Values do not appear as expected post PDF conversion using wkhtmltopdf

Currently, I am updating certain values within my HTML page by following this process: The function: function modifyContent(){ var newTitle = document.getElementById('myTextField1').value; if( newTitle.length==0 ){ alert('Plea ...

What could be the reason behind the occurrence of an invalid hook error when utilizing an imported function

I'm currently working on creating a navigation bar for a dashboard page, but I've run into an issue. Everything works fine until I try to integrate the navbar by importing and executing the function. I can pinpoint that the problem occurs when in ...

Utilize Twilio to forward messages to a different phone number

I am seeking a solution to automatically forward incoming messages from one Twilio number to another, based on the original sender's number. For example: If I receive a message on my Twilio number "+14444444444" from '+15555555555', I want ...

Issue with rendering partials in ExpressHandlebars in NodeJS

I am currently facing an issue while working with express-handlebars. I am attempting to use partials, but I keep encountering the following error message: The partial header could not be found. In my app.js file, the code appears as follows: var expr ...

The "self" variable in the Node.js prototype object fails to retain the correct context for the callback function

Although I have experience as a developer, I am new to Java Script and Node.js. I have searched through various examples and Stack Overflow answers, but I couldn't find a simple and complete example of a prototypical class with correct 'self&apos ...

Deciphering basic XML with Javascript/Ajax

I am trying to update the content on a page dynamically based on an XML Ajax response. To test this functionality, I have created a static PHP-generated XML file with just one tag. If the tag contains the text "yes", it should show "AVAIL"; otherwise, it s ...

Send data without needing to navigate away

Is there a way to submit a form without redirecting the page? The form is being submitted to a third party, so I am unable to make changes in PHP. I would like to submit the form without visiting the third party page. After successful submission, I want ...

Generating intricate arrays from a given list

If I have an array containing various items like the following: [ ["Core", "Mathematics", "Mathematics 20-4"], ["Core", "Mathematics", "Mathematics 30-1"], ["Other", "Fine Arts", "Art", "some art course"], ["Other", "Fine Arts", "Music", " ...

"Explore each row within the nested grid by hovering over them from the main parent

I want to implement a hover effect on each row within a nested grid that is displayed by columns instead of rows. The layout appears as follows: Grid Column The column displays a grid with only rows Check out this jsfiddle for the structure. I hav ...

Discovering the proper method of validating radio buttons is vital

Using VeeValidate rules, you can validate a select input with the "oneOf" rule. Check out more on VeeValidate Rules <ValidationProvider rules="oneOf:1,2,3" name="number" v-slot="{ errors }"> <select v-model="va ...

What is the reason for setting the initial value of a Vue computed property to a Javascript object property?

Can someone please explain why the Javascript object property, data.test, always holds the initial value of the computed property, square? Even after submitting a number in the input field, data.test remains set to 4. On the other hand, the computed proper ...

The React rendering process failed when attempting to utilize a stateless component

Struggling to integrate a stateless component with fetch in my project. The fetch API is successfully retrieving data, but for some reason, the stateless component remains blank. import React, { PropTypes } from 'react'; import { Card, CardTitle ...

Setting up environment variables for a production Vue build

My goal is to accomplish the following: Create a Vue application using npm build, Copy the /dist result to a specific environment, Have a static setting file in the environment with name=value settings, Allow the Vue application to read these settings fr ...

Acquiring JSON data from Node.js within Angular

After searching everywhere, I finally managed to retrieve all the data from my database using node and saved it into a file. The data is simple JSON chat logs that can be accessed through my browser with ease. Here's a snippet of how it looks: [{ " ...

Manipulating HTML content with jQuery

Review the code snippet provided below <div id="post-1234"> <h3><a href="some link">text</a></h3> <div> <div> <div> <span class"Event-Date">Event Date 1</span> </div> < ...