diff --git a/packages/vuetify/src/components/VData/VData.ts b/packages/vuetify/src/components/VData/VData.ts index faa305fb2a6..7bb29b52f0d 100644 --- a/packages/vuetify/src/components/VData/VData.ts +++ b/packages/vuetify/src/components/VData/VData.ts @@ -158,7 +158,7 @@ export default Vue.extend({ computedItems (): any[] { let items = this.filteredItems.slice() - if (!this.disableSort && this.serverItemsLength <= 0) { + if ((!this.disableSort || this.internalOptions.groupBy.length) && this.serverItemsLength <= 0) { items = this.sortItems(items) } @@ -348,8 +348,13 @@ export default Vue.extend({ } }, sortItems (items: any[]): any[] { - let sortBy = this.internalOptions.sortBy - let sortDesc = this.internalOptions.sortDesc + let sortBy: string[] = [] + let sortDesc: boolean[] = [] + + if (!this.disableSort) { + sortBy = this.internalOptions.sortBy + sortDesc = this.internalOptions.sortDesc + } if (this.internalOptions.groupBy.length) { sortBy = [...this.internalOptions.groupBy, ...sortBy] diff --git a/packages/vuetify/src/components/VData/__tests__/VData.spec.ts b/packages/vuetify/src/components/VData/__tests__/VData.spec.ts index f52a8c97a81..743953a1fb9 100644 --- a/packages/vuetify/src/components/VData/__tests__/VData.spec.ts +++ b/packages/vuetify/src/components/VData/__tests__/VData.spec.ts @@ -562,4 +562,38 @@ describe('VData.ts', () => { expect(wrapper.html()).toMatchSnapshot() }) + + // https://github.com/vuetifyjs/vuetify/issues/11905 + it('should group items when sort is disabled', async () => { + const render = jest.fn() + const items = [ + { id: 1, text: 'foo', baz: 'one' }, + { id: 2, text: 'bar', baz: 'two' }, + { id: 3, text: 'baz', baz: 'one' }, + ] + + const wrapper = mountFunction({ + propsData: { + items, + groupBy: ['baz'], + disableSort: true, + }, + scopedSlots: { + default: render, + }, + }) + + expect(render).toHaveBeenCalledWith(expect.objectContaining({ + groupedItems: [ + { + name: 'one', + items: [items[0], items[2]], + }, + { + name: 'two', + items: [items[1]], + }, + ], + })) + }) })