Commit 52874e27e58017ca3a7af9078efa61b745bc336f
1 parent
b8a43000
update Table
update Table
Showing
7 changed files
with
70 additions
and
13 deletions
Show diff stats
src/components/table/table-body.vue
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | </colgroup> | 5 | </colgroup> |
6 | <tbody :class="[prefixCls + '-tbody']"> | 6 | <tbody :class="[prefixCls + '-tbody']"> |
7 | <tr | 7 | <tr |
8 | - v-for="(index, row) in data" | 8 | + v-for="(index, row) in cloneData" |
9 | :class="rowClasses(row, index)" | 9 | :class="rowClasses(row, index)" |
10 | @mouseenter.stop="handleMouseIn(index)" | 10 | @mouseenter.stop="handleMouseIn(index)" |
11 | @mouseleave.stop="handleMouseOut(index)" | 11 | @mouseleave.stop="handleMouseOut(index)" |
@@ -34,7 +34,6 @@ | @@ -34,7 +34,6 @@ | ||
34 | prefixCls: String, | 34 | prefixCls: String, |
35 | style: Object, | 35 | style: Object, |
36 | columns: Array, | 36 | columns: Array, |
37 | - data: Array, | ||
38 | cloneData: Array, | 37 | cloneData: Array, |
39 | fixed: Boolean | 38 | fixed: Boolean |
40 | }, | 39 | }, |
@@ -53,7 +52,7 @@ | @@ -53,7 +52,7 @@ | ||
53 | return this.$parent.setCellWidth(column, index); | 52 | return this.$parent.setCellWidth(column, index); |
54 | }, | 53 | }, |
55 | rowClsName (index) { | 54 | rowClsName (index) { |
56 | - return this.$parent.rowClassName(this.data[index], index); | 55 | + return this.$parent.rowClassName(this.cloneData[index], index); |
57 | }, | 56 | }, |
58 | handleMouseIn (index) { | 57 | handleMouseIn (index) { |
59 | this.$parent.handleMouseIn(index); | 58 | this.$parent.handleMouseIn(index); |
src/components/table/table-head.vue
@@ -8,7 +8,13 @@ | @@ -8,7 +8,13 @@ | ||
8 | <th v-for="column in columns" :class="alignCls(column)"> | 8 | <th v-for="column in columns" :class="alignCls(column)"> |
9 | <div :class="cellClasses(column)"> | 9 | <div :class="cellClasses(column)"> |
10 | <template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template> | 10 | <template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template> |
11 | - <template v-else>{{{ renderHeader(column, $index) }}}</template> | 11 | + <template v-else> |
12 | + {{{ renderHeader(column, $index) }}} | ||
13 | + <span :class="[prefixCls + '-sort']" v-if="column.sortable"> | ||
14 | + <i class="ivu-icon ivu-icon-arrow-up-b" @click="handleSortAsc($index)"></i> | ||
15 | + <i class="ivu-icon ivu-icon-arrow-down-b" @click="handleSortDesc($index)"></i> | ||
16 | + </span> | ||
17 | + </template> | ||
12 | </div> | 18 | </div> |
13 | </th> | 19 | </th> |
14 | </tr> | 20 | </tr> |
@@ -57,6 +63,12 @@ | @@ -57,6 +63,12 @@ | ||
57 | selectAll () { | 63 | selectAll () { |
58 | const status = !this.isSelectAll; | 64 | const status = !this.isSelectAll; |
59 | this.$parent.selectAll(status); | 65 | this.$parent.selectAll(status); |
66 | + }, | ||
67 | + handleSortAsc (index) { | ||
68 | + this.$parent.handleSort(index, 'asc'); | ||
69 | + }, | ||
70 | + handleSortDesc (index) { | ||
71 | + this.$parent.handleSort(index, 'desc'); | ||
60 | } | 72 | } |
61 | } | 73 | } |
62 | } | 74 | } |
src/components/table/table.vue
@@ -14,7 +14,6 @@ | @@ -14,7 +14,6 @@ | ||
14 | :prefix-cls="prefixCls" | 14 | :prefix-cls="prefixCls" |
15 | :style="tableStyle" | 15 | :style="tableStyle" |
16 | :columns="cloneColumns" | 16 | :columns="cloneColumns" |
17 | - :data="data" | ||
18 | :clone-data="cloneData"></table-body> | 17 | :clone-data="cloneData"></table-body> |
19 | </div> | 18 | </div> |
20 | <div :class="[prefixCls + '-fixed']"> | 19 | <div :class="[prefixCls + '-fixed']"> |
@@ -32,7 +31,6 @@ | @@ -32,7 +31,6 @@ | ||
32 | :prefix-cls="prefixCls" | 31 | :prefix-cls="prefixCls" |
33 | :style="fixedTableStyle" | 32 | :style="fixedTableStyle" |
34 | :columns="leftFixedColumns" | 33 | :columns="leftFixedColumns" |
35 | - :data="data" | ||
36 | :clone-data="cloneData"></table-body> | 34 | :clone-data="cloneData"></table-body> |
37 | </div> | 35 | </div> |
38 | </div> | 36 | </div> |
@@ -51,7 +49,6 @@ | @@ -51,7 +49,6 @@ | ||
51 | :prefix-cls="prefixCls" | 49 | :prefix-cls="prefixCls" |
52 | :style="fixedRightTableStyle" | 50 | :style="fixedRightTableStyle" |
53 | :columns="rightFixedColumns" | 51 | :columns="rightFixedColumns" |
54 | - :data="data" | ||
55 | :clone-data="cloneData"></table-body> | 52 | :clone-data="cloneData"></table-body> |
56 | </div> | 53 | </div> |
57 | </div> | 54 | </div> |
@@ -269,9 +266,11 @@ | @@ -269,9 +266,11 @@ | ||
269 | }); | 266 | }); |
270 | this.cloneData = tmpData; | 267 | this.cloneData = tmpData; |
271 | 268 | ||
269 | + const selection = this.getSelection(); | ||
272 | if (status) { | 270 | if (status) { |
273 | - this.$emit('on-select-all', this.getSelection()); | 271 | + this.$emit('on-select-all', selection); |
274 | } | 272 | } |
273 | + this.$emit('on-selection-change', selection); | ||
275 | }, | 274 | }, |
276 | fixedHeader () { | 275 | fixedHeader () { |
277 | if (!!this.height) { | 276 | if (!!this.height) { |
@@ -315,6 +314,13 @@ | @@ -315,6 +314,13 @@ | ||
315 | } else { | 314 | } else { |
316 | $body.scrollLeft = $body.scrollLeft - 10; | 315 | $body.scrollLeft = $body.scrollLeft - 10; |
317 | } | 316 | } |
317 | + }, | ||
318 | + handleSort (index, type) { | ||
319 | + if (type === 'asc') { | ||
320 | + | ||
321 | + } else if (type === 'desc') { | ||
322 | + | ||
323 | + } | ||
318 | } | 324 | } |
319 | }, | 325 | }, |
320 | compiled () { | 326 | compiled () { |
src/styles/components/table.less
@@ -197,7 +197,7 @@ | @@ -197,7 +197,7 @@ | ||
197 | position: absolute; | 197 | position: absolute; |
198 | top: 0; | 198 | top: 0; |
199 | left: 0; | 199 | left: 0; |
200 | - box-shadow: 1px 0 8px #d3d4d6; | 200 | + box-shadow: @shadow-right; |
201 | overflow-x: hidden; | 201 | overflow-x: hidden; |
202 | 202 | ||
203 | &::before { | 203 | &::before { |
@@ -215,7 +215,7 @@ | @@ -215,7 +215,7 @@ | ||
215 | top: 0; | 215 | top: 0; |
216 | left: auto; | 216 | left: auto; |
217 | right: 0; | 217 | right: 0; |
218 | - box-shadow: -1px 0 8px #d3d4d6; | 218 | + box-shadow: @shadow-left; |
219 | } | 219 | } |
220 | &-fixed-header{ | 220 | &-fixed-header{ |
221 | overflow: hidden; | 221 | overflow: hidden; |
@@ -227,4 +227,8 @@ | @@ -227,4 +227,8 @@ | ||
227 | position: relative; | 227 | position: relative; |
228 | z-index: 3; | 228 | z-index: 3; |
229 | } | 229 | } |
230 | + | ||
231 | + &-sort{ | ||
232 | + .sortable(); | ||
233 | + } | ||
230 | } | 234 | } |
231 | \ No newline at end of file | 235 | \ No newline at end of file |
1 | +// sortable | ||
2 | +.sortable() { | ||
3 | + display: inline-block; | ||
4 | + width: 8px; | ||
5 | + height: 12px; | ||
6 | + margin-left: 4px; | ||
7 | + margin-top: -1px; | ||
8 | + vertical-align: middle; | ||
9 | + overflow: hidden; | ||
10 | + cursor: pointer; | ||
11 | + position: relative; | ||
12 | + | ||
13 | + i { | ||
14 | + display: block; | ||
15 | + height: 6px; | ||
16 | + line-height: 6px; | ||
17 | + overflow: hidden; | ||
18 | + position: absolute; | ||
19 | + color: @btn-disable-color; | ||
20 | + transition: color @transition-time @ease-in-out; | ||
21 | + | ||
22 | + &:hover{ | ||
23 | + color: inherit; | ||
24 | + } | ||
25 | + | ||
26 | + &:first-child{ | ||
27 | + top: 0; | ||
28 | + } | ||
29 | + &:last-child{ | ||
30 | + bottom: 0; | ||
31 | + } | ||
32 | + } | ||
33 | +} | ||
0 | \ No newline at end of file | 34 | \ No newline at end of file |
src/styles/mixins/index.less
test/routers/table.vue
@@ -9,8 +9,9 @@ | @@ -9,8 +9,9 @@ | ||
9 | <br> | 9 | <br> |
10 | <i-table | 10 | <i-table |
11 | width="450" | 11 | width="450" |
12 | - height="200" | 12 | + :height="height" |
13 | stripe | 13 | stripe |
14 | + border | ||
14 | highlight-row | 15 | highlight-row |
15 | :show-header="true" | 16 | :show-header="true" |
16 | :columns="columns" | 17 | :columns="columns" |
@@ -55,6 +56,7 @@ | @@ -55,6 +56,7 @@ | ||
55 | key: 'age', | 56 | key: 'age', |
56 | align: 'right', | 57 | align: 'right', |
57 | // fixed: 'left', | 58 | // fixed: 'left', |
59 | + sortable: true, | ||
58 | width: 100 | 60 | width: 100 |
59 | // render (row) { | 61 | // render (row) { |
60 | // return `<i-button>${row.age}</i-button>` | 62 | // return `<i-button>${row.age}</i-button>` |
@@ -80,7 +82,7 @@ | @@ -80,7 +82,7 @@ | ||
80 | fixed: 'right', | 82 | fixed: 'right', |
81 | width: 120, | 83 | width: 120, |
82 | render (row, column, index) { | 84 | render (row, column, index) { |
83 | - return `<i-button @click="edit(${index})">${row.name}</i-button>` | 85 | + return `<i-button @click="edit(${index})">${row.name}${index}</i-button>` |
84 | // return `<a>${row.name}</a>` | 86 | // return `<a>${row.name}</a>` |
85 | } | 87 | } |
86 | } | 88 | } |
@@ -153,7 +155,6 @@ | @@ -153,7 +155,6 @@ | ||
153 | // this.columns[2].width = 150; | 155 | // this.columns[2].width = 150; |
154 | // return; | 156 | // return; |
155 | // this.height = 150; | 157 | // this.height = 150; |
156 | -// return | ||
157 | // this.data.push({ | 158 | // this.data.push({ |
158 | // name: '刘天娇2', | 159 | // name: '刘天娇2', |
159 | // age: 272, | 160 | // age: 272, |
@@ -161,6 +162,7 @@ | @@ -161,6 +162,7 @@ | ||
161 | // edit: false | 162 | // edit: false |
162 | // }); | 163 | // }); |
163 | // this.data.splice(1, 1) | 164 | // this.data.splice(1, 1) |
165 | +// this.columns.splice(2,1) | ||
164 | }, 2000); | 166 | }, 2000); |
165 | } | 167 | } |
166 | } | 168 | } |