Commit 97edb2eb3bc90d356a1540b1218b70e3dd7cb8f6
1 parent
9f853e3e
update Table
update Table
Showing
3 changed files
with
22 additions
and
7 deletions
Show diff stats
src/components/table/table-body.vue
@@ -45,13 +45,13 @@ | @@ -45,13 +45,13 @@ | ||
45 | `${this.prefixCls}-row`, | 45 | `${this.prefixCls}-row`, |
46 | this.rowClsName(_index), | 46 | this.rowClsName(_index), |
47 | { | 47 | { |
48 | - [`${this.prefixCls}-row-highlight`]: this.objData[_index]._isHighlight, | ||
49 | - [`${this.prefixCls}-row-hover`]: this.objData[_index]._isHover | 48 | + [`${this.prefixCls}-row-highlight`]: this.objData[_index] && this.objData[_index]._isHighlight, |
49 | + [`${this.prefixCls}-row-hover`]: this.objData[_index] && this.objData[_index]._isHover | ||
50 | } | 50 | } |
51 | ] | 51 | ] |
52 | }, | 52 | }, |
53 | rowChecked (_index) { | 53 | rowChecked (_index) { |
54 | - return this.objData[_index]._isChecked; | 54 | + return this.objData[_index] && this.objData[_index]._isChecked; |
55 | }, | 55 | }, |
56 | setCellWidth (column, index) { | 56 | setCellWidth (column, index) { |
57 | return this.$parent.setCellWidth(column, index); | 57 | return this.$parent.setCellWidth(column, index); |
src/components/table/table.vue
@@ -338,7 +338,7 @@ | @@ -338,7 +338,7 @@ | ||
338 | const key = this.cloneColumns[index].key; | 338 | const key = this.cloneColumns[index].key; |
339 | if (this.cloneColumns[index].sortable !== 'custom') { // custom is for remote sort | 339 | if (this.cloneColumns[index].sortable !== 'custom') { // custom is for remote sort |
340 | if (type === 'normal') { | 340 | if (type === 'normal') { |
341 | - this.rebuildData = this.makeData(); | 341 | + this.rebuildData = this.makeDataWithFilter(); |
342 | } else { | 342 | } else { |
343 | this.rebuildData = this.sortData(this.rebuildData, type, index); | 343 | this.rebuildData = this.sortData(this.rebuildData, type, index); |
344 | } | 344 | } |
@@ -415,6 +415,16 @@ | @@ -415,6 +415,16 @@ | ||
415 | if (sortType !== 'normal') data = this.sortData(data, sortType, sortIndex); | 415 | if (sortType !== 'normal') data = this.sortData(data, sortType, sortIndex); |
416 | return data; | 416 | return data; |
417 | }, | 417 | }, |
418 | + makeDataWithFilter () { | ||
419 | + let data = this.makeData(); | ||
420 | + this.cloneColumns.forEach(col => data = this.filterData(data, col)); | ||
421 | + return data; | ||
422 | + }, | ||
423 | + makeDataWithSortAndFilter () { | ||
424 | + let data = this.makeDataWithSort(); | ||
425 | + this.cloneColumns.forEach(col => data = this.filterData(data, col)); | ||
426 | + return data; | ||
427 | + }, | ||
418 | makeObjData () { | 428 | makeObjData () { |
419 | let data = {}; | 429 | let data = {}; |
420 | this.data.forEach((row, index) => { | 430 | this.data.forEach((row, index) => { |
@@ -473,7 +483,7 @@ | @@ -473,7 +483,7 @@ | ||
473 | data: { | 483 | data: { |
474 | handler () { | 484 | handler () { |
475 | this.objData = this.makeObjData(); | 485 | this.objData = this.makeObjData(); |
476 | - this.rebuildData = this.makeData(); | 486 | + this.rebuildData = this.makeDataWithSortAndFilter(); |
477 | this.handleResize(); | 487 | this.handleResize(); |
478 | }, | 488 | }, |
479 | deep: true | 489 | deep: true |
@@ -481,6 +491,7 @@ | @@ -481,6 +491,7 @@ | ||
481 | columns: { | 491 | columns: { |
482 | handler () { | 492 | handler () { |
483 | this.cloneColumns = this.makeColumns(); | 493 | this.cloneColumns = this.makeColumns(); |
494 | + this.rebuildData = this.makeDataWithSortAndFilter(); | ||
484 | this.handleResize(); | 495 | this.handleResize(); |
485 | }, | 496 | }, |
486 | deep: true | 497 | deep: true |
test/routers/table.vue
@@ -25,6 +25,7 @@ | @@ -25,6 +25,7 @@ | ||
25 | <!--<div slot="footer">表格标题</div>--> | 25 | <!--<div slot="footer">表格标题</div>--> |
26 | </i-table> | 26 | </i-table> |
27 | <br> | 27 | <br> |
28 | + <i-button @click="showChildren">显示子节点</i-button> | ||
28 | <!--<i-table size="small" border stripe :columns="columns" :data="data"></i-table>--> | 29 | <!--<i-table size="small" border stripe :columns="columns" :data="data"></i-table>--> |
29 | </div> | 30 | </div> |
30 | </template> | 31 | </template> |
@@ -219,6 +220,9 @@ | @@ -219,6 +220,9 @@ | ||
219 | }, | 220 | }, |
220 | sortChange (data) { | 221 | sortChange (data) { |
221 | console.log(data) | 222 | console.log(data) |
223 | + }, | ||
224 | + showChildren () { | ||
225 | + console.log(this.$children) | ||
222 | } | 226 | } |
223 | }, | 227 | }, |
224 | ready () { | 228 | ready () { |
@@ -233,8 +237,8 @@ | @@ -233,8 +237,8 @@ | ||
233 | // address: '北京市东城区2', | 237 | // address: '北京市东城区2', |
234 | // edit: false | 238 | // edit: false |
235 | // }); | 239 | // }); |
236 | -// this.data.splice(0, 1) | ||
237 | -// this.columns.splice(2,1) | 240 | +// this.data.splice(0, 1); |
241 | + this.columns.splice(2,1) | ||
238 | }, 3000); | 242 | }, 3000); |
239 | } | 243 | } |
240 | } | 244 | } |