Skip to content

Commit

Permalink
fix(VDataTable): page resets when server-items-length is zero (#8594)
Browse files Browse the repository at this point in the history
we should not limit page to the current max page when using server-items-length
since all items are not loaded.

closes #8359
  • Loading branch information
nekosaur authored and johnleider committed Aug 22, 2019
1 parent cb045a2 commit 39f9d8b
Show file tree
Hide file tree
Showing 3 changed files with 810 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vuetify/src/components/VData/VData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ export default Vue.extend({
this.internalOptions = {
...this.internalOptions,
...options,
page: Math.max(1, Math.min(options.page || this.internalOptions.page, this.pageCount)),
page: this.serverItemsLength < 0
? Math.max(1, Math.min(options.page || this.internalOptions.page, this.pageCount))
: options.page || this.internalOptions.page,
}
},
sortItems (items: any[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,42 @@ describe('VDataTable.ts', () => {
expect(wrapper.html()).toMatchSnapshot()
})

// https://github.com/vuetifyjs/vuetify/issues/8359
it('should not limit page to current item count when using server-items-length', async () => {
const wrapper = mountFunction({
propsData: {
headers: testHeaders,
items: [],
page: 2,
itemsPerPage: 5,
serverItemsLength: 0,
},
})

expect(wrapper.html()).toMatchSnapshot()

wrapper.setProps({
items: testItems.slice(5),
serverItemsLength: 20,
})
await wrapper.vm.$nextTick()

expect(wrapper.html()).toMatchSnapshot()
})

// https://github.com/vuetifyjs/vuetify/issues/8359
it('should limit page to current page count if not using server-items-length', async () => {
const wrapper = mountFunction({
propsData: {
headers: testHeaders,
items: testItems,
page: 3,
itemsPerPage: 5,
},
})

expect(wrapper.html()).toMatchSnapshot()
})
// https://github.com/vuetifyjs/vuetify/issues/8184
it('should default to first option in itemsPerPageOptions if it does not include itemsPerPage', async () => {
const itemsPerPage = jest.fn()
Expand Down
Loading

0 comments on commit 39f9d8b

Please sign in to comment.