diff --git a/src/components/table/table.vue b/src/components/table/table.vue index cfa938e..0898092 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -436,7 +436,7 @@ const key = this.cloneColumns[index].key; data.sort((a, b) => { if (this.cloneColumns[index].sortMethod) { - return this.cloneColumns[index].sortMethod(a, b); + return this.cloneColumns[index].sortMethod(a[key], b[key], type); } else { if (type === 'asc') { return a[key] > b[key] ? 1 : -1; diff --git a/test/routers/table.vue b/test/routers/table.vue index fd801c9..101cd12 100644 --- a/test/routers/table.vue +++ b/test/routers/table.vue @@ -16,7 +16,15 @@ }, { title: '年龄', - key: 'age' + key: 'age', + sortable: true, + sortMethod: function (a, b, type) { + if (type === 'asc') { + return a < b ? 1 : -1; + } else if (type === 'desc') { + return a > b ? 1 : -1; + } + } }, { title: '地址', -- libgit2 0.21.4