Commit 1b737fdc83027a0ae722e517446ac444fe7798b3
1 parent
096f2bfe
fixed #122
Showing
2 changed files
with
19 additions
and
5 deletions
Show diff stats
examples/routers/table.vue
@@ -21,15 +21,16 @@ | @@ -21,15 +21,16 @@ | ||
21 | title: '姓名', | 21 | title: '姓名', |
22 | key: 'name', | 22 | key: 'name', |
23 | width: 100, | 23 | width: 100, |
24 | - fixed: 'left', | ||
25 | sortable: true, | 24 | sortable: true, |
26 | - renderHeader: (h, params) => { | ||
27 | - return h('Tag', params.index) | ||
28 | - } | 25 | +// fixed: 'left', |
26 | +// renderHeader: (h, params) => { | ||
27 | +// return h('Tag', params.index) | ||
28 | +// } | ||
29 | }, | 29 | }, |
30 | { | 30 | { |
31 | title: '年龄', | 31 | title: '年龄', |
32 | key: 'age', | 32 | key: 'age', |
33 | + sortable: true, | ||
33 | width: 100 | 34 | width: 100 |
34 | }, | 35 | }, |
35 | { | 36 | { |
src/components/table/table-head.vue
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | <template v-if="column.type === 'expand'"></template> | 10 | <template v-if="column.type === 'expand'"></template> |
11 | <template v-else-if="column.type === 'selection'"><Checkbox :value="isSelectAll" @on-change="selectAll"></Checkbox></template> | 11 | <template v-else-if="column.type === 'selection'"><Checkbox :value="isSelectAll" @on-change="selectAll"></Checkbox></template> |
12 | <template v-else> | 12 | <template v-else> |
13 | - <span v-if="!column.renderHeader">{{ column.title || '#' }}</span> | 13 | + <span v-if="!column.renderHeader" @click="handleSortByHead(index)">{{ column.title || '#' }}</span> |
14 | <render-header v-else :render="column.renderHeader" :column="column" :index="index"></render-header> | 14 | <render-header v-else :render="column.renderHeader" :column="column" :index="index"></render-header> |
15 | <span :class="[prefixCls + '-sort']" v-if="column.sortable"> | 15 | <span :class="[prefixCls + '-sort']" v-if="column.sortable"> |
16 | <i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort(index, 'asc')"></i> | 16 | <i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort(index, 'asc')"></i> |
@@ -134,6 +134,19 @@ | @@ -134,6 +134,19 @@ | ||
134 | } | 134 | } |
135 | this.$parent.handleSort(index, type); | 135 | this.$parent.handleSort(index, type); |
136 | }, | 136 | }, |
137 | + handleSortByHead (index) { | ||
138 | + const column = this.columns[index]; | ||
139 | + if (column.sortable) { | ||
140 | + const type = column._sortType; | ||
141 | + if (type === 'normal') { | ||
142 | + this.handleSort(index, 'asc'); | ||
143 | + } else if (type === 'asc') { | ||
144 | + this.handleSort(index, 'desc'); | ||
145 | + } else { | ||
146 | + this.handleSort(index, 'normal'); | ||
147 | + } | ||
148 | + } | ||
149 | + }, | ||
137 | handleFilter (index) { | 150 | handleFilter (index) { |
138 | this.$parent.handleFilter(index); | 151 | this.$parent.handleFilter(index); |
139 | }, | 152 | }, |