Commit 97edb2eb3bc90d356a1540b1218b70e3dd7cb8f6

Authored by 梁灏
1 parent 9f853e3e

update Table

update Table
src/components/table/table-body.vue
... ... @@ -45,13 +45,13 @@
45 45 `${this.prefixCls}-row`,
46 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 53 rowChecked (_index) {
54   - return this.objData[_index]._isChecked;
  54 + return this.objData[_index] && this.objData[_index]._isChecked;
55 55 },
56 56 setCellWidth (column, index) {
57 57 return this.$parent.setCellWidth(column, index);
... ...
src/components/table/table.vue
... ... @@ -338,7 +338,7 @@
338 338 const key = this.cloneColumns[index].key;
339 339 if (this.cloneColumns[index].sortable !== 'custom') { // custom is for remote sort
340 340 if (type === 'normal') {
341   - this.rebuildData = this.makeData();
  341 + this.rebuildData = this.makeDataWithFilter();
342 342 } else {
343 343 this.rebuildData = this.sortData(this.rebuildData, type, index);
344 344 }
... ... @@ -415,6 +415,16 @@
415 415 if (sortType !== 'normal') data = this.sortData(data, sortType, sortIndex);
416 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 428 makeObjData () {
419 429 let data = {};
420 430 this.data.forEach((row, index) => {
... ... @@ -473,7 +483,7 @@
473 483 data: {
474 484 handler () {
475 485 this.objData = this.makeObjData();
476   - this.rebuildData = this.makeData();
  486 + this.rebuildData = this.makeDataWithSortAndFilter();
477 487 this.handleResize();
478 488 },
479 489 deep: true
... ... @@ -481,6 +491,7 @@
481 491 columns: {
482 492 handler () {
483 493 this.cloneColumns = this.makeColumns();
  494 + this.rebuildData = this.makeDataWithSortAndFilter();
484 495 this.handleResize();
485 496 },
486 497 deep: true
... ...
test/routers/table.vue
... ... @@ -25,6 +25,7 @@
25 25 <!--<div slot="footer">表格标题</div>-->
26 26 </i-table>
27 27 <br>
  28 + <i-button @click="showChildren">显示子节点</i-button>
28 29 <!--<i-table size="small" border stripe :columns="columns" :data="data"></i-table>-->
29 30 </div>
30 31 </template>
... ... @@ -219,6 +220,9 @@
219 220 },
220 221 sortChange (data) {
221 222 console.log(data)
  223 + },
  224 + showChildren () {
  225 + console.log(this.$children)
222 226 }
223 227 },
224 228 ready () {
... ... @@ -233,8 +237,8 @@
233 237 // address: '北京市东城区2',
234 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 242 }, 3000);
239 243 }
240 244 }
... ...