diff --git a/src/components/my-table.vue b/src/components/my-table.vue index 4ca4555..7d385b0 100644 --- a/src/components/my-table.vue +++ b/src/components/my-table.vue @@ -4,7 +4,10 @@ - + @@ -40,6 +43,15 @@ export default { data() { return { } + }, + methods: { + orderBy(col) { + console.log(col); + this.$emit('sort', { + orderBy: col, + orderDesc: false + }); + } } } diff --git a/src/components/scroll-table.vue b/src/components/scroll-table.vue index b70a4a5..1fafe67 100644 --- a/src/components/scroll-table.vue +++ b/src/components/scroll-table.vue @@ -1,9 +1,9 @@ @@ -42,6 +42,13 @@ export default { type: Number, default: 10 }, + orderBy: { + type: String + }, + orderDesc: { + type: Boolean, + default: false + }, loading: { type: Boolean, default: false @@ -79,14 +86,18 @@ export default { rows: [ ], rowsToPush: [ ], currentOffset: this.offset, - loadingDelayed: false + currentOrderBy: this.orderBy, + currentOrderDesc: this.orderDesc, + loadingDelayed: false, + sortTriggered: false } }, methods: { visibilityChanged(isVisible, entry) { if (isVisible) { // infinite scrolling - this.handler(this.currentOffset, this.limit); + this.sortTriggered = false; + this.handler(this.currentOffset, this.limit, this.currentOrderBy, this.currentOrderDesc); } }, pushRows() { @@ -97,6 +108,22 @@ export default { this.pushRows(); }, 50); } + }, + clear() { + this.currentOffset = 0; + this.rows = []; + this.rowsToPush = []; + }, + sort(e) { + if (e.orderBy == this.currentOrderBy) { + this.currentOrderDesc = !this.currentOrderDesc; + } else { + this.currentOrderDesc = false; + } + this.currentOrderBy = e.orderBy; + console.log(e); + this.sortTriggered = true; + this.clear(); } } } diff --git a/src/components/userlist.vue b/src/components/userlist.vue index cb9fc61..ea5ac5d 100644 --- a/src/components/userlist.vue +++ b/src/components/userlist.vue @@ -1,7 +1,7 @@ @@ -18,11 +18,13 @@ export default { columns: [ { heading: 'ID', - prop: 'ID' + prop: 'ID', + orderBy: 'id' }, { heading: 'Benutzername', - prop: 'Username' + prop: 'Username', + orderBy: 'username' }, { heading: 'Render', @@ -37,13 +39,15 @@ export default { } }, methods: { - more(offset, limit) { + more(offset, limit, orderBy, orderDesc) { this.loading = true; this.$store.dispatch('apiRequest', { endpoint: 'users', params: { start: offset, - length: limit + length: limit, + orderBy, + orderDesc } }) .then(rows => {
{{ c.heading }} + {{ c.heading }} V + {{ c.heading }} +