Skip to content

Commit 2cce229

Browse files
bezanylzq4047
authored andcommitted
Table: fix sort icon (ElemeFE#15439)
1 parent 43c4ac0 commit 2cce229

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packages/table/src/store/watcher.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ export default Vue.extend({
266266
},
267267

268268
updateSort(column, prop, order) {
269+
if (this.states.sortingColumn && this.states.sortingColumn !== column) {
270+
this.states.sortingColumn.order = null;
271+
}
269272
this.states.sortingColumn = column;
270273
this.states.sortProp = prop;
271274
this.states.sortOrder = order;

test/unit/specs/table.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,11 +1753,47 @@ describe('Table', () => {
17531753
vm.$nextTick(() => {
17541754
expect(toArray(lastCells).map(node => node.textContent))
17551755
.to.eql(['-100', '-95', '-92', '-92', '-80']);
1756+
destroyVM(vm);
17561757
done();
17571758
});
17581759
});
17591760
}, DELAY);
17601761
});
1762+
1763+
it('sort correct change icon', async() => {
1764+
function assertSortIconCount($el, msg, count = 1) {
1765+
const sortIconCount = $el.querySelectorAll('th.ascending, th.descending').length;
1766+
expect(sortIconCount).to.equal(count, msg);
1767+
}
1768+
1769+
const vm = createVue({
1770+
template: `
1771+
<el-table ref="table" :data="testData" >
1772+
<el-table-column prop="name" sortable />
1773+
<el-table-column prop="release" sortable />
1774+
<el-table-column prop="director" sortable />
1775+
<el-table-column prop="runtime" sortable />
1776+
</el-table>
1777+
`,
1778+
data() {
1779+
return { testData: getTestData() };
1780+
}
1781+
});
1782+
await waitImmediate();
1783+
assertSortIconCount(vm.$el, 'sorting icon is not empty after mount', 0);
1784+
// manual click first column header
1785+
const elm = vm.$el.querySelector('.caret-wrapper');
1786+
elm.click();
1787+
await waitImmediate();
1788+
assertSortIconCount(vm.$el, 'sorting icon is not one after click header');
1789+
vm.$refs.table.sort('director', 'descending');
1790+
await waitImmediate();
1791+
assertSortIconCount(vm.$el, 'sorting icon is not one after call sort');
1792+
vm.$refs.table.sort('director', 'ascending');
1793+
await waitImmediate();
1794+
assertSortIconCount(vm.$el, 'sorting icon is not one after sort same column');
1795+
destroyVM(vm);
1796+
});
17611797
});
17621798

17631799
it('hover', async() => {

0 commit comments

Comments
 (0)