Skip to content

feat(VDataTable): always allow expand groupby#18536

Closed
Esgator wants to merge 2 commits intovuetifyjs:devfrom
Esgator:feat/noid-force-expand-groupby
Closed

feat(VDataTable): always allow expand groupby#18536
Esgator wants to merge 2 commits intovuetifyjs:devfrom
Esgator:feat/noid-force-expand-groupby

Conversation

@Esgator
Copy link
Copy Markdown
Contributor

@Esgator Esgator commented Oct 24, 2023

added groupExpanded prop to allow to always render group rows expanded

Description

I added a prop to all VDataTables to pass along with groupBy to make the groups always expand when set.

Markup:

<template>
  <v-app>
    <v-container>
      <v-data-table
        :group-by="groupBy"
        :group-Expanded="groupExpanded"
        :headers="headers"
        :items="desserts"
        :sort-by="sortBy"
        class="elevation-1"
        item-value="name"
      ></v-data-table>
    </v-container>
  </v-app>
</template>

<script>
  export default {
    name: 'Playground',
    data: () => ({
      sortBy: [{ key: 'name', order: 'asc' }],
      groupBy: [{ key: 'dairy', order: 'asc' }],
      groupExpanded: true,
      headers: [
        {
          title: 'Dessert (100g serving)',
          align: 'start',
          key: 'name',
          groupable: false,
        },
        { title: 'Category', key: 'category', align: 'end' },
        { title: 'Dairy', key: 'dairy', align: 'end' },
      ],
      desserts: [
        {
          name: 'Frozen Yogurt',
          category: 'Ice cream',
          dairy: 'Yes',
        },
        {
          name: 'Ice cream sandwich',
          category: 'Ice cream',
          dairy: 'Yes',
        },
        {
          name: 'Eclair',
          category: 'Cookie',
          dairy: 'Yes',
        },
        {
          name: 'Cupcake',
          category: 'Pastry',
          dairy: 'Yes',
        },
        {
          name: 'Gingerbread',
          category: 'Cookie',
          dairy: 'No',
        },
        {
          name: 'Jelly bean',
          category: 'Candy',
          dairy: 'No',
        },
        {
          name: 'Lollipop',
          category: 'Candy',
          dairy: 'No',
        },
        {
          name: 'Honeycomb',
          category: 'Toffee',
          dairy: 'No',
        },
        {
          name: 'Donut',
          category: 'Pastry',
          dairy: 'Yes',
        },
        {
          name: 'KitKat',
          category: 'Candy',
          dairy: 'Yes',
        },
      ],
    }),
  }
</script>

Soeren Lerch and others added 2 commits October 24, 2023 16:09
added groupExpanded prop to allow to always render group rows expanded
@MajesticPotatoe MajesticPotatoe added T: bug Functionality that does not work as intended/expected C: VDataTable labs Must be completed for this component to leave labs labels Oct 25, 2023
@nekosaur
Copy link
Copy Markdown
Member

Thank you for the PR and your interest in improving Vuetify. Unfortunately this is not how we plan to introduce this functionality.

@Esgator
Copy link
Copy Markdown
Contributor Author

Esgator commented Nov 9, 2023

Thank you for the PR and your interest in improving Vuetify. Unfortunately this is not how we plan to introduce this functionality.

Thanks for your response. Is it short term planned or can you share some informations how it should be done so i might help?

@SystemKeeper
Copy link
Copy Markdown

@nekosaur Are there any information available on how this should be implemented? I would be interested in having this as well and would be open to contribute.

@Employee87
Copy link
Copy Markdown

Me too, but also, I would like to control which specific groups are expanded by default too, and to control them via a boolean.

@SystemKeeper
Copy link
Copy Markdown

@nekosaur @johnleider Any chance to get some information on this so we could contribute the feature? (Or help in another way?)

@johnleider
Copy link
Copy Markdown
Member

Right now we need a champion for the Data Table component. Albert is currently inactive.

@SystemKeeper

This comment was marked as outdated.

@johnleider johnleider added S: stale This issue is untriaged and hasn't seen any activity in at least six months. and removed labs Must be completed for this component to leave labs labels Jul 2, 2024
@ezBuilder
Copy link
Copy Markdown

ezBuilder commented Jul 28, 2024

<template v-slot:group-header="{ item, columns, toggleGroup, isGroupOpen }" > <template :ref=" () => { if (item.depth === 0 && !isGroupOpen(item)) { toggleGroup(item); } } " /> <tr> <td :colspan="columns.length"> <VBtn :icon="isGroupOpen(item) ? '$expand' : '$next'" size="small" variant="text" ref="expandBtn" @click="toggleGroup(item)" ></VBtn> {{ item.value }} </td> </tr> </template> </<template>

@sonicd300
Copy link
Copy Markdown

sonicd300 commented Aug 1, 2024

With this approach the toggle button will work and the groups will be expanded by default, once expanded the template will be removed allowing the expand/collapse button to work properly

<script setup>
import { ref } from 'vue';

const expandedGroups = ref<Set<string>>(new Set())
</script>

<template>
  <v-data-table ...>
    <template v-if="props.groupBy"
                     #group-header="{ item, columns, toggleGroup, isGroupOpen }">
      <tr>
        <td :colspan="columns.length">
          <template v-if="!expandedGroups.has(`${item.key}_${item.value}`)"> <!-- self removable template -->
            <template :ref="(el) => { if (!isGroupOpen(item)) { expandedGroups.add(`${item.key}_${item.value}`); toggleGroup(item); } }"></template>
          </template>

          <v-btn ref="expandBtn"
                      :icon="isGroupOpen(item) ? '$expand' : '$next'"
                      size="small"
                      variant="text"
                      @click="toggleGroup(item)" />
        </td>
      </tr>
  </v-data-table>
</template>

@adamskeeled

This comment was marked as outdated.

@KaelWD KaelWD force-pushed the dev branch 2 times, most recently from 6331ca7 to 564ccc8 Compare September 10, 2025 13:29
@J-Sek J-Sek force-pushed the dev branch 3 times, most recently from a7fa817 to 2e2cddb Compare October 8, 2025 15:22
@J-Sek J-Sek force-pushed the dev branch 2 times, most recently from 5b257fd to 86800d9 Compare March 29, 2026 00:37
@J-Sek
Copy link
Copy Markdown
Contributor

J-Sek commented Apr 15, 2026

closing in favor of #22772

@J-Sek J-Sek closed this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: VDataTable S: stale This issue is untriaged and hasn't seen any activity in at least six months. T: bug Functionality that does not work as intended/expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] VDataTable: Ability to have grouped rows closed and/or open by default

10 participants