Vuetify's v-data-table is experiencing issues with displaying :headers and :items

I'm facing an issue while working on a Vue project with typescript. The v-data-table component in my Schedule.vue file is not rendering as expected. Instead, all I can see is the image below:

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

Despite searching extensively online, I have been unable to find a solution to this problem. At this point, I am considering starting over with a new project.

Below is the content of my Schedule.vue file:

<template>
  <div>
    <v-container>
      <v-row>
        <v-col>
          <v-data-table :headers="daoHeaders" :items="daoItems" :items-per-page="5" class="elevation-1">
            <v-toolbar-title>{{ dsTitle }}</v-toolbar-title>
          </v-data-table>
        </v-col>
      </v-row>
      <v-row>
        <v-col>
          This is below the table
        </v-col>
      </v-row>
    </v-container>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  data() {
    return {
      daoHeaders: [
        { title: 'Sport', key: 'sportName', align: 'start', sortable: true },
        { title: 'League', key: 'leagueName' },
        { title: 'Grade Level', key: 'gradeLevel' }
      ],
      daoItems: [
        { sportName: 'Basketball', leagueName: 'Spring Basketball League', gradeLevel: '6-12' }
      ],
      dsTitle: 'This is my Title'
    }
  },
  methods: {
  }
});
</script>

Next, let's take a look at my index.ts file:

/**
 * plugins/index.ts
 *
 * Automatically included in `./src/main.ts`
 */

// Plugins
import { loadFonts } from './webfontloader'
import vuetify from './vuetify'
import router from '../router'

// Types
import type { App } from 'vue'

export function registerPlugins (app: App) {
  loadFonts()
  app
    .use(vuetify)
    .use(router)
}

/**
 * main.ts
 *
 * Bootstraps Vuetify and other plugins then mounts the App`
 */

// Components
import App from './App.vue'

// Composables
import { createApp } from 'vue'

// Plugins
import { registerPlugins } from '@/plugins'

const app = createApp(App)

registerPlugins(app)

app.mount('#app')

Lastly, here is an overview of my tsconfig.json file:

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "ESNext",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "strict": true,
    "jsx": "preserve",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "lib": ["ESNext", "DOM"],
    "skipLibCheck": true,
    "noEmit": true,
    "paths": {
      "@/*": [
       "src/*"
      ]
     }
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/main.ts"],
  "references": [{ "path": "./tsconfig.node.json" }],
  "exclude": ["node_modules"]
}

Answer №1

If you're facing the issue of not being able to display the header in your v-data-table, a simple solution is to make a small change. Instead of using:

headers: [
{ text: 'Name user', value: 'name_user' },
 ]

try using:

headers: [
{ title: 'Name user', key: 'name_user' },
 ]

Answer №2

It appears that the naming conventions for your v-data-table headers need adjusting.

To properly display the data, consider changing your daoHeaders attributes from title and key to text and value.

FROM

daoHeaders: [
        { title: 'Sport', key: 'sportName', align: 'start', sortable: true },
        { title: 'League', key: 'leagueName' },
        { title: 'Grade Level', key: 'gradeLevel' }
      ],

TO

daoHeaders: [
          { text: 'Sport', value: 'sportName', align: 'start', sortable: true },
          { text: 'League', value: 'leagueName' },
          { text: 'Grade Level', value: 'gradeLevel' }
        ],

Output: https://i.sstatic.net/zkEdi.png

Answer №3

According to a comment by @MJenkins, the v-data-table on Vuetify 3 is currently a component from Labs, so it is required to import it either locally from Labs using:

import { VDataTable } from 'vuetify/labs/VDataTable'

or globally like this:

import { createVuetify } from 'vuetify'
import { VDataTable } from 'vuetify/labs/VDataTable'

export default createVuetify({
  components: {
    VDataTable,
  },
})

as stated in the official documentation.

If not imported, the v-data-table will be loaded similar to this structure:

<v-data-table data-v-hash="" modelvalue="" items-per-page="10" 
headers="[object Object],[object Object],[object Object]" 
items="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" 
item-key="key" search="" loading="false" hide-default-footer="" 
show-select="" fixed-header=""></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

What is the process for updating the internal TypeScript version in VS Code?

When using VS Code, I noticed it comes with its own TypeScript version: Is there a way to update this? The current version is 4.9.3. https://i.sstatic.net/vEx85.png ...

Looping through Vue with multiple options

