Commit 6831b361ca8144d6e679d5c6596707545d52df0a

Authored by Aresn
Committed by GitHub
2 parents e49f7963 da020a63

Merge pull request #210 from rijn/174

Changed parameters of sort method of Table
Showing 2 changed files with 10 additions and 2 deletions   Show diff stats
src/components/table/table.vue
@@ -436,7 +436,7 @@ @@ -436,7 +436,7 @@
436 const key = this.cloneColumns[index].key; 436 const key = this.cloneColumns[index].key;
437 data.sort((a, b) => { 437 data.sort((a, b) => {
438 if (this.cloneColumns[index].sortMethod) { 438 if (this.cloneColumns[index].sortMethod) {
439 - return this.cloneColumns[index].sortMethod(a, b); 439 + return this.cloneColumns[index].sortMethod(a[key], b[key], type);
440 } else { 440 } else {
441 if (type === 'asc') { 441 if (type === 'asc') {
442 return a[key] > b[key] ? 1 : -1; 442 return a[key] > b[key] ? 1 : -1;
test/routers/table.vue
@@ -16,7 +16,15 @@ @@ -16,7 +16,15 @@
16 }, 16 },
17 { 17 {
18 title: '年龄', 18 title: '年龄',
19 - key: 'age' 19 + key: 'age',
  20 + sortable: true,
  21 + sortMethod: function (a, b, type) {
  22 + if (type === 'asc') {
  23 + return a < b ? 1 : -1;
  24 + } else if (type === 'desc') {
  25 + return a > b ? 1 : -1;
  26 + }
  27 + }
20 }, 28 },
21 { 29 {
22 title: '地址', 30 title: '地址',