Skip to content

Commit ec58373

Browse files
authored
add an example of sort data by table (#1236)
1 parent bf2629f commit ec58373

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/views/table/complexTable.vue

+17-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
border
2525
fit
2626
highlight-current-row
27-
style="width: 100%;">
28-
<el-table-column :label="$t('table.id')" align="center" width="65">
27+
style="width: 100%;"
28+
@sort-change="sortChange">
29+
<el-table-column :label="$t('table.id')" prop="id" sortable="custom" align="center" width="65">
2930
<template slot-scope="scope">
3031
<span>{{ scope.row.id }}</span>
3132
</template>
@@ -233,6 +234,20 @@ export default {
233234
})
234235
row.status = status
235236
},
237+
sortChange(data) {
238+
const { prop, order } = data
239+
if (prop === 'id') {
240+
this.sortByID(order)
241+
}
242+
},
243+
sortByID(order) {
244+
if (order === 'ascending') {
245+
this.listQuery.sort = '+id'
246+
} else {
247+
this.listQuery.sort = '-id'
248+
}
249+
this.handleFilter()
250+
},
236251
resetTemp() {
237252
this.temp = {
238253
id: undefined,

0 commit comments

Comments
 (0)