Looking for help with Vue2 looping to display multiple options within a select element. We have an object structured like this; sorting = { name: [ 'asc', 'desc' ], price: [ 'cheapest', ...

Using Vue.js to implement dynamic table rowspan functionality

Has anyone experimented with implementing dynamic table rowspan in vue.js? Here is the sample data { date: '2018-08-14', temp_que : 120, }, { date: '2018-08-14', temp_que : 120, }, { date: '2018-08-15', ...

Having trouble locating the TypeScript compiler in Visual Studio 2017?

In an attempt to develop an application in Visual Studio using TypeScript, I meticulously followed the instructions outlined here and proceeded to install the necessary TypeScript compiler for version 2.2 of the project via NPM. npm install typescript ...

Utilizing the get and set methods to alter the structure of a string, but encountering the issue where the set method is

Upon receiving a datetime through an HTTP request, I need to format it before utilizing it. To achieve this, I utilize the get and set methods in my code. However, I noticed that the set method is never invoked. This is how my component (AdminComponent) l ...

Learn how to trigger an HTTP exception after a failed command in a saga with NestJS CQRS

Currently utilizing the NestJS CQRS pattern to handle interactions between User and UserProfile entities within my system. The setup consists of an API Gateway NestJS server along with dedicated NestJS servers for each microservice (User, UserProfile, etc. ...

What would be the optimal type for the second argument of the `simulate` method?

When using the simulate function, I am familiar with code like this: simulate("change", { target: { value: '7' } }); However, if my onChange function requires an object as a parameter, what should I pass in the second argument? interface myObj ...

Streamlined Authorization in MEAN (SPA) Applications

I have created an application, but now I am trying to adapt it into a SPA application. The main issue I am facing is with the Authorization process. While I can successfully register new users, log them in, and retrieve their tokens, I seem to encounter a ...

Exploring multilingual options with VeeValidate/i18n in version 4

Previously, I utilized VeeValidate v2 and had a setup like this: VeeValidate.Validator.localize('en', customErrors); const customErrors = { custom: { someField: { required: 'error.required', }, ... }} I have JSON files such ...

Issue with VueJS where the datalist input does not reset the value

I am currently working on a Vue component that scans QR codes and adds information to a database upon successful scanning. The scanning process works perfectly fine. However, after successfully sending the data, I need to clear the input field in my datali ...

Return either a wrapped or base type based on the condition

I am a beginner in TypeScript and I'm struggling to find the right combination of search terms to solve my issue. It seems like using a type condition could be helpful, but I still need to grasp how they function. My goal is to pass a function that p ...

The issue with Angular's Array.push method arises when only the last object in the array is being pushed after a mat-checkbox

I am currently working with two components called item-list and item. The item-list component is responsible for displaying a list of items with checkboxes. I have been facing an issue where the Array that stores the checked items only retains the last ite ...

The 'XXX' property is not found in 'YYY' type but is necessary in 'ZZZ' type

I'm struggling with setting up class properties in TypeScript. Here is the TypeScript code that I am working on: export class myClass { a: number; b: number; public getCopy(anotherClass: myClass): myClass { return { a: anotherClass.a, ...

Vue encountered an error: TypeError - _c is not recognized as a function

I recently created an icon library in Vue using Vue-cli and vue-svg-loader, and then exported it as a package. However, when I tried to use the icons like this: <template> <div> <MyIcon /> </div> </template> <scri ...

The axios library fails to send formdata to the server

Recently, I've been working on an axios code to handle form data submission. Here's the snippet of the code: updatesetting: function(){ let formData = new FormData(); formData.append('email', this.email); formData.append(&a ...

Generating an instance of an enum using a string in Typescript

Having trouble accessing the enum members of a numeric enum in TypeScript using window[name]. The result is an undefined object. export enum MyEnum { MemberOne = 0, MemberTwo = 1 } export class ObjectUtils { public static GetEnumMembers(name ...

Encountering challenges with Object-Oriented Programming combined with Typescript: Are you experiencing a

Currently, I'm in the process of building a comprehensive authentication application using the MERN stack entirely in TypeScript. However, I am encountering some issues (specifically type errors) with my userController file. Here is my routes file: i ...

Issue with Vue-gtag @legacy query not retrieving customer identification ID

Currently utilizing Vue2, I opted for vue-gtag@legacy as it's tailored for compatibility with version 2 of VueJS. Here is the setup in main.ts plugin: import VueGtagPlugin from "vue-gtag"; Vue.use(VueGtagPlugin, { config: { id: "G-MY ...

Having trouble retrieving data values from methods within my Vue.js component

I am having trouble accessing the lat and lng values from the data() method within the maps() method. Here is a link to my Vue.js component code: https://gist.github.com/melvin2016/c8082e27b9c50964dcc742ecff853080 Here is an image of the console showing ...

Prevent redirection when submitting and show an error message instead

I implemented a login system where, upon entering the correct username and password, a token is stored in local storage. If there's an error with the credentials, an "Login Unsuccessful" message is displayed. Everything was functioning correctly until ...