Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DataTable): allow removal of additional sortings #20990

Merged

Conversation

KYash03
Copy link
Contributor

@KYash03 KYash03 commented Feb 16, 2025

Fixes #20985

What I Did: The issue was with must-sort and multi-sort enabled, sorted columns couldn't be removed, only toggled ascending/descending. I modified toggleSort so in multi-sort mode, columns sorting descending are removed if multiple sorts are active, but toggle back to ascending if they're the only sorted column (satisfying must-sort).

How to Verify: Click a column header to sort ascending, then again for descending. Add another sorted column to test multi-sort - when you click the descending column, it should get removed since there's multiple sorts. Try with just one sorted column too - clicking it should just flip the sort direction instead of removing it.

<template>
  <v-app>
    <v-container>
      <v-data-table
        :headers="headers"
        :items="desserts"
        :must-sort="true"
        :multi-sort="true"
      />
    </v-container>
  </v-app>
</template>

<script>
export default {
  name: 'Playground',
  setup() {
    const headers = [
      {
        title: 'Dessert (100g serving)',
        key: 'name',
      },
      {
        title: 'Calories',
        key: 'calories',
      },
      {
        title: 'Fat (g)',
        key: 'fat',
      },
      {
        title: 'Carbs (g)',
        key: 'carbs',
      },
      {
        title: 'Protein (g)',
        key: 'protein',
      },
    ]

    const desserts = [
      {
        name: 'Frozen Yogurt',
        calories: 159,
        fat: 6.0,
        carbs: 24,
        protein: 4.0,
      },
      {
        name: 'Ice cream sandwich',
        calories: 237,
        fat: 9.0,
        carbs: 37,
        protein: 4.3,
      },
      {
        name: 'Eclair',
        calories: 262,
        fat: 16.0,
        carbs: 23,
        protein: 6.0,
      },
      {
        name: 'Cupcake',
        calories: 305,
        fat: 3.7,
        carbs: 67,
        protein: 4.3,
      },
      {
        name: 'Gingerbread',
        calories: 356,
        fat: 16.0,
        carbs: 49,
        protein: 3.9,
      },
    ]

    return {
      headers,
      desserts,
    }
  },
}
</script>

@KaelWD KaelWD merged commit 32e5747 into vuetifyjs:master Feb 17, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report][3.7.12] Data Tables with both must-sort and multi-sort do not work well together
2 participants