Vuetify Data Table Expand Row on Column Click

Tags: , , , ,

I have a vuetify data table that includes expandable rows. The only real difference I have from the demo is that I would like the column to open/close the expandable row just like the chevron icon. When I put an @click handler on the v-slot for that column I get the error Error in v-on handler: "TypeError: expand is not a function". This is the only column I need to customize so I would like to not have to build out the entire <tr> v-slot by hand. A scaled-down code example is below. Thanks.


  <template"{ item, expand, isExpanded }" >
    <h4 class="my-2" @click="expand(!isExpanded)">{{ }} located in {{ item.depot | camelToWords }}</h4>

  <template v-slot:expanded-item="{ headers, item }">
    <ProductDetailExpandedRow :currentProduct="item" :headers="headers"/>


export default {
  data() {
    return {
      headers: [
          text: 'Name',
          value: 'name',
          text: 'Product ID',
          value: 'productCode',
          text: 'Stock',
          value: 'stock',
6 more columns continue on here...
      products: [],


Column click

Here is how you could do it with a specific column click. Put a @click handler in the column’s slot template. This handler receives the column data on click. In this case, the column’s name is name:

   <div @click="columnClick(slotData)">{{ }}</div>

Expanded rows are tracked in the expanded array, so add this row’s data. But if it’s already there, remove it (because then you’re trying to collapse an already expanded column)

columnClick(slotData) {
  const indexRow = slotData.index;
  const indexExpanded = this.expanded.findIndex(i => i === slotData.item);
  if (indexExpanded > -1) {
    this.expanded.splice(indexExpanded, 1)
  } else {

Here is the codepen (Rows expand when clicking the first column, within the padding)

Row click

Here is how you could do it with a row click (i.e. any column). In the template, add a listener to the <v-data-table> for the click:row event:

<v-data-table @click:row="clickRow">

This event passes two arguments: the item, and the item slot data, including the index of the clicked row. Use this information to modify the this.expanded array which tracks all expanded rows:

clickRow(item, event) {
  if(event.isExpanded) {
    const index = this.expanded.findIndex(i => i === item);
    this.expanded.splice(index, 1)
  } else {

This adds the item to the expanded array or it removes it by finding the index and using splice.

Here is the codepen (Rows expand when clicking anywhere in the row)

Source: stackoverflow