Click2Buy / vue-pivot-table

A vue component for pivot table
MIT License
225 stars 71 forks source link

how change variable in reduce function #5

Closed lalo4ka closed 5 years ago

lalo4ka commented 5 years ago

is possible change dynamically the variable in reducer function? reducer: (sum, item) => sum + item.count

antoinematyja commented 5 years ago

Yes, you can set the reducer prop of the component to a method that will reduce values depending on whatever you want. Here is an example of what you could do :

data: {
  reduceAttr: 'count' // Can be set to 'sum', 'average' or 'count' by the user
},
methods: {
  reduce: function(sum, item) {
    return sum + item[this.reduceAttr]
  }
}