Skip to content

Conversation

4very
Copy link

@4very 4very commented Aug 21, 2025

Description

Add a slot item.prepend to add content before each item in a VDataTable. The use case is for alerts/notifications for rows. I refrained from adding a item.append since it would be weird with expanded rows, but if symmetry is requested then I will happily add it.

Some considerations:

  • Should it be item.data-table-prepend to prevent any conflicts with the item.${key} slots?

Markup:

<template>
  <v-data-table :headers="headers" :items="tools">
    <template #item.prepend="{item}">
      <v-alert text="Alert!" type="error" v-if="item.alert" />
    </template>
  </v-data-table>
</template>

<script setup>
const headers = [
  { title: 'Tool Name', align: 'start', sortable: false, key: 'name' },
  { title: 'Weight(kg)', key: 'weight', align: 'end' },
  { title: 'Length(cm)', key: 'length', align: 'end' },
  { title: 'Price($)', key: 'price', align: 'end' },
]

const tools = [
  { name: 'Hammer', weight: 0.5, length: 30, price: 10, type: 'hand', alert: true },
  { name: 'Screwdriver', weight: 0.2, length: 20, price: 5, type: 'hand' },
  { name: 'Drill', weight: 1.5, length: 25, price: 50, type: 'power' },
  { name: 'Saw', weight: 0.7, length: 50, price: 15, type: 'hand' },
  { name: 'Tape Measure', weight: 0.3, length: 10, price: 8, type: 'measuring' },
  { name: 'Level', weight: 0.4, length: 60, price: 12, type: 'measuring' },
  { name: 'Wrench', weight: 0.6, length: 25, price: 10, type: 'hand' },
  { name: 'Pliers', weight: 0.3, length: 15, price: 7, type: 'hand' },
  { name: 'Sander', weight: 2.0, length: 30, price: 60, type: 'power' },
  { name: 'Multimeter', weight: 0.5, length: 15, price: 30, type: 'measuring' },
]
</script>

@KaelWD KaelWD force-pushed the dev branch 2 times, most recently from 6331ca7 to 564ccc8 Compare September 10, 2025 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants