Skip to content

Commit

Permalink
Fix #1126 init sort using columns prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jtommy committed Dec 19, 2018
1 parent a8fe73e commit 19ec350
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@

* Fix taginput when ``allow-new`` is enabled
* Fix pagination order when simple
* #1126 Fix init sort using columns table prop

## 0.7.1

Expand Down
39 changes: 22 additions & 17 deletions src/components/table/Table.vue
Expand Up @@ -403,23 +403,8 @@
this.newColumns = [...value]
},
/**
* When newColumns change, call initSort only first time (For example async data).
*/
newColumns(newColumns) {
if (newColumns.length && this.firstTimeSort) {
this.initSort()
this.firstTimeSort = false
} else if (newColumns.length) {
if (this.currentSortColumn.field) {
for (let i = 0; i < newColumns.length; i++) {
if (newColumns[i].field === this.currentSortColumn.field) {
this.currentSortColumn = newColumns[i]
break
}
}
}
}
newColumns(value) {
this.checkSort()
},
/**
Expand Down Expand Up @@ -636,6 +621,25 @@
}
},
/**
* Call initSort only first time (For example async data).
*/
checkSort() {
if (this.newColumns.length && this.firstTimeSort) {
this.initSort()
this.firstTimeSort = false
} else if (this.newColumns.length) {
if (this.currentSortColumn.field) {
for (let i = 0; i < this.newColumns.length; i++) {
if (this.newColumns[i].field === this.currentSortColumn.field) {
this.currentSortColumn = this.newColumns[i]
break
}
}
}
}
},
/**
* Check if footer slot has custom content.
*/
Expand Down Expand Up @@ -711,6 +715,7 @@
mounted() {
this.checkPredefinedDetailedRows()
this.checkSort()
}
}
</script>

0 comments on commit 19ec350

Please sign in to comment.