From 12bcf7bd14d0ca8f098ff7ad293e4f0f2fd8f872 Mon Sep 17 00:00:00 2001 From: H <21418592@qq.com> Date: Thu, 6 Apr 2017 17:07:03 +0800 Subject: [PATCH] 添加 remoteFilter方法,支持用户远程筛选数据 --- examples/routers/table.vue | 40 +++++++++++++++++++++++++++++++++++++++- src/components/table/table.vue | 8 ++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/examples/routers/table.vue b/examples/routers/table.vue index bed307c..7eb7eee 100644 --- a/examples/routers/table.vue +++ b/examples/routers/table.vue @@ -15,7 +15,28 @@ }, { title: '年龄', - key: 'age' + key: 'age', + filters:[ + { + label: '小学', + value: '小学' + }, + { + label: '中学', + value: '大学' + }, + { + label: '中学', + value: '中学' + } + ], + filterRemote:function(value,key,column){ + var that = this; + this.$Notice.open({title:`正在远程过滤${key}`,desc:value,duration:3,onClose:function(){ + that.remoteFilter(value,key,column) + }}) + + } }, { title: '地址', @@ -45,6 +66,23 @@ } ] } + + }, + methods:{ + remoteFilter:function(val,age,column){ + this.data1 = [ + { + name: '模拟1', + age: 18, + address: '北京市朝阳区芍药居' + }, + { + name: '模拟2', + age: 25, + address: '北京市海淀区西二旗' + }, + ] + } } } diff --git a/src/components/table/table.vue b/src/components/table/table.vue index 1b588c1..dbc2cd1 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -496,6 +496,9 @@ }, filterData (data, column) { return data.filter((row) => { + if(typeof column.filterRemote == 'function'){ //如果定义了远程过滤方法则忽略此方法 + return true; + } let status = !column._filterChecked.length; for (let i = 0; i < column._filterChecked.length; i++) { status = column.filterMethod(column._filterChecked[i], row); @@ -505,6 +508,11 @@ }); }, filterOtherData (data, index) { + let column = this.cloneColumns[index]; + if(typeof column.filterRemote == 'function'){ + column.filterRemote.call(this.currentContext,column._filterChecked,column.key,column); + } + this.cloneColumns.forEach((col, colIndex) => { if (colIndex !== index) { data = this.filterData(data, col); -- libgit2 0.21.4