Whenever I click on the header of a sortable column, I can trigger an event (header-click). However, clicking on the sort carets does not have any effect.
This behavior is normal. It seems like you are looking for the sort-change
event, which is activated when the table's sorting changes:
<template>
<el-table @sort-change="sortChange" @header-click="headerClick" :data="tableData" :default-sort="{prop: 'date', order: 'descending'}" style="width: 100%">
<el-table-column prop="date" label="Date" sortable width="180">
</el-table-column>
<el-table-column prop="name" label="Name" sortable width="180">
</el-table-column>
<el-table-column prop="address" label="Address" sortable :formatter="formatter">
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [{
date: '2016-05-03',
name: 'Tom',
address: 'No. 189, Grove St, Los Angeles'
},
//...
]
}
},
methods: {
sortChange(sortProps){
this.headerClick(sortProps.column,event) //optional: trigger header-click event
},
headerClick(column, event){
console.log("Header clicked: " + JSON.stringify(column))
}
}
}
</script>
Demo