vue柱状图排序功能


    
    
    


for (let item1 of this.dragTo.rows) {
   item1.sort = 'dcaret'
}
editSort(o,type) {
      this.sortItem = o
      this.sortType = type
      switch (o.sort) {
        case 'asc':
            o.sort = 'desc';
            break;
        case 'desc':
            o.sort = 'dcaret';
            break;
        default:
            o.sort = 'asc';
            break;
        }
        if (this.sortType === 'row') {
          this.dragTo.columns.forEach(item => {
            item.sort = 'dcaret'
          })
          this.dragTo.values.forEach(item => {
            item.sort = 'dcaret'
          })
          this.dragTo.rows.forEach(item => {
            if (item.column === this.sortItem.column) {
              item.sort = this.sortItem.sort
            }
          })
        }
        this.$forceUpdate()
},
this.tableData.forEach((val, i) => {
                  Object.keys(val).forEach(key => {
                    this.dragTo.rows.forEach(item => {
                      if (key === item.alias) {
                        if (item.sort === 'asc') {
                          this.tableData.sort(sortAscMethod(key))
                        } else if (item.sort === 'desc') {
                          this.tableData.sort(sortDescMethod(key))
                        }
                      }
                    })
                  })
})
export function sortAscMethod(prop) {
  return function (obj1, obj2) {
    var val1 = obj1[prop]
    var val2 = obj2[prop]
    if (!isNaN(Number(val1)) && !isNaN(Number(val2))) {
      val1 = Number(val1);
      val2 = Number(val2);
    }
    if (val1 < val2) {
      return -1;
    } else if (val1 > val2) {
      return 1;
    } else {
      return 0;
    }
  }
}
export function sortDescMethod(prop) {
  return function (obj1, obj2) {
    var val1 = obj1[prop]
    var val2 = obj2[prop]
    if (!isNaN(Number(val1)) && !isNaN(Number(val2))) {
      val1 = Number(val1);
      val2 = Number(val2);
    }
    if (val1 < val2) {
      return 1;
    } else if (val1 > val2) {
      return -1;
    } else {
      return 0;
    }
  }
}

 

你可能感兴趣的:(vue柱状图排序功能)