1

I am new to vuetify and I'm trying to take the value in a column of a v-data-table and convert it to it's text equivalent, but can't find out how to do it.

headers: [
    { text: 'Name', value: 'name' },
    { text: 'Type', value: 'typeName(type)' },
  ]

I have tried typeName as a computed value and as a method:

typeName(typId) {
  return ...
},

How do I get this to work?

Graham
  • 7,807
  • 20
  • 69
  • 114

1 Answers1

1

Yes, you can format the column value by adding a explict function

Here is the working codepen which reverse the value of first column: https://codepen.io/chansv/pen/GRRjaqj?editors=1010

If you have headers type, no need to call the function from here, instead we need to call from column by adding a template

headers: [
    { text: 'Name', value: 'name' },
    { text: 'Type', value: 'type' },
  ]

In the HTML , add a template with slot points to body

<v-data-table
      :headers="headers"
      :items="items"   >
<template v-slot:body="{items}">
      <tbody>
        <tr v-for="item in items" :key="item.name">
        <td>{{item.name}}</td>
        <td>{{typeName(item.type)}}</td>
        </tr>
        </tbody>
    </template>
</v-data-table>

Inside data property add a property typeName

data() {
  return {
    typeName: (type) => type.substring(2),
  }
}
chans
  • 5,104
  • 16
  • 43