0

Looping the list of values in element.io table. I need to display the sum of list of weights. I am unable to sum all the weight values.

var val= [ 
  { 
    "NmVehiclePlanning.deliveryBranch": "Madurai", 
    "NmVehiclePlanning.deliveryCity": "Madurai", 
    "NmVehiclePlanning.weight": 30106 
  }, 
  { 
    "NmVehiclePlanning.deliveryBranch": "Madurai", 
    "NmVehiclePlanning.deliveryCity": "Virudhunagar", 
    "NmVehiclePlanning.weight": 3498 
  }, 
  { 
    "NmVehiclePlanning.deliveryBranch": "Madurai", 
    "NmVehiclePlanning.deliveryCity": "KANYAKUMARI", 
    "NmVehiclePlanning.weight": 500 
  },  ]

The above data is my json data. Need to sum of all (Key name: NmVehiclePlanning.weight)

<el-table-column label="weight">
    <template slot-scope="scope">
        <span v-for="data in scope.row.details">
            {{ data['NmVehiclePlanning.weight'] }}
        </span>
     </template>
</el-table-column>

Received value is

30106 3498 500

Expected value is

34104
0

2 Answers 2

1

Try with this. Hope it will work

<el-table-column label="weight">
    <template slot-scope="scope">
        {{ calculateSum(scope.row.details) }}
    </template>
</el-table-column>

Add this function in your script.

calculateSum(val){
    var sum = 0;
    for(let value in val){
        sum += val[value]['NmVehiclePlanning.weight']
    }
    return sum;
},
Sign up to request clarification or add additional context in comments.

Comments

1

I think you need to calculate this value in your javaScript and then display the sum.

calculateSum(){
    var sum = 0;
    for(let value in val){
        sum += value['NmVehiclePlanning.weight']
    }
    return sum;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.