From 9ea47cb3d276e779dbc4c88a70ae746b0a1c0d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Mon, 26 Mar 2018 14:28:11 +0800 Subject: [PATCH] fixed Table multiple head filter & sort bug --- examples/routers/table.vue | 135 ++++++++++++++++++++++++++-- src/components/table/table-head.vue | 33 ++++--- 2 files changed, 148 insertions(+), 20 deletions(-) diff --git a/examples/routers/table.vue b/examples/routers/table.vue index 4cbd0668..0558bf48 100644 --- a/examples/routers/table.vue +++ b/examples/routers/table.vue @@ -3,7 +3,11 @@









-
+ + +
+




+





@@ -17,7 +21,25 @@ key: 'name', align: 'center', width: 200, - fixed: 'left' + fixed: 'left', + filters: [ + { + label: 'Joe', + value: 1 + }, + { + label: 'John', + value: 2 + } + ], + filterMultiple: false, + filterMethod (value, row) { + if (value === 1) { + return row.name === 'Joe'; + } else if (value === 2) { + return row.name === 'John Brown'; + } + } }, { title: 'Other', @@ -27,7 +49,8 @@ title: 'Age', key: 'age', align: 'center', - width: 200 + width: 200, + sortable: true }, { title: 'Address', @@ -47,7 +70,8 @@ title: 'Building', key: 'building', align: 'center', - width: 200 + width: 200, + sortable: true }, { title: 'Door No.', @@ -210,12 +234,111 @@ city: 'Ottawa', zip: 100000 } - ] + ], + columns5: [ + { + title: 'Date', + key: 'date', + sortable: true + }, + { + title: 'Name', + key: 'name' + }, + { + title: 'Age', + key: 'age', + sortable: true + }, + { + title: 'Address', + key: 'address' + } + ], + data5: [ + { + name: 'John Brown', + age: 18, + address: 'New York No. 1 Lake Park', + date: '2016-10-03' + }, + { + name: 'Jim Green', + age: 24, + address: 'London No. 1 Lake Park', + date: '2016-10-01' + }, + { + name: 'Joe Black', + age: 30, + address: 'Sydney No. 1 Lake Park', + date: '2016-10-02' + }, + { + name: 'Jon Snow', + age: 26, + address: 'Ottawa No. 2 Lake Park', + date: '2016-10-04' + } + ], + columns6: [ + { + title: 'Date', + key: 'date' + }, + { + title: 'Name', + key: 'name' + }, + { + title: 'Age', + key: 'age', + filters: [ + { + label: 'Greater than 25', + value: 1 + }, + { + label: 'Less than 25', + value: 2 + } + ], + filterMultiple: false, + filterMethod (value, row) { + if (value === 1) { + return row.age > 25; + } else if (value === 2) { + return row.age < 25; + } + } + }, + { + title: 'Address', + key: 'address', + filters: [ + { + label: 'New York', + value: 'New York' + }, + { + label: 'London', + value: 'London' + }, + { + label: 'Sydney', + value: 'Sydney' + } + ], + filterMethod (value, row) { + return row.address.indexOf(value) > -1; + } + } + ], } }, mounted () { const data = []; - for (let i = 0; i < 100; i++) { + for (let i = 0; i < 20; i++) { data.push({ key: i, name: 'John Brown', diff --git a/src/components/table/table-head.vue b/src/components/table/table-head.vue index 436df201..fc873609 100644 --- a/src/components/table/table-head.vue +++ b/src/components/table/table-head.vue @@ -17,42 +17,42 @@