By default, the groups initiated by the group-by
property are sorted alphabetically, but I just want it to keep the original order or set it manually. How to configure v-data-table
groups order ?
<v-data-table
:headers="headers"
:items="questions"
:item-class="rowClass"
:group-by="'group'"
disable-pagination
hide-default-footer
>
Per the docs it doesn't seem to support sorting the categories per your needs. However @DevonDahon is on the right track and helped me sort my grouped content as I needed it.
But if you are here, also read where one of the answers shows you how to style the category.
Just to run you through how I managed to make it work:
notificationTypes
notificationCategoryOrder: [
"All Notifications",
"Request",
"Order",
"Inventory",
"Spend Code",
];
this.notificationTypes = resp.data.data.map((notification) => ({
...notification,
position: this.notificationCategoryOrder.indexOf(notification.category),
}));
Then use it in the v-data-table
like :
<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>
Came out pretty clean!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With