I have to add red background Colour for false, and green background for true based on the result column in a table, I am using elementUI + paginations of data-tables + vuejs. I am try to add in the column declarations by using style binding on result column thanks in advance
My template code
<template slot="header" slot-scope="table" :style = "customRowBackground(table.row)">
<template slot-scope="table">{{ table.row.launch_success }}</template>
</el-table-column>
my customRowBackgrond() function
customRowBackgrond({row}){
if (row.launch_success == true) {
return {'backgrondColor': 'rgb(252, 230, 190)'};
}
else if (row.launch_success == false) {
return { backgrondColor: 'rgb(252, 230, 190)'};
}
else {
return {backgrondColor: 'rgb(252, 230, 190)'};
}
},
I need to get the true value to green and false to red to my whole table.... Thanks in advance.
Try this
:style = "table.row.launch_success == true ? '{"backgrondColor": "rgb(252, 230, 190)"}' : table.row.launch_success == false ? '{"backgrondColor": "rgb(252, 230, 190)"}' : '{"backgrondColor': "rgb(252, 230, 190)"}'
Or
In template
<el-table :data="tableData2" style="width: 100%" :row-class-name="tableRowClassName">
Update method as below
methods: {
tableRowClassName({row, rowIndex}) {
if (row.launch_success == true) {
return 'success-row';
} else if (row.launch_success == false) {
return 'warning-row';
}
return 'other-row';
}
},
Update CSS as below
.el-table .warning-row {
background: 'rgb(252, 230, 190)';
}
.el-table .success-row {
background: 'rgb(252, 230, 190)';
}
.el-table .other-row {
background: 'rgb(252, 230, 190)';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With