problem description
enter the number in the input box of the table, and then the line of the total price calculates the sum you just entered
the environmental background of the problems and what methods you have tried
related codes
/ / Please paste the code text below (do not replace the code with pictures)
https://jsbin.com/zezaqovisi/.
<el-table :data="tableData6" border="" :summary-method="getSummaries" show-summary style="width: 100%; margin-top: 20px">
<el-table-column prop="id" label="ID">
</el-table-column>
<el-table-column prop="name" label="">
</el-table-column>
<el-table-column prop="amount1" label=" 1">
</el-table-column>
<el-table-column prop="amount2" label=" 2">
</el-table-column>
<el-table-column prop="amount3" label=" 3">
</el-table-column>
<el-table-column label="" width="100" prop="amount4">
<template slot-scope="scope">
<el-input size="small" v-model="scope.numberscore" placeholder="" style="width: 80px;" @blur="aaa(scope.$index,scope.numberscore)" ></el-input>
</template>
</el-table-column>
</el-table>
js Code
: summary-method= "getSummaries" is an attribute that comes with the frame
var Main = {
data() {
return {
tableData6: [{
id: "12987122",
name: "111",
amount1: "234",
amount2: "3.2",
amount3: 10
}, {
id: "12987123",
name: "222",
amount1: "165",
amount2: "4.43",
amount3: 12
}, {
id: "12987124",
name: "333",
amount1: "324",
amount2: "1.9",
amount3: 9
}, {
id: "12987125",
name: "444",
amount1: "621",
amount2: "2.2",
amount3: 17
}, {
id: "12987126",
name: "555",
amount1: "539",
amount2: "4.1",
amount3: 15
}]
};
},
created() {
this.tableData6.map((item) => {
item.amount4 = ""
})
console.log("created----this.tableData6", this.tableData6)
},
methods: {
//
aaa(index, number) {
let temp = Object.assign({}, this.tableData6)
this.tableData6[index].amount4 = number
console.log("this.tableData6", this.tableData6)
if (index === (this.tableData6.length - 1)) {
console.log("PPPPPPPP")
this.tableData6 = this.tableData6
}
},
getSummaries(param) {
const {
columns,
data
} = param;
console.log("param", param)
//console.log("data", data)
const sums = [];
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = "";
return;
}
const values = data.map(item => {
return Number(item[column.property])
});
if (!values.every(value => isNaN(value))) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
sums[index] += " ";
} else {
sums[index] = "N/A";
}
});
return sums;
}
}
};
var Ctor = Vue.extend(Main)
new Ctor().$mount("-sharpapp")