Merge pull request #2309 from njleonzhang/fix_sortevent_bug

fix bug: default-sort-prop is not defined but trigger sort-change event
pull/2390/head
baiyaaaaa 2017-01-12 22:38:22 +08:00 committed by GitHub
commit 5246b170f4
2 changed files with 18 additions and 12 deletions

View File

@ -190,20 +190,26 @@ export default {
}, },
mounted() { mounted() {
const states = this.store.states; if (this.defaultSortProp) {
states.sortProp = this.defaultSortProp; const states = this.store.states;
states.sortOrder = this.defaultSortOrder; states.sortProp = this.defaultSortProp;
states.sortOrder = this.defaultSortOrder;
this.$nextTick(_ => { this.$nextTick(_ => {
for (let i = 0, length = this.columns.length; i < length; i++) { for (let i = 0, length = this.columns.length; i < length; i++) {
if (this.columns[i].property === this.defaultSortProp) { let column = this.columns[i];
this.columns[i].order = this.defaultSortOrder; if (column.property === this.defaultSortProp) {
break; column.order = this.defaultSortOrder;
states.sortingColumn = column;
break;
}
} }
}
this.store.commit('changeSortCondition'); if (states.sortingColumn) {
}); this.store.commit('changeSortCondition');
}
});
}
}, },
beforeDestroy() { beforeDestroy() {

View File

@ -1127,7 +1127,7 @@ describe('Table', () => {
} }
}, '@sort-change="sortChange"'); }, '@sort-change="sortChange"');
setTimeout(_ => { setTimeout(_ => {
const elm = vm.$el.querySelector('.caret-wrapper > .ascending'); const elm = vm.$el.querySelector('.caret-wrapper');
elm.click(); elm.click();
setTimeout(_ => { setTimeout(_ => {