Add basic pagination support for model index, and view w/ rows
This commit is contained in:
parent
c87fd1ab35
commit
e83d98905a
|
@ -58,7 +58,7 @@
|
||||||
<div v-if="hasRows && mode == 'viewing'">
|
<div v-if="hasRows && mode == 'viewing'">
|
||||||
<b-menu>
|
<b-menu>
|
||||||
<b-menu-list>
|
<b-menu-list>
|
||||||
<b-menu-item v-for="row in rows"
|
<b-menu-item v-for="row in rowData.data"
|
||||||
:key="row.uuid"
|
:key="row.uuid"
|
||||||
tag="router-link"
|
tag="router-link"
|
||||||
:to="getRowPathPrefix() + '/' + row.uuid">
|
:to="getRowPathPrefix() + '/' + row.uuid">
|
||||||
|
@ -68,6 +68,14 @@
|
||||||
</b-menu-item>
|
</b-menu-item>
|
||||||
</b-menu-list>
|
</b-menu-list>
|
||||||
</b-menu>
|
</b-menu>
|
||||||
|
<b-pagination v-if="rowsPaginated"
|
||||||
|
:total="rowData.total"
|
||||||
|
:current.sync="rowPage"
|
||||||
|
:per-page="rowsPerPage"
|
||||||
|
@change="changeRowPagination"
|
||||||
|
>
|
||||||
|
<!-- icon-pack="fas" -->
|
||||||
|
</b-pagination>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<slot name="footer"></slot>
|
<slot name="footer"></slot>
|
||||||
|
@ -97,6 +105,14 @@ export default {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
rowsPaginated: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
rowsPerPage: {
|
||||||
|
type: Number,
|
||||||
|
default: 20,
|
||||||
|
},
|
||||||
apiRowsUrl: String,
|
apiRowsUrl: String,
|
||||||
isRow: {
|
isRow: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
@ -121,7 +137,8 @@ export default {
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
record: {},
|
record: {},
|
||||||
rows: [],
|
rowData: {},
|
||||||
|
rowPage: 1,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -328,8 +345,12 @@ export default {
|
||||||
orderBy: 'modified',
|
orderBy: 'modified',
|
||||||
ascending: 0,
|
ascending: 0,
|
||||||
}
|
}
|
||||||
|
if (this.rowsPaginated) {
|
||||||
|
params.per_page = this.rowsPerPage
|
||||||
|
params.page = this.rowPage
|
||||||
|
}
|
||||||
this.$http.get(this.getApiRowsUrl(), {params: params}).then(response => {
|
this.$http.get(this.getApiRowsUrl(), {params: params}).then(response => {
|
||||||
this.rows = response.data.data
|
this.rowData = response.data
|
||||||
|
|
||||||
}, response => {
|
}, response => {
|
||||||
if (response.status == 403) { // forbidden; redirect to home page
|
if (response.status == 403) { // forbidden; redirect to home page
|
||||||
|
@ -349,6 +370,10 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
changeRowPagination(value) {
|
||||||
|
this.fetchRows(this.record.uuid)
|
||||||
|
},
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
let url = this.getApiIndexUrl()
|
let url = this.getApiIndexUrl()
|
||||||
if (this.mode != 'creating') {
|
if (this.mode != 'creating') {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
<b-menu>
|
<b-menu>
|
||||||
<b-menu-list>
|
<b-menu-list>
|
||||||
<b-menu-item v-for="obj in records"
|
<b-menu-item v-for="obj in data.data"
|
||||||
:key="obj.uuid"
|
:key="obj.uuid"
|
||||||
:label="renderLabel(obj)"
|
:label="renderLabel(obj)"
|
||||||
:tag="hasModelPerm('view') ? 'router-link' : 'a'"
|
:tag="hasModelPerm('view') ? 'router-link' : 'a'"
|
||||||
|
@ -27,6 +27,16 @@
|
||||||
</b-menu-item>
|
</b-menu-item>
|
||||||
</b-menu-list>
|
</b-menu-list>
|
||||||
</b-menu>
|
</b-menu>
|
||||||
|
|
||||||
|
<b-pagination v-if="paginated"
|
||||||
|
:total="data.total"
|
||||||
|
:current.sync="page"
|
||||||
|
:per-page="perPage"
|
||||||
|
@change="changePagination"
|
||||||
|
>
|
||||||
|
<!-- icon-pack="fas" -->
|
||||||
|
</b-pagination>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -49,10 +59,19 @@ export default {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
paginated: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
perPage: {
|
||||||
|
type: Number,
|
||||||
|
default: 20,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
records: [],
|
data: {},
|
||||||
|
page: 1,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -65,14 +84,22 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
|
changePagination(value) {
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
|
||||||
fetchData() {
|
fetchData() {
|
||||||
let params = {
|
let params = {
|
||||||
filters: JSON.stringify(this.apiIndexFilters),
|
filters: JSON.stringify(this.apiIndexFilters),
|
||||||
orderBy: this.apiIndexSort.field,
|
orderBy: this.apiIndexSort.field,
|
||||||
ascending: (this.apiIndexSort.dir == 'asc') ? 1 : 0,
|
ascending: (this.apiIndexSort.dir == 'asc') ? 1 : 0,
|
||||||
}
|
}
|
||||||
|
if (this.paginated) {
|
||||||
|
params.per_page = this.perPage
|
||||||
|
params.page = this.page
|
||||||
|
}
|
||||||
this.$http.get(this.getApiIndexUrl(), {params: params}).then(response => {
|
this.$http.get(this.getApiIndexUrl(), {params: params}).then(response => {
|
||||||
this.records = response.data.data
|
this.data = response.data
|
||||||
|
|
||||||
}, response => {
|
}, response => {
|
||||||
if (response.status == 403) { // forbidden; redirect to home page
|
if (response.status == 403) { // forbidden; redirect to home page
|
||||||
|
|
Loading…
Reference in a new issue