我有一个包含可展开行的 Vuetify 数据表格。每一行对应一个客户的订单,其中包括他们想要进行测试的样品。
目前,我正在检索所有订单及其所有样品,但加载所有信息需要太长时间。
因此,当我展开一行时,我希望能够执行 API 调用,只检索应显示在该特定订单的扩展部分中的样品。
我已经尽力研究了,并且陷入了死胡同。以下是我当前所处的阶段:
<v-data-table
:headers="orders_headers"
:items="orders"
show-expand
:single-expand="true"
:expanded.sync="expanded"
>
<!-- Expand Buttons -->
<template v-slot:item.data-table-expand="{ item, isExpanded, expand }">
<v-btn @click="expand(true)" v-if="!isExpanded">Expand</v-btn>
<v-btn @click="expand(false)" v-if="isExpanded">close</v-btn>
</template>
<!-- Expanded Data -->
<template v-slot:expanded-item="{ headers, item }">
<td :colspan="headers.length">
<table v-for="(sample, index) in item.samples" :key="index">
<tr>
<th>Sample Acc</th>
<td>{{ sample.sample_accession }}</td>
</tr>
<tr>
<th>Sample Status</th>
<td>{{ sample.sample_status }}</td>
</tr>
</table>
</td>
</template>
</v-data-table>
我写作时可能已经找到解决方法
当我在打字的时候,我意识到我可能需要做的是添加一个方法调用到展开按钮中,在该方法中将结果设置为expandedSamples
并用其替换item.samples
。
与此同时,如果有更好的解决方案,我很愿意听取。否则,我会发布我的解决方案,以防其他人尝试类似的事情。
额外奖励
有没有人知道是否有一种方法可以在不替换默认图标/功能的情况下利用展开事件,或者在使用v-slot:item.data-table-expand
时包含原始图标/功能?
目前,当我使用v-slot:item.data-table-expand
时,我必须重新添加按钮,并且失去了尖角和动画效果。