layui.use(['layer', 'form', 'table'], function () {
var $ = layui.jquery;
var layer = layui.layer;
var table = layui.table;
var form = layui.form;
var cols = [
{field: 'id', title: '<spring:message code="Board_Code"/>', align: 'center', templet: function (d) {
return '<span style="font-size: 20px">'+d.id+'</span>';
}},
{field: 'modelname', title: '<spring:message code="DsBoard_modelname"/>', align: 'center', templet: function (d) {
return '<span style="font-size: 20px">'+d.modelname+'</span>';
}},
{field: 'sizex', title: '<spring:message code="DsBoardDesign_boxsizeX"/>', align: 'center', templet: function (d) {
return '<span style="font-size: 20px">'+d.sizex+'</span>';
}},
{field: 'sizey', title: '<spring:message code="DsBoardDesign_boxsizeY"/>', align: 'center', templet: function (d) {
return '<span style="font-size: 20px">'+d.sizey+'</span>';
}},
{field: 'sizez', title: '<spring:message code="DsBoardDesign_boxsizeZ"/>', align: 'center', templet: function (d) {
return '<span style="font-size: 20px">'+d.sizez+'</span>';
}},
];
let url="${ctxRoot}/dsFront/getBoardList?dsProject.id=${dsBoard.dsProject.id}";
url=url+"&dsProjectObsid.id=${dsBoard.dsProjectObsid.id}&sysOfficeId=${dsBoard.sysOfficeId}";
url=url+"¶ms=${dsBoard.params}&wheresql=AnZhuangTu";
var insTb = table.render({
elem: '#dataTable',
url: url,
toolbar: false,
cellMinWidth: 80,
cols: [cols],
page: false,
request: {
//重点:后台的参数page会冲突
pageName: 'pageNum',
limitName: 'pageSize'
},
done: function (res, curr, count) {
$('td').css({'cursor':'pointer'}); //设置成指针放在表格上换成手指
$('table').width('100%');
for(var i =0;i<res.data.length;i++){
if(res.data[i].id==="${dsBoard.id}"){
$(".layui-table tbody tr").eq(i).attr({ "style": "background:#5FB878;color:#FFFFFF" });
}
}
},
parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
return {
"code": 0, //解析接口状态
"msg": res.msg, //解析提示文本
"data": res.result //解析数据列表
};
}
});
//选中行后改变行背景及字体颜色
$("body").on('click', '.layui-table-body tr ', function () {
var data_index = $(this).attr('data-index');//得到当前的tr的index
$(".layui-table-body tr").attr({ "style": "background:#FFFFFF; color:#666666" });//其他tr恢复颜色
$(".layui-table-body tr[data-index=" + data_index + "]").attr({ "style": "background:#5FB878;color:#FFFFFF" });//改变当前tr颜色
});
});
</script>
<style>
::-webkit-scrollbar {
/*隐藏滚轮*/
display: none;
}
</style>
layui点击表格单行实现单行改变颜色
最新推荐文章于 2023-01-30 11:00:23 发布