浅谈bootstrapTable如何动态设置行和列的颜色

青灯夜游
发布: 2021-05-25 10:32:30
转载
4995人浏览过

本篇文章给大家介绍一下bootstraptable 动态设置行(rowstyle)的颜色 和 列(cellstyle 单元格)的颜色。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

浅谈bootstrapTable如何动态设置行和列的颜色

【相关推荐:《bootstrap教程》】

动态修改行颜色的方法

rowStyle: function(row, index) {	
	// 参数说明:
	//row, 行,row.xxx,能获取某个字段的值
	//index,索引,第几行
	
	// 逻辑判断
	// .....
	return  {css:{"background-color":'rgba(245,245,245,0.7)'}};
}
登录后复制

动态修改列(单元格)颜色的方法

cellStyle:function(value,row,index){
	// 参数说明:
	// value ,当前单元格的值
	// row,当前行的值
	//index ,第几行
	
	// 逻辑判断
	// .....             
	return {css:{"background-color":"rgba(255,250,250,0.7)"}};    
}
登录后复制

说明:

  • rowStyle 是 Table options(表配置) ;
  • cellStyle 是Column options (列配置)。

在列中的选项配置。两者的位置最大的区别

使用示例如下:

function load() {
	$('#exampleTable').bootstrapTable({
		url : "/config/list", 
		queryParams : function(params) {
			return {
				limit: params.limit,
				offset: params.offset,			
			}
		},		
		rowStyle: function(row, index) {   // 动态修改行的颜色
			var isDel = $.trim(row.isDel);
			if(isDel=="1"){               // 如果值是1,表示已删除,设置行的颜色
				return  {css:{"background-color":'rgba(245,245,245,0.7)'}};
			}
			return '';          // 即使不改变颜色,也得返回 '' ,否则会报错。
		},
		columns : [
			{
				checkbox : true,				
			},			
            {
				field : 'platformName', 
				title : '平台名称' ,
				width : 140,
			},       			
            {
				field : 'ydaaa', 
				title : '移动的aaa' ,
				width : 140,
				cellStyle : function(value,row,index){          // 修改列(单元格)的颜色
					return {css:{"background-color":"rgba(255,250,250,0.7)"}};    
				}
			},
            {
				field : 'ydbbb', 
				title : '移动的bbb' ,
				width : 140,
				formatter : function(value, row, index) {
					value=$.trim(value);
					if(value.length>25){
						return value.substr(0,24)+"...";
					}									
					return value;
				},				
			},			
            {
				field : 'ltaaaa', 
				title : '联通的aaaa' ,
				width : 140,
				cellStyle:function(value,row,index){                 // 修改列(单元格)的颜色
					return {css:{"background-color":"rgba(248,248,255,0.7)"}}; 
				}
			},
            {
				field : 'ltbbbb', 
				title : '联通的bbbb' ,
				width : 140,
				formatter : function(value, row, index) {
					value=$.trim(value);
					if(value.length>25){
						return value.substr(0,24)+"...";
					}									
					return value;
				}
			},
			{
				field : 'dxaaaa' , 
				title : '电信的aaaaa' ,
				width : 140 ,
				cellStyle:function(value,row,index){                 // 修改列(单元格)的颜色
					return {css:{"background-color":"rgba(240,255,240,0.7)"}}; 
				}
			},
			{
				field : 'dxbbbbb' , 
				title : '电信的bbbbb' ,
				width : 140 ,
			},				
            {
				field : 'isDel', 
				title : '是否删除' ,
				width : 80,
				formatter : function(value, row, index) {
					value=$.trim(value);
					if(value=="0"){
						return "正常";
					}else if(value=="1"){
						return "已删除";
					}					
					return "";
				}
			},
            {
				field : 'createTime', 
				title : '创建日期' ,
				width : 140,
				formatter : function(value, row, index) {
					value = $.trim(value) ;
					if(value.length >= 19){
						return value.substr(0 , 19);
					}
					return value;
				}
			},			
            {								
				title : '操作',
				field : 'id',
				align : 'center',
				width : 200,								
				formatter : function(value, row, index) {

					return '' ;
				}
			} ]
	});
}
登录后复制

说明:

{css:{"background-color":"rgba(255,250,250,0.7)"}}; 中 0.7 是指透明度,

当 两种(行和列)颜色交汇时,在交汇的单元格中,可以看到两种颜色。如下图所示:

在这里插入图片描述

更多编程相关知识,请访问:编程入门!!

以上就是浅谈bootstrapTable如何动态设置行和列的颜色的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
来源:csdn网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号