-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
[Bug Report][3.4.6] VDataTable - Using #thead and #tbody slots does not remove VDataTable thead or tbody #18854
[Bug Report][3.4.6] VDataTable - Using #thead and #tbody slots does not remove VDataTable thead or tbody #18854
Comments
The thead and tbody slots are documented in the slots section of the page you linked: thead: https://vuetifyjs.com/en/api/v-data-table/#slots-thead tbody: https://vuetifyjs.com/en/api/v-data-table/#slots-tbody Also using the headers slot does not allow me to replace the |
I was just about to post this issue. Seems like the issue is here: // vuetify/packages/vuetify/src/components/VDataTable/VDataTable.tsx
default: () => slots.default ? slots.default(slotProps.value) : (
<>
{ slots.colgroup?.(slotProps.value) }
<thead>
<VDataTableHeaders
{ ...dataTableHeadersProps }
v-slots={ slots }
/>
</thead>
{ slots.thead?.(slotProps.value) }
<tbody>
{ slots['body.prepend']?.(slotProps.value) }
{ slots.body ? slots.body(slotProps.value) : (
<VDataTableRows
{ ...attrs }
{ ...dataTableRowsProps }
items={ paginatedItems.value }
v-slots={ slots }
/>
)}
{ slots['body.append']?.(slotProps.value) }
</tbody>
{ slots.tbody?.(slotProps.value) }
{ slots.tfoot?.(slotProps.value) }
</>
), The body slot isn't rendered until we're already inside the element, so it doesn't replace it. |
@codetakki I had the same issue, tight now the only workaround I was able to achieve is something like this <template
v-if="allowItemsDragAndDrop"
#body
>
<!-- workaround for the following issue https://github.com/vuetifyjs/vuetify/issues/18854 -->
</template>
<template
v-if="allowItemsDragAndDrop"
#tbody="bodySlotProps"
>
<!-- my tbody here-->
</template> |
The Personally I wouldn't call this a bug, but more like the documentation needs info for the |
Except that the |
Valid point that the To fix |
This is not a helpful response. There's very obviously a very common use case and one that's been highlighted by multiple people in this thread. You need access to the tbody element to use any sorting libraries, like say, VueUse's useSortable composable. Having the need to sort items in a data table is extremely common. |
Agreed with @craigrileyuk, as i mentioned, the only way to use libraries that really on controlling their own list items by iteration is to replace the tbody tag. And its definitely not logical how the tbody and body slots are used currently, check out #19413 To why. |
Why would someone use a sorting library like VueUse useSortable, when that is a built in functionality of the VDataTable along with it's headers? There are plenty of ways to sort a VDataTable with or without a sorting library. That is not a common use case, as that defeats the purpose of the VDataTable component. What that's doing is basically trying to turn the VDataTable into a VTable, so you can then turn it back into a VDataTable, aka redundant and completely unneeded. If you would like to change my mind, show me a working example in the Vuetify Playground on how it's "not possible" to do what you are trying to do. Or post it in the Vuetify Discord or StackOverflow and other can help you. Other cases people are posing also make it sound like people should be using either the default slot, or the If you don't know how to do something, then perhaps ask StackOverflow, or join the Vuetify Discord channel where people can also get help from people who know how to use Vuetify extensively. |
In these cases "sortable" refers to being able to drag items in the list around, enabling resorting of the list. If you ask stack overflow you will get the answer to use the #body slot for this, witch works for vuetify 2 https://stackoverflow.com/questions/66090612/can-vue-draggable-be-used-with-vuetify-v-data-table-and-allow-utilisation-of-tab#comment135280475_66090613 |
To me, logically, tbody/thead etc etc should replace the content that the slot is depicted by. However, as stated #17206 (comment) They were initially intended as additions to the slot, to not have to reinvent default functionality (as thats what slots tend to do, which has its use itself). Personally I think that logically the naming should be Current structure is like this
With that being said, for v3, may just need a better documentation to outline it, and we can add a This would make it so doing <v-data-table hide-default-body>
<template #tbody />
</v-data-table> which would render just your one custom |
You didn't mention draggable when you mentioned sorting in that comment. I missed that you posted about draggable and thought it was someone else, so I didn't think you were talking about the same thing. It makes more sense now that you made that clear. As I mentioned before, and as MajesticPotatoe also mentioned, while it is a valid point, it's still a breaking change to completely change how it works. This is why I don't consider it a "bug" but more of a "feature request" as it currently works as intended. A |
As of v3.6.5 <v-data-table hide-default-header>
<template #thead>
<thead />
</template>
</v-data-table> I will be putting in a fix in for the next patch to have the same functionality using <v-data-table hide-default-body>
<template #tbody>
<tbody />
</template>
</v-data-table> This will suffice till v4 when we can revisit slot names + structure and introduce a breaking change. |
Environment
Vuetify Version: 3.4.6
Vue Version: 3.3.9
Browsers: Firefox 120.0
OS: Mac OS 10.15
Steps to reproduce
Add a #thead slot with the VDataTable component. Notice the thead element for the headers remains.
Add a #tbody slot to VDataTable and notice the tbody with the data remains.
Expected Behavior
When using the #thead or #tbody slot I'd expect this to completely replace the
<thead>
and<tbody>
of the VDataTable for when I want to implement my own<thead>
and<tbody>
elementsActual Behavior
When adding a #thead or #tbody slot the content within that slot is added as a sibling to the VDataTable
<thead>
and<tbody>
element.Reproduction Link
https://play.vuetifyjs.com/#...
The text was updated successfully, but these errors were encountered: