antd table根据判断条件单元格设置背景色

1.文档显示,table表格中有customCell属性
Column:列描述数据对象
参数 --------------------------------------- 说明------------------------------------------------------------------类型
在这里插入图片描述
2.vue页面使用

//template    rowClassName
<a-table ref="table" :columns="columns" :dataSource="dataSource" :loading="loading" 
	:pagination="ipagination" :scroll="{x:true}" bordered size="middle" @change="handleTableChange" >
	<div slot="alarmType" slot-scope="text, record">
		<span> {{ text }}</span>
	</div>
</a-table>

//script
<script>
	export default {
		data(){
			return{
				//表头
				columns:[
					{
						title: "告警类型",
						align: "center",
						dataIndex: "typename",
						scopedSlots: { customRender: "alarmType" }customCell: this.getRowBackGround
					}
				]
			}
		},
		methods:{
			//根据条件table中customCell改变单元格样式
			getRowBackGround(recordAlarm) {
				// console.log("customCell改变单元格样式" + JSON.stringify(recordAlarm))
				console.log("levelid------" + recordAlarm.levelid)
				switch (recordAlarm.levelid) {//这里根据条件改变单元格背景色
					case "0":
						return { class: "table-color-default" }
					case "1":
						return { class: "table-color-success" }
					case "2":
						return { class: "table-color-processing" }
					case "3":
						return { class: "table-color-warning" }
					case "4":
						return { class: "table-color-error" }
					default:
						return { class: "table-color-default" }
				}
			},
		}
	}
</script>
<style>
.table-color-success {
	color: #ffffff;
	background-color: #0c8fcf;
}

.table-color-processing {
	background-color: #FFFF00;
}

.table-color-warning {
	color: #ffffff;
	background-color: #FFA500;
}

.table-color-error {
	color: #ffffff;
	background-color: #FF0000;
}

.table-color-default {
	color: #ffffff;
	background-color: #808080;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值