Commit da020a63ee3a061fa062e13b41e917ec2ef11260

Authored by Rijn
1 parent e49f7963

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: '地址',
... ...