Skip to content

Commit 4a2de37

Browse files
fix(VDataTable): add missing disable-sort prop (#19820)
resolves #19197
1 parent 9342288 commit 4a2de37

File tree

6 files changed

+13
-7
lines changed

6 files changed

+13
-7
lines changed

packages/api-generator/src/locale/en/VDataTableHeader.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"props": {
3-
"disableSort": "Toggles rendering of sort button.",
43
"everyItem": "Indicates if all items in table are selected.",
54
"headers": "Array of header items to display.",
65
"mobile": "Renders mobile view of headers.",

packages/api-generator/src/locale/en/VDataTableHeaders.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"props": {
3+
"disableSort": "Toggles rendering of sort button.",
34
"sortAscIcon": "Icon used for ascending sort button.",
45
"sortDescIcon": "Icon used for descending sort button.",
56
"sticky": "Sticks the header to the top of the table."

packages/api-generator/src/locale/en/VDataTableServer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"column.data-table-select": "Slot to replace the default `v-simple-checkbox` used when selecting rows.",
1313
"dataTableGroup": "Slot for custom rendering of a group.",
1414
"data-table-select": "Slot for custom rendering of a header cell with the select checkbox.",
15+
"disableSort": "Disables sorting completely.",
1516
"expanded-row": "Slot for custom rendering of an expanded row.",
1617
"footer.prepend": "Adds content to the empty space in the footer.",
1718
"group-header": "Slot for custom rendering of a group header.",

packages/api-generator/src/locale/en/VDataTableVirtual.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"column.data-table-select": "Slot to replace the default `v-simple-checkbox` used when selecting rows.",
1010
"data-table-group": "Slot for custom rendering of a group.",
1111
"data-table-select": "Slot for custom rendering of a header cell with the select checkbox.",
12+
"disableSort": "Disables sorting completely.",
1213
"expanded-row": "Slot for custom rendering of an expanded row.",
1314
"group-header": "Slot for custom rendering of a group header.",
1415
"headers": "Slot to replace the default rendering of the `<thead>` element.",

packages/vuetify/src/components/VDataTable/VDataTableHeaders.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export type VDataTableHeadersSlots = {
6060
export const makeVDataTableHeadersProps = propsFactory({
6161
color: String,
6262
sticky: Boolean,
63+
disableSort: Boolean,
6364
multiSort: Boolean,
6465
sortAscIcon: {
6566
type: IconValue,
@@ -142,7 +143,7 @@ export const VDataTableHeaders = genericComponent<VDataTableHeadersSlots>()({
142143
align={ column.align }
143144
class={[
144145
{
145-
'v-data-table__th--sortable': column.sortable,
146+
'v-data-table__th--sortable': column.sortable && !props.disableSort,
146147
'v-data-table__th--sorted': isSorted(column),
147148
'v-data-table__th--fixed': column.fixed,
148149
},
@@ -192,7 +193,7 @@ export const VDataTableHeaders = genericComponent<VDataTableHeadersSlots>()({
192193
return (
193194
<div class="v-data-table-header__content">
194195
<span>{ column.title }</span>
195-
{ column.sortable && (
196+
{ column.sortable && !props.disableSort && (
196197
<VIcon
197198
key="icon"
198199
class="v-data-table-header__sort-icon"
@@ -223,7 +224,7 @@ export const VDataTableHeaders = genericComponent<VDataTableHeadersSlots>()({
223224
const headerProps = mergeProps(props.headerProps ?? {} ?? {})
224225

225226
const displayItems = computed<ItemProps['items']>(() => {
226-
return columns.value.filter(column => column?.sortable)
227+
return columns.value.filter(column => column?.sortable && !props.disableSort)
227228
})
228229

229230
const appendIcon = computed(() => {

packages/vuetify/src/components/VDataTable/composables/sort.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ export function useSort () {
9595
}
9696

9797
// TODO: abstract into project composable
98-
export function useSortedItems <T extends InternalItem> (
99-
props: { customKeySort: Record<string, DataTableCompareFunction> | undefined },
98+
export function useSortedItems<T extends InternalItem> (
99+
props: {
100+
customKeySort: Record<string, DataTableCompareFunction> | undefined
101+
disableSort?: Boolean
102+
},
100103
items: Ref<T[]>,
101104
sortBy: Ref<readonly SortItem[]>,
102105
options?: {
@@ -107,7 +110,7 @@ export function useSortedItems <T extends InternalItem> (
107110
) {
108111
const locale = useLocale()
109112
const sortedItems = computed(() => {
110-
if (!sortBy.value.length) return items.value
113+
if (!sortBy.value.length || props.disableSort) return items.value
111114

112115
return sortItems(items.value, sortBy.value, locale.current.value, {
113116
transform: options?.transform,

0 commit comments

Comments
 (0)