Layui表格好看样式

Layui表格好看样式

开发工具与关键技术:web
作者:熊琪
撰写时间:2019.7.27

Layui表格的运用至今已经很广了,如需要以下样式的请继续往下看哦,如图一为layui表格的样式效果图,主要与layui的数据表格默认的样式不同的地方就是表头的颜色不同,和数据的颜色相间当为数为偶数时颜色为白色,除了偶数就是奇数,奇数显示为灰色,合计为黄色,而且表格高度固定,当数据条数过多,自动添加滚动条合计是固定在表格最下方。
看效果图:
在这里插入图片描述
(图一)
实现代码如下:
layui.use([‘layer’, ‘table’], function () {
layer = layui.layer, layuiTable = layui.table;
TabSalesDetail = layuiTable.render({
elem: ‘#SalesDetail’, size: ‘sm’,
totalRow: true, height:385,
cols: [[
{ type: ‘numbers’, title: ‘’, totalRowText: " 合计:", rowspan: 2 },
{ title: ‘商品编码(条码)’, field:‘CommodityCode’, align: ‘center’, rowspan: 2 },
{ title: ‘商品名称’, field: ‘CommodityName’, align: ‘center’, rowspan: 2 },
{ title: ‘款号’, field: ‘CommodityStyleNumber’, align: ‘center’, rowspan: 2 },
{ title: ‘颜色’, field: ‘ColorName’, align: ‘center’, rowspan: 2 },
{ title: ‘尺码’, field: ‘SizeName’, align: ‘center’, rowspan: 2 },
{ title: ‘吊牌价’, field: ‘TagPrice’, align: ‘center’, rowspan: 2 },
{ title: ‘单位’, field: ‘UnitName’, align: ‘center’, rowspan: 2 },
{ title: ‘销售’, align: ‘center’, colspan: 2 },{ title: ‘金额’, align: ‘center’, colspan: 2 },{ title: ‘成本’, align: ‘center’, colspan: 2 },{ title: ‘小票’, align: ‘center’, colspan: 2 },
],
[{ title: ‘折扣’, field: ‘Discount’, align: ‘center’ },
{ title: ‘数量’, field: ‘shuliang’, align: ‘center’, totalRow: ‘true’, },
{ title: ‘单价’, field: ‘CountPrice’, align: ‘center’ },
{ title: ‘合计’, field: ‘Price’, align: ‘center’ },
{ title: ‘单价’, field: ‘chengben’, align: ‘center’ },
{ title: ‘合计’, field: ‘chengbenall’, align: ‘center’ },
{ title: ‘单号’, field: ‘SellNumber’, align: ‘center’ },
{ title: ‘日期’, field: ‘danjuriqi’, align: ‘center’ },
]],
page: { limit: 1000,//指定每页显示的条数limits: [1000, 100, 50],//每页条数的选择项
}, //开启分页
data: [],//加载本地数据
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”);
} else {
var tr = that.find(".layui-table-box tbody tr[data-index=’" + index + “’]”).css(“background-color”, “white”);
} })
},
});
});
Size表头参数,可以改变表头的大小号,totalRow是开启统计的参数true表示开启,再在需要统计的字段上加totalRow:truez就可以统计了, height:385,这是设置了表格的高度,th表头背景颜色为#bdccea,字体颜色为黑色,字体粗细为500,tr同理,最后判段数据是否为偶数行,为偶数行显示为灰色也就是#ecedff,否则显示为白色。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值