0👍
you can do it by changing it from the slot directly like this :
<template>
<v-data-table :items="items">
<template v-slot:item="props">
<tr :id="'row-' + props.item.id"> <!-- Use a dynamic id -->
<td>
<!-- Your custom cell content -->
<slot name="item.columnName" :item="props.item"></slot>
</td>
<!-- ... other columns ... -->
</tr>
</template>
</v-data-table>
</template>
OR … you can keep the same structure and update it on mounted like this :
<template>
<v-data-table :items="items">
<!-- ... slots for headers and custom cells ... -->
</v-data-table>
</template>
<script>
export default {
data() {
return {
items: [
{ id: 1, /* other properties */ },
{ id: 2, /* other properties */ },
// ... other items ...
]
};
},
mounted() {
this.items.forEach(item => {
const rowElement = this.$el.querySelector(`tr[data-item-key="${item[this.itemKey]}"]`);
if (rowElement) {
rowElement.setAttribute('id', `row-${item.id}`);
}
});
}
};
</script>
- [Vuejs]-Vite: Rollup failed to resolve import from external directory
- [Vuejs]-VueJS v3: automatically add css class to any component
0👍
After some time of checking. It is understood that you are trying to make an ID of each record. But, the problem is, there’s no uniques
on each record(so it’s difficult to pin point the id of each). If so, we need to create an index of each. Therefore we need to make a function that creates index each of the records. By doing so, I make this sample function to make an ID
each of the record.
<template v-slot:item.bar="{ item }">
{{
props2.items
.map(function (x) {
return x.bar;
})
.indexOf(item.bar) + 1
}}
</template>
- [Vuejs]-How to show date in 13-digit Unix Timestamp format in JSpreadSheet?
- [Vuejs]-Vue.js- How is the value of v-model and this.pageNumber are changing according to the pagination?
Source:stackexchange.com