Skip to content
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

Add support for backend pagination to Table #221

Merged
merged 2 commits into from
Aug 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/components/table/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<div class="level-right">
<div v-if="paginated" class="level-item">
<b-pagination
:total="newData.length"
:total="newDataTotal"
:per-page="perPage"
:simple="paginationSimple"
:current="currentPage"
Expand Down Expand Up @@ -172,13 +172,19 @@
rowClass: {
type: Function,
default: () => ''
},
backendPagination: Boolean,
total: {
type: [Number, String],
default: 0
}
},
data() {
return {
columns: [],
visibleDetailRows: [],
newData: this.data,
newDataTotal: this.backendPagination ? this.total : this.data.length,
newCheckedRows: [...this.checkedRows],
currentSortColumn: {},
isAsc: true,
Expand All @@ -192,12 +198,26 @@
/**
* When data prop change, update internal value and sort again,
* do not sort however if it's backend-sort.
* If it isn't backend-paginated set new total
*/
data(value) {
this.newData = value
if (!this.backendSorting) {
this.sort(this.currentSortColumn, true)
}
if (!this.backendPagination) {
this.newDataTotal = value.length
}
},

/**
* When Pagination total change, update internal total
* only if it's backend-paginated.
*/
total(newTotal) {
if (this.backendPagination) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to

if (!this.backendPagination) return

this.newDataTotal = newTotal

It's a good practice to return the function as soon as possible.

this.newDataTotal = newTotal
}
},

/**
Expand Down