给Layui表格添加好看的样式

 function loaddata(datafield) {
                    //alert(JSON.stringify(data));
                    table.render({
                        elem: '#order_query_table'
                        , url: '../order/getAutomaticRequestRecordlist'
                        , where: datafield
                        , title: '自动请货记录表'
                        , cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
                        , limits: [10, 20, 30, 40, 50, 200, 400, 600]
                        , limit: 10
                        , page: true
                        , done: function (data) {

                            console.log(data);
                        }
                        , cols: [[
                        { type: 'checkbox', fixed: 'left' },
                        {
                            field: 'Operator', title: '操作人', style: "text-align:center", align: "center",
                        },
                        //{
                        //    field: 'StoreId', title: '门店id', style: "text-align:center", align: "center",
                        //},
                        {
                            field: 'R_time', title: '请货日期', style: "text-align:center", align: "center",

                        },
                        {
                            field: 'R_requestId', title: '请货号', style: "text-align:center", event: "getaddress", align: "center",

                        },
                        {
                            field: 'R_type', title: '请货类型', style: "text-align:center", align: "center",
                            templet: function (mydata) {
                                if (mydata.R_type == 1) {
                                    return "手动";
                                } else {
                                    return "自动";
                                }
                            }
                        },
                        {
                            field: 'R_state', title: '请货状态', style: "text-align:center;color:red;", event: "getprodetail", align: "center",
                            templet: function (mydata) {
                                if (mydata.R_state == 1) {
                                    return "是";
                                } else {
                                    return "否";
                                }
                            }

                        },
                        //{
                        //    field: 'GOODSID', title: '商品Id', style: "text-align:center", align: "center",

                        //},
                        //{
                        //    field: 'GOODSNAME', title: '商品名称', style: "text-align:center", align: "center",

                        //},
                        //{
                        //    field: 'GOODSTYPE', title: '规格',style: "text-align:center", align: "center",
                        //},
                        //{
                        //    field: 'FACTORYNAME', title: '厂商', style: "text-align:center", align: "center",
                        //},
                        //{
                        //    field: 'BARCODE', title: 'UPC',  style: "text-align:center", align: "center",
                        //},
                        //{
                        //    field: 'GOODSQTY', title: '库存', style: "text-align:center", align: "center",
                        //},
                        //{
                        //    field: 'R_Detail_time', title: '确定请货时间', style: "text-align:center", align: "center",
                        //},
                        {
                            fixed: 'right', title: '操作', toolbar: '#barDemo'
                        }]],
                        toolbar: "#toolbarDemo",
                        done: function (res, curr, count) {
                            $('th').css({ 'background-color': '#bdccea', 'color': 'black', 'font-weight': '500' });
                          

                            var that = this.elem.next(); res.data.forEach(function (item, index) {
                                //console.log(item.empName);item表示每列显示的数据
                                if (index % 2 == 0) {
                                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css('background-color', '#ecedff').addClass('addclass');
                                } else {
                                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css('background-color', '#E0EEF6').addClass('addclass');
                                }
                            }) 
                            },
                        text: {
                            none: '暂无相关数据' //默认:无数据。注:该属性为 layui 2.2.5 开始新增
                        },
                        id: 'order_list'
                    });
                }

主要代码:

 done: function (res, curr, count) {
                            $('th').css({ 'background-color': '#bdccea', 'color': 'black', 'font-weight': '500' });
                            $('th').css({ 'background-color': '#bdccea', 'color': 'black', 'font-weight': '500' });
                            $('layui-table-total.layui-table tbody tr').css({ 'color': 'red' });
                            $('.layui-table-total.layui-table tbody tr').css({ 'background-color': '#ffffb4' });

                            var that = this.elem.next(); res.data.forEach(function (item, index) {
                                //console.log(item.empName);item表示每列显示的数据
                                if (index % 2 == 0) {
                                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css('background-color', '#ecedff').addClass('addclass');
                                } else {
                                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css('background-color', '#E0EEF6').addClass('addclass');
                                }
                            }) 
                            },

效果展示:

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你的美,让我痴迷

你的好,我会永远记住你的。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值