Commit 52874e27e58017ca3a7af9078efa61b745bc336f

Authored by 梁灏
1 parent b8a43000

update Table

update Table
src/components/table/table-body.vue
... ... @@ -5,7 +5,7 @@
5 5 </colgroup>
6 6 <tbody :class="[prefixCls + '-tbody']">
7 7 <tr
8   - v-for="(index, row) in data"
  8 + v-for="(index, row) in cloneData"
9 9 :class="rowClasses(row, index)"
10 10 @mouseenter.stop="handleMouseIn(index)"
11 11 @mouseleave.stop="handleMouseOut(index)"
... ... @@ -34,7 +34,6 @@
34 34 prefixCls: String,
35 35 style: Object,
36 36 columns: Array,
37   - data: Array,
38 37 cloneData: Array,
39 38 fixed: Boolean
40 39 },
... ... @@ -53,7 +52,7 @@
53 52 return this.$parent.setCellWidth(column, index);
54 53 },
55 54 rowClsName (index) {
56   - return this.$parent.rowClassName(this.data[index], index);
  55 + return this.$parent.rowClassName(this.cloneData[index], index);
57 56 },
58 57 handleMouseIn (index) {
59 58 this.$parent.handleMouseIn(index);
... ...
src/components/table/table-head.vue
... ... @@ -8,7 +8,13 @@
8 8 <th v-for="column in columns" :class="alignCls(column)">
9 9 <div :class="cellClasses(column)">
10 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 18 </div>
13 19 </th>
14 20 </tr>
... ... @@ -57,6 +63,12 @@
57 63 selectAll () {
58 64 const status = !this.isSelectAll;
59 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 14 :prefix-cls="prefixCls"
15 15 :style="tableStyle"
16 16 :columns="cloneColumns"
17   - :data="data"
18 17 :clone-data="cloneData"></table-body>
19 18 </div>
20 19 <div :class="[prefixCls + '-fixed']">
... ... @@ -32,7 +31,6 @@
32 31 :prefix-cls="prefixCls"
33 32 :style="fixedTableStyle"
34 33 :columns="leftFixedColumns"
35   - :data="data"
36 34 :clone-data="cloneData"></table-body>
37 35 </div>
38 36 </div>
... ... @@ -51,7 +49,6 @@
51 49 :prefix-cls="prefixCls"
52 50 :style="fixedRightTableStyle"
53 51 :columns="rightFixedColumns"
54   - :data="data"
55 52 :clone-data="cloneData"></table-body>
56 53 </div>
57 54 </div>
... ... @@ -269,9 +266,11 @@
269 266 });
270 267 this.cloneData = tmpData;
271 268  
  269 + const selection = this.getSelection();
272 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 275 fixedHeader () {
277 276 if (!!this.height) {
... ... @@ -315,6 +314,13 @@
315 314 } else {
316 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 326 compiled () {
... ...
src/styles/components/table.less
... ... @@ -197,7 +197,7 @@
197 197 position: absolute;
198 198 top: 0;
199 199 left: 0;
200   - box-shadow: 1px 0 8px #d3d4d6;
  200 + box-shadow: @shadow-right;
201 201 overflow-x: hidden;
202 202  
203 203 &::before {
... ... @@ -215,7 +215,7 @@
215 215 top: 0;
216 216 left: auto;
217 217 right: 0;
218   - box-shadow: -1px 0 8px #d3d4d6;
  218 + box-shadow: @shadow-left;
219 219 }
220 220 &-fixed-header{
221 221 overflow: hidden;
... ... @@ -227,4 +227,8 @@
227 227 position: relative;
228 228 z-index: 3;
229 229 }
  230 +
  231 + &-sort{
  232 + .sortable();
  233 + }
230 234 }
231 235 \ No newline at end of file
... ...
src/styles/mixins/caret.less 0 → 100644
  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 34 \ No newline at end of file
... ...
src/styles/mixins/index.less
... ... @@ -12,3 +12,4 @@
12 12 @import "content"; // card、modal
13 13 @import "tooltip";
14 14 @import "select";
  15 +@import "caret";
15 16 \ No newline at end of file
... ...
test/routers/table.vue
... ... @@ -9,8 +9,9 @@
9 9 <br>
10 10 <i-table
11 11 width="450"
12   - height="200"
  12 + :height="height"
13 13 stripe
  14 + border
14 15 highlight-row
15 16 :show-header="true"
16 17 :columns="columns"
... ... @@ -55,6 +56,7 @@
55 56 key: 'age',
56 57 align: 'right',
57 58 // fixed: 'left',
  59 + sortable: true,
58 60 width: 100
59 61 // render (row) {
60 62 // return `<i-button>${row.age}</i-button>`
... ... @@ -80,7 +82,7 @@
80 82 fixed: 'right',
81 83 width: 120,
82 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 86 // return `<a>${row.name}</a>`
85 87 }
86 88 }
... ... @@ -153,7 +155,6 @@
153 155 // this.columns[2].width = 150;
154 156 // return;
155 157 // this.height = 150;
156   -// return
157 158 // this.data.push({
158 159 // name: '刘天娇2',
159 160 // age: 272,
... ... @@ -161,6 +162,7 @@
161 162 // edit: false
162 163 // });
163 164 // this.data.splice(1, 1)
  165 +// this.columns.splice(2,1)
164 166 }, 2000);
165 167 }
166 168 }
... ...