有些时间使用layui渲染表格数据,可能不仅需要渲染table,也有可能需要做各种统计或者其他操作,这个时候值就不方便渲染。
找了很久解决办法,终的大悟,其实很简单,只需要引用layui的parseData 插件就可以实现,下面有例子!
var tableIns = table.render({
elem : '#adminList',
url : '',
cellMinWidth : 95,
page : true,
method : 'post',
height : "full-175",
loading : true,
id : "adminListTable",
parseData : function(res) { //res 即为原始返回的数据
$(".sum").val(res.data.sum);
return {
"code" : res.code, //解析接口状态
"msg" : res.msg, //解析提示文本
"count" : res.count, //解析数据长度
"data" : res.data.listData //解析数据列表
};
},
cols : [ [
{type : "checkbox",fixed : "left",width : 50},
{field : 'title',title : '房源标题',minWidth : 100,align : "center"},
{field : 'quota',title : '期望金额(万元)',minWidth : 100,align : "center"},
{field : 'name',title : '用款人姓名',minWidth : 100,align : "center"},
{field : 'nikeName',title : '用款人昵称',minWidth : 100,align : "center"},
{field : 'count',title : '房源投标量',minWidth : 100,align : "center"},
{field : 'cost',title : '房源总收入(元)',minWidth : 100,align : "center"},
{field : 'operationTime',title : '发布时间',minWidth : 165,align : "center"},
{field : 'status',title : '房源状态',align : 'center',width : 100,
templet : function(d) {
var js = d.status;
if (js == 0) {
return "正常";
} else if (js == 1) {
return "结束";
}
}
},
{title : '操作',minWidth : 175,templet : '#adminListBar',fixed : "right",align : "center"}
] ]
});
注意事项:该插件为 layui 2.4.0 开始新增!抓紧去更新尝试把!layui官网