From cb31ede0398f8e6f746c015b5a8db00b0179beee Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Tue, 29 Nov 2016 14:55:25 +0800 Subject: [PATCH] update Table --- src/components/table/table.vue | 31 ++++++++++++++++++++++++------- test/routers/table.vue | 26 +++++++++++++++++--------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/components/table/table.vue b/src/components/table/table.vue index 88ad85c..b511728 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -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); diff --git a/test/routers/table.vue b/test/routers/table.vue index 353c97e..91afb40 100644 --- a/test/routers/table.vue +++ b/test/routers/table.vue @@ -8,7 +8,7 @@
= 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 `${row.age}` // } -- libgit2 0.21.4