I have two question while using v-data-table in Vuetify 3.3.x. I have googled but all answers are for Vuetify 2.x, not suitable for Vuetify 3.3.x.
Here are my questions:
When click
Next PageorPrevious Page, if there is any expanded row in data table, close all of them.When click a row, call function
getRandomAnswer(null)and print it to the expanded row.When I click a row, how come all slots are expanded ? My code is very similar to the sample of official page (https://vuetifyjs.com/en/components/data-tables/basics/
For question 1 and 2, initially, I was trying to find relevant events in
<template v-slot:expanded-row="{ columns, item, isExpanded, toggleExpand }">
so that it would be very easy to make it. Unfortunatelly there is no such event in the slot. So, what can I do ?
In Vuetify 3, DataTable has an
:item-valueprop, which should identify a property on the item objects giving a unique value for each item (in your caseitem-value="city"would make sense). The default value isid.Vuetify tracks which rows are expanded through an array containing the item values of all expanded rows (i.e.
['TOKYO',TAIPEI]would correspond to the first two rows being expanded in your example).Since you are not setting an
item-valueand your items do not have anidproperty, the item value for every item isundefined. When you expand a row,undefinedis pushed to the array, which matches every item, so all rows are expanded. This is what the documentation means with:and on the selection page:
Use
v-model:expanded="..."to two-way bind to the array with the expanded items, or use the:expandedprop and@update:expandedevent individually.After you have set the
:item-valueand put an array intov-model:expandedyou can:item-value)getRandomAnswer()finishedDoes that answer your question?