update Table

update Table
This commit is contained in:
梁灏 2016-11-29 14:55:25 +08:00
parent 45e7ed7ef5
commit cb31ede039
2 changed files with 41 additions and 16 deletions

View file

@ -358,18 +358,32 @@
handleFilterHide (index) { // clear checked that not filter now
if (!this.cloneColumns[index]._isFiltered) this.cloneColumns[index]._filterChecked = [];
},
handleFilter (index) {
const column = this.cloneColumns[index];
const filterData = this.makeData();
this.rebuildData = filterData.filter((row) => {
let status = false;
filterData (data, column) {
return data.filter((row) => {
let status = !column._filterChecked.length;
for (let i = 0; i < column._filterChecked.length; i++) {
status = column.filterMethod(column._filterChecked[i], row);
if (status) break;
}
return status;
});
},
filterOtherData (data, index) {
this.cloneColumns.forEach((col, colIndex) => {
if (colIndex !== index) {
data = this.filterData(data, col);
}
});
return data;
},
handleFilter (index) {
const column = this.cloneColumns[index];
let filterData = this.makeData();
// filter others first, after filter this column
filterData = this.filterOtherData(filterData, index);
this.rebuildData = this.filterData(filterData, column);
this.cloneColumns[index]._isFiltered = true;
this.cloneColumns[index]._filterVisible = false;
},
@ -381,7 +395,10 @@
this.cloneColumns[index]._isFiltered = false;
this.cloneColumns[index]._filterVisible = false;
this.cloneColumns[index]._filterChecked = [];
this.rebuildData = this.makeData();
let filterData = this.makeData();
filterData = this.filterOtherData(filterData, index);
this.rebuildData = filterData;
},
makeData () {
let data = deepCopy(this.data);

View file

@ -8,7 +8,7 @@
<!--<i-table size="large" border stripe :columns="columns" :data="data"></i-table>-->
<br>
<i-table
width="450"
width="850"
stripe
border
highlight-row
@ -55,20 +55,20 @@
width: 100,
filters: [
{
label: '大于25岁',
label: '两个字',
value: 1
},
{
label: '小于25岁',
label: '三个字',
value: 2
}
],
filterMultiple: false,
filterMethod (value, row) {
if (value === 1) {
return row.age >= 25;
return row.name.length == 2;
} else if (value === 2) {
return row.age < 25;
return row.name.length == 3;
}
}
},
@ -103,14 +103,22 @@
width: 100,
filters: [
{
label: '',
value: 'home'
label: '大于25岁',
value: 1
},
{
label: '公司',
value: 'company'
label: '小于25岁',
value: 2
}
],
filterMultiple: false,
filterMethod (value, row) {
if (value === 1) {
return row.age >= 25;
} else if (value === 2) {
return row.age < 25;
}
}
// render (row) {
// return `<i-button>${row.age}</i-button>`
// }