Skip to content

Commit

Permalink
fix(VData): allow group-by to be used with disable-sort (#13027)
Browse files Browse the repository at this point in the history
Co-authored-by: Sören Lerch <soeren.lerch@baecker-mueller.de>
Co-authored-by: John Leider <john.j.leider@gmail.com>
  • Loading branch information
3 people authored May 24, 2021
1 parent 2508e2f commit 560b52c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/vuetify/src/components/VData/VData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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]
Expand Down
34 changes: 34 additions & 0 deletions packages/vuetify/src/components/VData/__tests__/VData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
},
],
}))
})
})

0 comments on commit 560b52c

Please sign in to comment.