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 436 const key = this.cloneColumns[index].key;
437 437 data.sort((a, b) => {
438 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 440 } else {
441 441 if (type === 'asc') {
442 442 return a[key] > b[key] ? 1 : -1;
... ...
test/routers/table.vue
... ... @@ -16,7 +16,15 @@
16 16 },
17 17 {
18 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 30 title: '地址',
... ...