Skip to content

v-data-table sort strings #21019

Answered by bcExpt1123
mrefik asked this question in Q&A
Feb 24, 2025 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

To sort the values as strings instead of numbers in Vuetify, you can use the customSort function in your data table configuration. Here is an example of how you can implement it:

  1. Define your headers with the customSort function for the specific column:
const headers = [
  {
    title: 'Values',
    key: 'value',
    customSort: (a, b) => a.localeCompare(b),
  },
  // other headers...
];
  1. Use these headers in your v-data-table component:
<template>
  <v-data-table
    :headers="headers"
    :items="items"
    :sort-by="[{ key: 'value', order: 'asc' }]"
  ></v-data-table>
</template>

<script>
export default {
  data() {
    return {
      headers: [
        {
          title: 'Values',

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mrefik
Comment options

Answer selected by mrefik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants