zoukankan      html  css  js  c++  java
  • layui数据表格根据字段生成自定义样式

    layui数据表格根据字段生成自定义样式

    1.根据文字的值不一样显示不同的样式

    {
        field: 'checkState', title: '奖励状态',
        templet: function (d) {
            if (d.checkState == "已通过") {
                return '<span style="color:#008000;">' + d.checkState + '</span>'
            }
            if (d.checkState == "未通过") {
                return '<span style="color:#c00;">' + d.checkState + '</span>'
            }
            if (d.checkState == "待审核") {
                return '<span style="color:#FF4500;">' + d.checkState + '</span>'
            }
            if (d.checkState == "未提交") {
                return '<span style="color:#000000;">' + d.checkState + '</span>'
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    2.根据数字的值不一样显示不同的文字

    2.1只是文字
    
    	{field: 'state', title: '状态',templet:function (d) {
    	    if(d.state=='1') return '可用'
    	    else return '不可用'
    	}}
    	
    2.2 设置文字样式
    
    	{field: 'state',width:'7.4%', align: 'center', title: '是否授权',
    		templet : function(data) {// 替换数据
    			if(data.state==1){
    				 return "授权";  
    		   }else if(data.state==0){
    		  	return '<span style="color: #c00;">'+'未授权'+'</span>';
    		   }
    	   }
    	}
    	
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    3.表格显示图片

    
    {field: 'imgUrl', title: '图片', width: 160,templet: function(d){
        return '<img src="'+d.imgUrl+'" alt="" width="160px" height="80px"/></div>';
    }}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    4.表格里间加按钮
    	引入的javascript
    <script type="text/html" id="toolbartopheadUrl">
    	 <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detailheadUrl">查看</a>
    </script>
    
    	Html页面
    {field:'btn', width:'5%', title: '头像',align:'center',toolbar:'#toolbartopheadUrl'}
    
    	JS监听
    if (obj.event === 'detailheadUrl') {
       	var tu = data.headUrl;
        if(tu=="" || tu==null){
      		layer.msg('未上传图片');
        }else{	
            var img = '<img  src=' + '"' + tu + '"' + ' width="200px" height="200px" />';
            layer.tab({
                area: ['200px', '250px'],
                tab: [{
                    title: '图片',
                    content: img
                }]
            });
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    5 设置背景颜色文字颜色
    {field: 'orPrice', title: '订单总价', width: 100,style:"color: red;"}
  • 相关阅读:
    Spring Boot2(九):整合Jpa的基本使用
    Spring Boot2(八):性感banner,在线发牌
    Spring Boot2(七):拦截器和过滤器
    我为什么要写作
    代码整洁之道
    redis-缓存穿透和缓存击穿
    云计算的三种服务模式
    java-泛型
    java-注解
    java-反射
  • 原文地址:https://www.cnblogs.com/onesea/p/13713131.html
Copyright © 2011-2022 走看看