vue.js - 如何设置 v-data-table 组顺序?
问题描述
默认情况下,该group-by
属性启动的组按字母顺序排序,但我只是希望它保持原始顺序或手动设置。如何配置v-data-table
组顺序?
<v-data-table
:headers="headers"
:items="questions"
:item-class="rowClass"
:group-by="'group'"
disable-pagination
hide-default-footer
>
解决方案
根据文档,它似乎不支持根据您的需要对类别进行排序。然而,@DevonDahon 走在正确的轨道上,并帮助我根据需要对分组内容进行排序。
但是,如果您在这里,还请阅读其中一个答案向您展示了如何设置该类别的样式。
只是为了让你了解我是如何使它工作的:
- 获取数据(这里我存储在一个名为
notificationTypes
notificationCategoryOrder: [
"All Notifications",
"Request",
"Order",
"Inventory",
"Spend Code",
];
this.notificationTypes = resp.data.data.map((notification) => ({
...notification,
position: this.notificationCategoryOrder.indexOf(notification.category),
}));
然后v-data-table
像这样使用它:
<v-data-table
:headers="headers"
hide-default-footer
:items="notificationTypes"
disable-pagination
dense
group-by="position"
>
<template #group.header="{ group, headers, toggle, isOpen }">
<td :colspan="headers.length">
<v-btn @click="toggle" x-small icon :ref="group">
<v-icon v-if="isOpen">mdi-plus</v-icon>
<v-icon v-else>mdi-minus</v-icon>
</v-btn>
<span class="mx-5 font-weight-bold">{{
notificationCategoryOrder[group]
}}</span>
</td>
</template>
</v-data-table>
出来很干净!
推荐阅读
- service-worker - 何时以及如何在 service worker 中触发同步事件?
- android - canvas.drawPath() 不是实时绘图
- javascript - ES6 对窗口调整大小和窗口就绪的执行方法
- google-bigquery - 与 BigQuery 表输入大小相比,为什么我的 PCollection (SCollection) 大小如此之大?
- java - Spark scala为列添加权重和运行计算
- r - 如何在观星者输出中省略开始表
- actions-on-google - 在收到成功的操作响应后,Google 助理现在会间歇性地永远挂起
- python - pygame不画线
- sql - 是否有任何 Eloquent 方法来获取关系表的总和并按其排序?
- java - 从 Java 中的 BufferedReader 中过滤文本